Skip to content

Commit b0280c8

Browse files
authored
feat: allow overriding the iOS modal theme (light/dark) (#465)
1 parent fbb6e59 commit b0280c8

File tree

6 files changed

+28
-1
lines changed

6 files changed

+28
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ export default () => {
175175
| `title` | Modal only: Title text. Can be set to null to remove text. |
176176
| `confirmText` | Modal only: Confirm button text. |
177177
| `cancelText` | Modal only: Cancel button text. |
178+
| `theme` | Modal only, iOS 13+: The theme of the modal. `"light"`, `"dark"`, `"auto"`. Defaults to `"auto"`. |
178179

179180
## Linking
180181

index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ export interface DatePickerProps extends ViewProps {
100100

101101
/** Modal title. Set to null to remove */
102102
title?: string | null
103+
104+
/** Modal color theme on iOS. Defaults to 'auto' */
105+
theme?: 'light' | 'dark' | 'auto'
103106
}
104107

105108
export default class DatePicker extends Component<DatePickerProps> {}

ios/RNDatePicker/RNDatePickerManager.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,17 @@ - (UIView *)view
114114
[picker setTimeZone:[RCTConvert NSTimeZone:timeZoneProp]];
115115
}
116116

117+
if(@available(iOS 13, *)) {
118+
NSString * _Nonnull theme = [RCTConvert NSString:[props objectForKey:@"theme"]];
119+
if ([theme isEqualToString:@"light"]) {
120+
alertController.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
121+
} else if ([theme isEqualToString:@"dark"]) {
122+
alertController.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;
123+
} else {
124+
alertController.overrideUserInterfaceStyle = UIUserInterfaceStyleUnspecified;
125+
}
126+
}
127+
117128
[alertView addSubview:picker];
118129

119130
UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:confirmText style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

src/DatePickerIOS.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export default class DatePickerIOS extends React.Component {
3636
locale: props.locale ? props.locale : undefined,
3737
maximumDate: props.maximumDate ? props.maximumDate.getTime() : undefined,
3838
minimumDate: props.minimumDate ? props.minimumDate.getTime() : undefined,
39+
theme: props.theme ? props.theme : 'auto',
3940
}
4041
}
4142

src/propChecker.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,17 @@ const androidVariantCheck = new PropCheck(
5353
"Invalid android variant. Valid modes: 'nativeAndroid', 'iosClone'"
5454
)
5555

56+
const themeCheck = new PropCheck(
57+
(props) =>
58+
props && props.theme && !['light', 'dark', 'auto'].includes(props.theme),
59+
"Invalid theme. Valid options: 'light', 'dark', 'auto'"
60+
)
61+
5662
const checks = [
5763
dateCheck,
5864
widthCheck,
5965
heightCheck,
6066
modeCheck,
6167
androidVariantCheck,
68+
themeCheck,
6269
]

src/propTypes.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ const androidPropTypes = {
88
is24hourSource: PropTypes.oneOf(['locale', 'device']),
99
}
1010

11+
const iOSPropTypes = {
12+
theme: PropTypes.oneOf(['light', 'dark', 'auto']),
13+
}
14+
1115
const modalPropTypes = {
1216
modal: PropTypes.bool,
1317
open: PropTypes.bool,
@@ -21,7 +25,7 @@ const modalPropTypes = {
2125
const DateType = PropTypes.instanceOf(Date)
2226

2327
export default {
24-
...(Platform === 'android' ? androidPropTypes : {}),
28+
...(Platform === 'android' ? androidPropTypes : iOSPropTypes),
2529
date: DateType.isRequired,
2630
onChange: PropTypes.func,
2731
minimumDate: DateType,

0 commit comments

Comments
 (0)