-
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.
Merge pull request #83 from dcalacci/develop
Merge develop for latest release
- Loading branch information
Showing
127 changed files
with
1,407 additions
and
39,528 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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import React, { useState } from 'react'; | ||
import { View, Text, Pressable, Platform } from 'react-native'; | ||
import { tailwind } from 'tailwind'; | ||
import moment from 'moment'; | ||
|
||
import Modal from 'react-native-modal'; | ||
import DateTimePicker from '@react-native-community/datetimepicker'; | ||
|
||
export default ({ | ||
defaultDate = new Date(), | ||
onSetDate, | ||
}: { | ||
defaultDate?: Date; | ||
onSetDate: (d: Date) => void; | ||
}) => { | ||
const [date, setDate] = useState(defaultDate); | ||
const [mode, setMode] = useState('date'); | ||
const [show, setShow] = useState(false); | ||
const [showModal, setShowModal] = useState(false); | ||
|
||
const onChange = (event, selectedDate) => { | ||
const currentDate = selectedDate || date; | ||
setDate(currentDate); | ||
onSetDate(currentDate); | ||
}; | ||
|
||
const showMode = (currentMode) => { | ||
setShow(true); | ||
setMode(currentMode); | ||
}; | ||
|
||
const showDatepicker = () => { | ||
showMode('date'); | ||
setShowModal(true); | ||
}; | ||
|
||
const showTimepicker = () => { | ||
showMode('time'); | ||
setShowModal(true); | ||
}; | ||
|
||
return ( | ||
<View> | ||
<Modal | ||
style={tailwind('flex-col justify-end items-center')} | ||
isVisible={showModal} | ||
onBackButtonPress={() => setShowModal(false)} | ||
onBackdropPress={() => setShowModal(false)} | ||
hasBackdrop={true} | ||
> | ||
<View style={tailwind('rounded-lg bg-white p-2 m-2 w-full h-1/2 flex-col')}> | ||
{show && ( | ||
<DateTimePicker | ||
style={tailwind('m-1 flex-grow')} | ||
testID="dateTimePicker" | ||
value={date} | ||
mode={mode} | ||
is24Hour={true} | ||
display={ | ||
Platform.OS === 'ios' | ||
? mode == 'date' | ||
? 'inline' | ||
: 'spinner' | ||
: 'default' | ||
} | ||
onChange={onChange} | ||
/> | ||
)} | ||
</View> | ||
<Pressable | ||
onPress={() => setShowModal(false)} | ||
style={tailwind('bg-black rounded-lg p-2 w-full items-center')} | ||
> | ||
<Text style={tailwind('font-bold text-white m-1')}>Done</Text> | ||
</Pressable> | ||
</Modal> | ||
<View style={tailwind('flex-row w-full items-center')}> | ||
<Pressable | ||
onPress={showDatepicker} | ||
style={tailwind('p-2 m-1 bg-gray-100 rounded-lg')} | ||
> | ||
<Text>{moment(date).format('M/D/YY')}</Text> | ||
</Pressable> | ||
<Pressable | ||
onPress={showTimepicker} | ||
style={tailwind('p-2 m-1 bg-gray-100 rounded-lg')} | ||
> | ||
<Text>{moment(date).format('h:mm a')}</Text> | ||
</Pressable> | ||
</View> | ||
</View> | ||
); | ||
}; |
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
Oops, something went wrong.