Skip to content

Commit 2e6504f

Browse files
authored
feat(ios): support passing view props (#693)
1 parent 7bb2ebd commit 2e6504f

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,13 @@ React Native date & time picker component for iOS, Android and Windows.
7676
- [`themeVariant` (`optional`, `iOS only`)](#themevariant-optional-ios-only)
7777
- [`locale` (`optional`, `iOS only`)](#locale-optional-ios-only)
7878
- [`is24Hour` (`optional`, `Windows and Android only`)](#is24hour-optional-windows-and-android-only)
79-
- [`positiveButtonLabel` (`optional`, `Android only`)](#positiveButtonLabel-optional-android-only)
80-
- [`negativeButtonLabel` (`optional`, `Android only`)](#negativeButtonLabel-optional-android-only)
81-
- [`neutralButtonLabel` (`optional`, `Android only`)](#neutralbuttonlabel-optional-android-only)
79+
- [`positiveButton` (`optional`, `Android only`)](#positiveButton-optional-android-only)
80+
- [`negativeButton` (`optional`, `Android only`)](#negativeButton-optional-android-only)
81+
- [`neutralButton` (`optional`, `Android only`)](#neutralButton-optional-android-only)
8282
- [`minuteInterval` (`optional`)](#minuteinterval-optional)
8383
- [`style` (`optional`, `iOS only`)](#style-optional-ios-only)
8484
- [`disabled` (`optional`, `iOS only`)](#disabled-optional-ios-only)
85+
- [`view props` (`optional`, `iOS only`)](#view-props-optional-ios-only)
8586
- [`onError` (`optional`, `Android only`)](#onError-optional-android-only)
8687
- [Testing with Jest](#testing-with-jest)
8788
- [Migration from the older components](#migration-from-the-older-components)
@@ -448,7 +449,7 @@ Allows displaying neutral button on picker dialog.
448449
Pressing button can be observed in onChange handler as `event.type === 'neutralButtonPressed'`
449450

450451
```js
451-
<RNDateTimePicker neutralButton={{label: 'Clear', textColor: 'red'}} />
452+
<RNDateTimePicker neutralButton={{label: 'Clear', textColor: 'grey'}} />
452453
```
453454

454455
#### `negativeButton` (`optional`, `Android only`)
@@ -515,6 +516,10 @@ Alternatively, use the `themeVariant` prop.
515516

516517
If true, the user won't be able to interact with the view.
517518

519+
#### `View Props` (`optional`, `iOS only`)
520+
521+
On iOS, you can pass any [View props](https://reactnative.dev/docs/view#props) to the component. Given that the underlying component is a native view, not all of them are guaranteed to be supported, but `testID` and `onLayout` are known to work.
522+
518523
#### `onError` (`optional`, `Android only`)
519524

520525
Callback that is called when an error occurs inside the date picker native code (such as null activity).

src/datetimepicker.ios.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ export default function Picker({
4848
locale,
4949
maximumDate,
5050
minimumDate,
51-
style,
52-
testID,
5351
minuteInterval,
5452
timeZoneOffsetInMinutes,
5553
textColor,
@@ -59,6 +57,7 @@ export default function Picker({
5957
mode = IOS_MODE.date,
6058
display: providedDisplay = IOS_DISPLAY.default,
6159
disabled = false,
60+
...other
6261
}: IOSNativeProps): React.Node {
6362
sharedPropsValidation({value});
6463

@@ -92,8 +91,7 @@ export default function Picker({
9291

9392
return (
9493
<RNDateTimePicker
95-
testID={testID}
96-
style={style}
94+
{...other}
9795
date={dateToMilliseconds(value)}
9896
locale={locale !== null && locale !== '' ? locale : undefined}
9997
maximumDate={dateToMilliseconds(maximumDate)}

src/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type TimeOptions = Readonly<
6363
}
6464
>;
6565

66-
export type BaseProps = Readonly<ViewProps & DateOptions>;
66+
export type BaseProps = Readonly<Omit<ViewProps, 'children'> & DateOptions>;
6767

6868
export type IOSNativeProps = Readonly<
6969
BaseProps & {

src/types.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import type {SyntheticEvent} from 'react-native/Libraries/Types/CoreEventTypes';
77
import type {HostComponent} from 'react-native';
88
import type {ViewProps} from 'react-native/Libraries/Components/View/ViewPropTypes';
9-
import type {ElementRef} from 'react';
9+
import type {ElementRef, Node} from 'react';
1010
import type {ColorValue} from 'react-native/Libraries/StyleSheet/StyleSheet';
1111
import {
1212
ANDROID_MODE,
@@ -84,8 +84,13 @@ type TimeOptions = $ReadOnly<{|
8484
is24Hour?: ?boolean,
8585
|}>;
8686

87+
type ViewPropsWithoutChildren = $Diff<
88+
ViewProps,
89+
{children: ViewProps['children']},
90+
>;
91+
8792
export type BaseProps = $ReadOnly<{|
88-
...ViewProps,
93+
...ViewPropsWithoutChildren,
8994
...DateOptions,
9095
|}>;
9196

0 commit comments

Comments
 (0)