-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I AM A WIZARD! Displaying the time on load
- Loading branch information
1 parent
37f4cf8
commit 84f6cbf
Showing
2 changed files
with
40 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,32 @@ | ||
import React, {Component} from 'react'; | ||
import {View, Button, Platform, UIManager} from 'react-native'; | ||
import DateTimePicker from '@react-native-community/datetimepicker'; | ||
import {DatePickerIOS, View, StyleSheet} from 'react-native'; | ||
|
||
export default class TimePicker extends Component { | ||
state = { | ||
date: new Date('2020-06-12T14:42:42'), | ||
mode: 'date', | ||
show: false, | ||
}; | ||
export default class App extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = {chosenDate: new Date()}; | ||
|
||
setDate = (event, date) => { | ||
date = date || this.state.date; | ||
|
||
this.setState({ | ||
show: Platform.OS === 'ios' ? true : false, | ||
date, | ||
}); | ||
}; | ||
|
||
show = mode => { | ||
this.setState({ | ||
show: true, | ||
mode, | ||
}); | ||
}; | ||
|
||
datepicker = () => { | ||
this.show('date'); | ||
}; | ||
this.setDate = this.setDate.bind(this); | ||
} | ||
|
||
timepicker = () => { | ||
this.show('time'); | ||
}; | ||
componentDidMount() { | ||
this.time; | ||
setDate(newDate) { | ||
this.setState({chosenDate: newDate}); | ||
} | ||
render() { | ||
const {show, date, mode} = this.state; | ||
|
||
render() { | ||
return ( | ||
<View> | ||
<View> | ||
<Button onPress={this.datepicker} title="Show Date" /> | ||
</View> | ||
<View> | ||
<Button onPress={this.timepicker} title="Select Time" /> | ||
</View> | ||
{show && ( | ||
<DateTimePicker | ||
value={date} | ||
mode={mode} | ||
is24Hour={true} | ||
display="default" | ||
onChange={this.setDate} | ||
/> | ||
)} | ||
<View style={styles.container}> | ||
<DatePickerIOS | ||
date={this.state.chosenDate} | ||
onDateChange={this.setDate} | ||
/> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
justifyContent: 'center', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters