-
-
Notifications
You must be signed in to change notification settings - Fork 416
Expand file tree
/
Copy pathDatePickerIOS.js
More file actions
53 lines (46 loc) · 1.37 KB
/
DatePickerIOS.js
File metadata and controls
53 lines (46 loc) · 1.37 KB
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
import React, { useCallback } from 'react'
import { StyleSheet } from 'react-native'
import { useModal } from './modal'
import { getNativeComponent } from './modules'
const NativeComponent = getNativeComponent()
/** @type {React.FC<PlatformPickerProps>} */
export const DatePickerIOS = (props) => {
const onChange = useCallback(
/** @param {{ nativeEvent: { timestamp: string } }} event */
(event) => {
const nativeTimeStamp = event.nativeEvent.timestamp
if (props.onDateChange) props.onDateChange(new Date(nativeTimeStamp))
},
[props]
)
/** @type {NativeProps} */
const modifiedProps = {
...props,
onChange,
style: [styles.datePickerIOS, props.style],
date: props.date ? props.date.toISOString() : undefined,
locale: props.locale ? props.locale : undefined,
maximumDate: props.maximumDate
? props.maximumDate.toISOString()
: undefined,
minimumDate: props.minimumDate
? props.minimumDate.toISOString()
: undefined,
theme: props.theme ? props.theme : 'auto',
}
useModal({ props: modifiedProps, id: undefined })
if (props.modal) return null
return (
<NativeComponent
{...modifiedProps}
onStartShouldSetResponder={() => true}
onResponderTerminationRequest={() => false}
/>
)
}
const styles = StyleSheet.create({
datePickerIOS: {
height: 216,
width: 310,
},
})