appear button in ios
See original GitHub issueAll is working fine in Android but in ios have an extra button showing current date and I need to press on that instead of pressing Show Picker.
In my code I am using TouchableOpacity instead of Button.
Any advise?
Below are my code. `export const AppDateTimePicker = () => { const [date, setDate] = useState(new Date()); const [mode, setMode] = useState(‘date’); const [show, setShow] = useState(false); const [chosenDate, setChosenDate] = useState(‘dd/mm/yyyy’);
const onChange = (event, selectedDate) => { const currentDate = selectedDate || date; setShow(Platform.OS === ‘ios’); setDate(currentDate);
let tempDate = new Date(currentDate);
let showDate = [tempDate.getDate(), (tempDate.getMonth() + 1), tempDate.getFullYear()].join('/');
setChosenDate(showDate);
};
const showMode = (currentMode) => { setShow(true); setMode(currentMode); };
const showDatepicker = () => { showMode(‘date’); };
return ( <View style={styles.container}> <View style={styles.dateContent}> <TouchableOpacity onPress={(showDatepicker)} > <Text style={styles.textStyle}>{chosenDate}</Text> <MaterialCommunityIcons name="calendar" size={24} style={styles.icon}/> </TouchableOpacity> {/* <Button onPress={showDatepicker} title="Show date picker!" /> */} </View>
{show && (
<DateTimePicker
testID="dateTimePicker"
value={date}
mode={mode}
display="default"
onChange={onChange}
/>
)}
</View>
); };
const styles = StyleSheet.create({ container: { borderBottomWidth: 1, borderBottomColor: colors.grey, width: ‘100%’, paddingTop: 8, paddingBottom: 8, marginBottom: 30, marginTop: -10 }, icon: { position: ‘absolute’, right: 0, // top: 12 }, dateContent: { width: ‘100%’, padding: 8, color: colors.primary }, textStyle: { color: colors.primary } }); `
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:6
Top GitHub Comments
Save your time and use this package instead https://github.com/mmazzarolo/react-native-modal-datetime-picker
Solved. Need to wrapped inside Modal and display as ‘spinner’ for ios. You can check below code. I found the solution from the link below: https://www.youtube.com/watch?v=lpIEpggB6o4 Thanks to A3 Programming.