1
- import React , { useCallback , useEffect , useMemo , useRef , useState } from 'react' ;
1
+ import React , {
2
+ useCallback ,
3
+ useEffect ,
4
+ useMemo ,
5
+ useRef ,
6
+ useState ,
7
+ useImperativeHandle ,
8
+ forwardRef ,
9
+ ForwardedRef
10
+ } from 'react' ;
2
11
import { StyleProp , StyleSheet , ViewStyle } from 'react-native' ;
3
12
import { DateTimePickerPackage as RNDateTimePicker , MomentPackage as moment } from '../../optionalDependencies' ;
4
- import { useDidUpdate } from 'hooks' ;
13
+ import { useDidUpdate } from '../../ hooks' ;
5
14
import { Colors } from '../../style' ;
6
15
import Assets from '../../assets' ;
7
16
import { Constants , asBaseComponent , BaseComponentInjectedProps } from '../../commons/new' ;
@@ -10,7 +19,7 @@ import {DialogProps} from '../dialog';
10
19
import View from '../view' ;
11
20
import Button from '../button' ;
12
21
import ExpandableOverlay , { ExpandableOverlayMethods , RenderCustomOverlayProps } from '../../incubator/expandableOverlay' ;
13
- import type { TextFieldProps } from '../../incubator/TextField' ;
22
+ import type { TextFieldProps , TextFieldMethods } from '../../incubator/TextField' ;
14
23
15
24
const MODES = {
16
25
DATE : 'date' ,
@@ -98,11 +107,10 @@ export type DateTimePickerProps = Omit<TextFieldProps, 'value' | 'onChange'> & {
98
107
* Should migrate to the new TextField implementation
99
108
*/
100
109
migrateTextField ?: boolean ;
101
- }
110
+ } ;
102
111
103
112
type DateTimePickerPropsInternal = DateTimePickerProps & BaseComponentInjectedProps ;
104
113
105
-
106
114
/*eslint-disable*/
107
115
/**
108
116
* @description : Date and Time Picker Component that wraps RNDateTimePicker for date and time modes.
@@ -113,7 +121,7 @@ type DateTimePickerPropsInternal = DateTimePickerProps & BaseComponentInjectedPr
113
121
* @gif : https://github.com/wix/react-native-ui-lib/blob/master/demo/showcase/DateTimePicker/DateTimePicker_iOS.gif?raw=true, https://github.com/wix/react-native-ui-lib/blob/master/demo/showcase/DateTimePicker/DateTimePicker_Android.gif?raw=true
114
122
*/
115
123
/*eslint-enable*/
116
- function DateTimePicker ( props : DateTimePickerPropsInternal ) {
124
+ const DateTimePicker = forwardRef ( ( props : DateTimePickerPropsInternal , ref : ForwardedRef < any > ) => {
117
125
const {
118
126
value : propsValue ,
119
127
renderInput,
@@ -143,6 +151,13 @@ function DateTimePicker(props: DateTimePickerPropsInternal) {
143
151
const [ value , setValue ] = useState ( propsValue ) ;
144
152
const chosenDate = useRef ( propsValue ) ;
145
153
const expandable = useRef < ExpandableOverlayMethods > ( ) ;
154
+ const textField = useRef < TextFieldMethods > ( ) ;
155
+
156
+ useImperativeHandle ( ref , ( ) => {
157
+ return {
158
+ validate : ( ) => textField . current ?. validate ( )
159
+ } ;
160
+ } ) ;
146
161
147
162
useEffect ( ( ) => {
148
163
if ( ! RNDateTimePicker ) {
@@ -322,6 +337,8 @@ function DateTimePicker(props: DateTimePickerPropsInternal) {
322
337
) : (
323
338
< TextField
324
339
{ ...others }
340
+ // @ts -expect-error
341
+ ref = { textField }
325
342
migrate = { migrateTextField }
326
343
testID = { testID }
327
344
editable = { editable }
@@ -333,7 +350,7 @@ function DateTimePicker(props: DateTimePickerPropsInternal) {
333
350
</ ExpandableOverlay >
334
351
</ >
335
352
) ;
336
- }
353
+ } ) ;
337
354
338
355
DateTimePicker . displayName = 'DateTimePicker' ;
339
356
export { DateTimePicker } ; // For tests
0 commit comments