Skip to content

Commit 0073069

Browse files
author
Vivek Kozhisseri
authored
Added theme config support for picker and dateTimePicker (#6054)
1 parent 5b7c745 commit 0073069

File tree

5 files changed

+50
-37
lines changed

5 files changed

+50
-37
lines changed

source/community/reactnative/src/components/inputs/choice-set/choice-set-input.js

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ export class ChoiceSetInput extends React.Component {
165165
onPress={onPress}
166166
accessible={true}
167167
accessibilityRole={'button'}
168-
accessibilityState={{expanded: this.state.isPickerSelected}}
169-
>
168+
accessibilityState={{ expanded: this.state.isPickerSelected }}
169+
>
170170
<View style={this.styleConfig.dropdown}>
171171
<Text
172172
style={[this.styleConfig.dropdownText, this.styleConfig.defaultFontConfig]}
@@ -182,26 +182,25 @@ export class ChoiceSetInput extends React.Component {
182182
</View>
183183
</TouchableOpacity>}
184184
{((Platform.OS === Constants.PlatformIOS) ? this.state.isPickerSelected : true) &&
185-
<View style={styles.pickerContainer}>
186-
<Picker
187-
mode={'dropdown'}
188-
selectedValue={this.getPickerInitialValue(addInputItem)}
189-
onValueChange={
190-
(itemValue) => {
191-
this.setState({
192-
selectedPickerValue: itemValue,
193-
isError: false
194-
})
195-
addInputItem(this.id, { value: itemValue, errorState: false });
196-
}}>
197-
{this.choices.map((item, key) => (
198-
<Picker.Item
199-
label={item.title}
200-
value={item.value} key={key}
201-
/>)
202-
)}
203-
</Picker>
204-
</View>
185+
<Picker
186+
mode={'dropdown'}
187+
itemStyle={this.styleConfig.picker}
188+
selectedValue={this.getPickerInitialValue(addInputItem)}
189+
onValueChange={
190+
(itemValue) => {
191+
this.setState({
192+
selectedPickerValue: itemValue,
193+
isError: false
194+
})
195+
addInputItem(this.id, { value: itemValue, errorState: false });
196+
}}>
197+
{this.choices.map((item, key) => (
198+
<Picker.Item
199+
label={item.title}
200+
value={item.value} key={key}
201+
/>)
202+
)}
203+
</Picker>
205204
}
206205
</View>
207206
)
@@ -326,13 +325,6 @@ const styles = StyleSheet.create({
326325
choiceSetView: {
327326
marginTop: 3
328327
},
329-
pickerContainer: {
330-
borderWidth: 1,
331-
backgroundColor: Constants.LightGreyColor,
332-
borderColor: Constants.LightGreyColor,
333-
borderRadius: 5,
334-
marginHorizontal: 2
335-
},
336328
button: {
337329
height: 30,
338330
width: 30,

source/community/reactnative/src/components/inputs/picker-input.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class PickerInput extends React.Component {
8484
<ElementWrapper configManager={this.props.configManager} style={styles.elementWrapper} json={this.payload} isError={this.state.isError} isFirst={this.props.isFirst}>
8585
<InputLabel configManager={this.props.configManager} isRequired={this.isRequired} label={label} />
8686
<TouchableOpacity style={styles.inputWrapper} onPress={this.props.showPicker}
87-
accessibilityRole='button'>
87+
accessibilityRole='button'>
8888
{/* added extra view to fix touch event in ios . */}
8989
<View
9090
accessible={true}
@@ -109,7 +109,7 @@ export class PickerInput extends React.Component {
109109
visible={this.props.modalVisible}
110110
onRequestClose={this.props.handleModalClose}>
111111
<View style={[styles.overlay, modalOverlayStyle]}>
112-
<View style={[styles.modal, modalStyle]}>
112+
<View style={[this.styleConfig.dateTimePicker, modalStyle]}>
113113
<View style={[styles.modalBtnContainer, modalBtnContainer]}>
114114
<Button
115115
style={[modalButtonStyle]}
@@ -124,6 +124,7 @@ export class PickerInput extends React.Component {
124124
value={this.props.chosenDate || new Date()}
125125
minimumDate={this.props.minDate}
126126
maximumDate={this.props.maxDate}
127+
textColor={this.styleConfig.dateTimePicker.textColor}
127128
onChange={(event, date) => this.props.handleDateChange(date)} />
128129
</View>
129130
</View>
@@ -162,11 +163,6 @@ const styles = StyleSheet.create({
162163
alignItems: Constants.CenterString,
163164
justifyContent: Constants.FlexEnd
164165
},
165-
modal: {
166-
backgroundColor: Constants.WhiteColor,
167-
height: 260,
168-
width: Constants.FullWidth
169-
},
170166
modalBtnContainer: {
171167
width: Constants.FullWidth,
172168
alignItems: Constants.CenterString,

source/community/reactnative/src/styles/style-config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ export class StyleConfig {
8181
},
8282
dropdownText: {
8383
...this.themeConfig.dropdownText[Platform.OS]
84+
},
85+
picker: {
86+
...this.themeConfig.picker[Platform.OS]
87+
},
88+
dateTimePicker: {
89+
...this.themeConfig.dateTimePicker[Platform.OS]
8490
}
8591
};
8692
return styles;

source/community/reactnative/src/utils/enums.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,6 @@ export const ThemeElement = Object.freeze({
186186
CheckBoxText: "checkBoxText",
187187
Dropdown: "dropdown",
188188
DropdownText: "dropdownText",
189+
Picker: "picker",
190+
DateTimePicker: "dateTimePicker"
189191
});

source/community/reactnative/src/utils/theme-config.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ export class ThemeConfig {
1414
this.checkBoxText = new Config(ThemeElement.CheckBoxText, obj);
1515
this.dropdown = new Config(ThemeElement.Dropdown, obj);
1616
this.dropdownText = new Config(ThemeElement.DropdownText, obj);
17+
this.picker = new Config(ThemeElement.Picker, obj);
18+
this.dateTimePicker = new Config(ThemeElement.DateTimePicker, obj)
1719
}
1820
}
1921

2022
// Each instance of this class holds config of specific element type
23+
// this class holds config of specific element type
2124
class Config {
2225
constructor(type, customConfig = {}) {
2326
this.type = type;
@@ -125,6 +128,20 @@ export const defaultThemeConfig = {
125128
marginTop: 10,
126129
marginLeft: 8,
127130
height: 30,
128-
}
131+
},
132+
picker: {
133+
borderWidth: 1,
134+
backgroundColor: Constants.LightGreyColor,
135+
borderColor: Constants.LightGreyColor,
136+
color: Constants.BlackColor,
137+
borderRadius: 5,
138+
marginHorizontal: 2
139+
},
140+
dateTimePicker: {
141+
backgroundColor: Constants.WhiteColor,
142+
height: 260,
143+
width: Constants.FullWidth,
144+
textColor: Constants.BlackColor
145+
},
129146

130147
}

0 commit comments

Comments
 (0)