-
Notifications
You must be signed in to change notification settings - Fork 0
/
MiPrettyChip.tsx
160 lines (94 loc) · 3.64 KB
/
MiPrettyChip.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import React, { Component, createRef, RefObject } from 'react';
import { Animated, StyleSheet, Text, View, Platform,StatusBar, TextInput, FlatList, Image, Modal, Switch,AsyncStorage, Alert, AlertButton, ProgressBarAndroid, ColorPropType, VirtualizedList, Picker, Dimensions, PermissionsAndroid, StyleProp, ViewStyle, TextStyle, TouchableHighlight, TouchableOpacity, TouchableWithoutFeedbackComponent, TouchableNativeFeedbackComponent, TouchableHighlightBase } from 'react-native';
import SvgMi, { st } from './SvgMi';
//this is called a chip but it's really a radioBox,
//with more of a checkbox functionanlity : doesnt take care of the excusive selection logic, do it yourself through the hosting parent
const wraper_style : StyleProp<ViewStyle> = {
flexDirection:"column",
// width:"100%",
// backgroundColor:"maroon",
//height:150
}
const head_style : StyleProp<ViewStyle> = {
marginTop:6,
paddingVertical:16,
paddingHorizontal:16,
flexDirection:"row",
alignItems:"center",
alignSelf:"flex-start",
backgroundColor:"#fff0",
}
const head_pressed_style : StyleProp<ViewStyle> = {
marginTop:6,
paddingVertical:16,
paddingHorizontal:16,
flexDirection:"row",
alignItems:"center",
alignSelf:"flex-start",
backgroundColor:"#2c2c2c"
}
const text_style : StyleProp<TextStyle> = {
//fontFamily:"sans-serif-light",
fontSize:14,
color:'#dfefff',//cool low key blue white
marginHorizontal:2,
}
const text_selected_style : StyleProp<TextStyle> = {
//fontFamily:"sans-serif-light",
color:'lightseagreen',
}
type MiPrettyChipProps = {
tilte:string,
isSelected?:boolean
contentStyle?:StyleProp<ViewStyle>
style?:StyleProp<ViewStyle>
textStyle?:StyleProp<TextStyle>
textStylePressed?:StyleProp<TextStyle>
selectedRadioIx:number
ix:number
changeSelected : (ix)=>void
}
type MiPrettyChipState= {
isSelected:boolean
pressed?:boolean
contentStyle?:StyleProp<ViewStyle>
style?:StyleProp<ViewStyle>
textStyle?:StyleProp<TextStyle>
}
export default class MiPrettyChip extends Component<MiPrettyChipProps,MiPrettyChipState>{
constructor(props:MiPrettyChipProps){
super(props)
this.state = {
isSelected : props.ix===props.selectedRadioIx,
pressed : false
}
this.selectMe=this.selectMe.bind(this)
}
amIselected(){
return(this.props.selectedRadioIx===this.props.ix)
}
selectMe(){
this.props.changeSelected(this.props.ix)
}
pressIn(){
this.setState({pressed:true})
}
pressOut(){
this.setState({pressed:false})
}
render(){
return <View style={[wraper_style,this.props.style]}>
<View style={{flexDirection:"row", alignContent:"center"}}>
<TouchableHighlight onPressIn={this.pressIn.bind(this)}
onPressOut={this.pressOut.bind(this)} activeOpacity={1}
underlayColor='#8880' onPress={()=> this.selectMe()}>
<View style={[head_style,(this.state.pressed&&head_pressed_style)]} >
<SvgMi height={20} width={20} xmldata={this.amIselected()?st.radio_button_checked:st.radio_button_unchecked} color={this.amIselected()?"#00c0c0":"#dfefff"} > </SvgMi>
<Text style={[text_style,this.props.textStyle,
,(this.state.pressed&& this.props.textStylePressed)]} > {this.props.tilte} </Text>
</View>
</TouchableHighlight>
</View>
</View>
}
}