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
Copy file name to clipboardExpand all lines: README.md
+94-27Lines changed: 94 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
### 🚧🚧 Looking for collaborators and backers 🚧🚧
2
2
3
-
See this [issue](https://github.com/react-native-datetimepicker/datetimepicker/issues/313)
3
+
See this [issue](https://github.com/react-native-datetimepicker/datetimepicker/issues/313).
4
4
5
5
### Backers
6
6
7
-
Support us with a monthly donation and help us continue our activities. [Become a backer on OpenCollective](https://opencollective.com/react-native-datetimepicker) or [sponsor us on GitHub Sponsors](https://github.com/sponsors/react-native-datetimepicker)
7
+
Support us with a monthly donation and help us continue our activities. [Become a backer on OpenCollective](https://opencollective.com/react-native-datetimepicker) or [sponsor us on GitHub Sponsors](https://github.com/sponsors/react-native-datetimepicker).
We give two equivalent examples on how to use the package on all supported platforms.
125
+
126
+
### Recommended imperative api usage on Android
127
+
128
+
While the component-approach as given in the second paragraph works on Android, the recommended approach is to use the imperative api given in the first paragraph.
129
+
130
+
Read more about the motivation in [Android imperative API](#android-imperative-api).
<Button onPress={showTimepicker} title="Show time picker!"/>
164
206
</View>
207
+
<Text>selected: {date.toLocaleString()}</Text>
165
208
{show && (
166
209
<DateTimePicker
167
210
testID="dateTimePicker"
168
211
value={date}
169
212
mode={mode}
170
213
is24Hour={true}
171
-
display="default"
172
214
onChange={onChange}
173
215
/>
174
216
)}
175
217
</View>
176
218
);
177
-
};
219
+
}
178
220
```
179
221
222
+
</details>
223
+
224
+
180
225
## Localization note
181
226
182
227
On Android, the picker will be controlled by the system locale. If you wish to change it, [see instructions here](https://stackoverflow.com/a/2900144/2070942).
@@ -191,11 +236,29 @@ There is also the iOS-only locale prop that can be used to force locale in some
191
236
192
237
For Expo, follow the [localization docs](https://docs.expo.dev/distribution/app-stores/#localizing-your-ios-app).
193
238
194
-
## Props
239
+
240
+
### Android imperative api
241
+
242
+
On Android, you have a choice between using the component API (regular React component) or an imperative api (think something like `ReactNative.alert()`).
243
+
244
+
While the component API has the benefit of writing the same code on all platforms, for start we recommend to use the imperative API on Android.
245
+
246
+
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.)
Reason we recommend the imperative API is: on Android, the date/time picker opens in a dialog, similar to `ReactNative.alert()` from core react native. The imperative api models this behavior better than the declarative component api. While the component approach is perfectly functional, based on the issue tracker history, it appears to be more prone to introducing bugs.
256
+
257
+
## Component props / params of the Android imperative api
195
258
196
259
> Please note that this library currently exposes functionality from [`UIDatePicker`](https://developer.apple.com/documentation/uikit/uidatepicker?language=objc) on iOS and [DatePickerDialog](https://developer.android.com/reference/android/app/DatePickerDialog) + [TimePickerDialog](https://developer.android.com/reference/android/app/TimePickerDialog) on Android, and [`CalendarDatePicker`](https://docs.microsoft.com/en-us/windows/uwp/design/controls-and-patterns/calendar-date-picker) +[TimePicker](https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.timepicker?view=winrt-19041) on Windows.
197
260
>
198
-
> These native classes offer only limited configuration, while there are dozens of possible options you as a developer may need. It follows that if your requirement is not supported by the backing native views, this library will _not_ be able to implement your requirement. When you open an issue with a feature request, please document if (or how) the feature can be implemented using the aforementioned native views. If those views do not support what you need, such feature requests will be closed as not actionable.
261
+
> These native classes offer only limited configuration, while there are dozens of possible options you as a developer may need. It follows that if your requirement is not supported by the backing native views, this library will _not_ be able to implement your requirement. When you open an issue with a feature request, please document if (or how) the feature can be implemented using the aforementioned native views. If the native views do not support what you need, such feature requests will be closed as not actionable.
199
262
200
263
#### `mode` (`optional`)
201
264
@@ -395,6 +458,10 @@ Alternatively, use the `themeVariant` prop or [opt-out from dark mode (discourag
395
458
396
459
If true, the user won't be able to interact with the view.
397
460
461
+
#### `onError` (`optional`, `Android only`)
462
+
463
+
Callback that is called when an error occurs inside the date picker native code (such as null activity).
0 commit comments