You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Migration from the older components](#migration-from-the-older-components)
87
88
-[Contributing to the component](#contributing-to-the-component)
88
89
-[Manual installation](#manual-installation)
@@ -146,8 +147,8 @@ export const App = () => {
146
147
value: date,
147
148
onChange,
148
149
mode: currentMode,
149
-
is24Hour:true
150
-
})
150
+
is24Hour:true,
151
+
});
151
152
};
152
153
153
154
constshowDatepicker= () => {
@@ -160,16 +161,12 @@ export const App = () => {
160
161
161
162
return (
162
163
<View>
163
-
<View>
164
-
<Button onPress={showDatepicker} title="Show date picker!"/>
165
-
</View>
166
-
<View>
167
-
<Button onPress={showTimepicker} title="Show time picker!"/>
168
-
</View>
164
+
<Button onPress={showDatepicker} title="Show date picker!"/>
165
+
<Button onPress={showTimepicker} title="Show time picker!"/>
169
166
<Text>selected: {date.toLocaleString()}</Text>
170
167
</View>
171
168
);
172
-
}
169
+
};
173
170
```
174
171
175
172
### Component usage on iOS / Android / Windows
@@ -187,7 +184,10 @@ export const App = () => {
187
184
};
188
185
189
186
constshowMode= (currentMode) => {
190
-
setShow(true);
187
+
if (Platform.OS==='android') {
188
+
setShow(false);
189
+
// for iOS, add a button that closes the picker
190
+
}
191
191
setMode(currentMode);
192
192
};
193
193
@@ -201,12 +201,8 @@ export const App = () => {
201
201
202
202
return (
203
203
<View>
204
-
<View>
205
-
<Button onPress={showDatepicker} title="Show date picker!"/>
206
-
</View>
207
-
<View>
208
-
<Button onPress={showTimepicker} title="Show time picker!"/>
209
-
</View>
204
+
<Button onPress={showDatepicker} title="Show date picker!"/>
205
+
<Button onPress={showTimepicker} title="Show time picker!"/>
210
206
<Text>selected: {date.toLocaleString()}</Text>
211
207
{show && (
212
208
<DateTimePicker
@@ -219,12 +215,11 @@ export const App = () => {
219
215
)}
220
216
</View>
221
217
);
222
-
}
218
+
};
223
219
```
224
220
225
221
</details>
226
222
227
-
228
223
## Localization note
229
224
230
225
By localization, we refer to the language (names of months and days), as well as order in which date can be presented in a picker (month/day vs. day/month) and 12 / 24 hour-format.
@@ -241,16 +236,15 @@ There is also the iOS-only locale prop that can be used to force locale in some
241
236
242
237
For Expo, follow the [localization docs](https://docs.expo.dev/distribution/app-stores/#localizing-your-ios-app).
243
238
244
-
245
239
### Android imperative api
246
240
247
241
On Android, you have a choice between using the component API (regular React component) or an imperative api (think of something like `ReactNative.alert()`).
248
242
249
-
While the component API has the benefit of writing the same code on all platforms, to start we recommend using the imperative API on Android.
243
+
While the component API has the benefit of writing the same code on all platforms, for start we recommend using the imperative API on Android.
250
244
251
245
The `params` is an object with the same properties as the component props documented in the next paragraph. (This is also because the component api internally uses the imperative one.)
@@ -294,7 +288,7 @@ List of possible values for Android
294
288
List of possible values for iOS (maps to [preferredDatePickerStyle](https://developer.apple.com/documentation/uikit/uidatepicker/3526124-preferreddatepickerstyle?changes=latest_minor&language=objc))
295
289
296
290
-`"default"` - Automatically pick the best style available for the current platform & mode.
297
-
-`"spinner"` - the usual appearance with a wheel from which you choose values
291
+
-`"spinner"` - the usual pre-iOS 14 appearance with a wheel from which you choose values
298
292
-`"compact"` - Affects only iOS 14 and later. Will fall back to "spinner" if not supported.
299
293
-`"inline"` - Affects only iOS 14 and later. Will fall back to "spinner" if not supported.
300
294
@@ -350,7 +344,7 @@ We strongly recommend avoiding this prop on android because of known issues in t
Allows changing of the time zone of the date picker. By default it uses the device's time zone.
347
+
Allows changing of the time zone of the date picker. By default, it uses the device's time zone.
354
348
355
349
```js
356
350
// UTC+1
@@ -423,7 +417,7 @@ Prefer localization as documented in [Localization note](#localization-note).
423
417
424
418
#### `is24Hour` (`optional`, `Windows and Android only`)
425
419
426
-
Allows changing of the time picker to a 24hour format. By default, this value is decided automatcially based on the locale and other preferences.
420
+
Allows changing of the time picker to a 24-hour format. By default, this value is decided automatically based on the locale and other preferences.
427
421
428
422
```js
429
423
<RNDateTimePicker is24Hour={true} />
@@ -473,7 +467,7 @@ Sets style directly on picker component. By default, the picker height is determ
473
467
474
468
Please note that by default, picker's text color is controlled by the application theme (light / dark mode). In dark mode, text is white and in light mode, text is black.
475
469
476
-
This means that eg. if the device has dark mode turned on, and your screen background color is white, you will not see the picker. Please use the `Appearance` api to adjust the picker's background color so that it is visible, as we do in the [example App](/example/App.js).
470
+
This means that e.g. if the device has dark mode turned on, and your screen background color is white, you will not see the picker. Please use the `Appearance` api to adjust the picker's background color so that it is visible, as we do in the [example App](/example/App.js).
477
471
Alternatively, use the `themeVariant` prop or [opt-out from dark mode (discouraged)](https://stackoverflow.com/a/56546554/2070942).
478
472
479
473
```js
@@ -488,6 +482,16 @@ If true, the user won't be able to interact with the view.
488
482
489
483
Callback that is called when an error occurs inside the date picker native code (such as null activity).
490
484
485
+
## Testing with Jest
486
+
487
+
If you're rendering the picker component (using the `@testing-library/react-native` or similar), you need to mock the native module:
0 commit comments