Skip to content

Commit 0a9cc34

Browse files
Arjan-Zuidemafacebook-github-bot
authored andcommitted
Added userInterfaceStyle prop to ActionSheetmanager to override user interface style for iOS 13 (#26401)
Summary: Support to override actionsheet and share interface style to match your app. For example, when your app has it's own theming you want to match the stying on actionsheet and the share menu. ## Changelog [iOS] [Added] - Added userInterfaceStyle for ActionSheetIOS and Share to override user interface style on IOS 13 Pull Request resolved: #26401 Test Plan: Set dark style ![dark](https://user-images.githubusercontent.com/30040390/64685321-12a53080-d487-11e9-8846-f2ef89e114a2.jpg) Set light style ![light](https://user-images.githubusercontent.com/30040390/64685322-12a53080-d487-11e9-9dfd-1e07b9fe0ce2.jpg) Differential Revision: D17314080 Pulled By: hramos fbshipit-source-id: f84278ca99ba20347d17e27295f661d6690fa68c
1 parent 061f54e commit 0a9cc34

File tree

5 files changed

+50
-2
lines changed

5 files changed

+50
-2
lines changed

Libraries/ActionSheetIOS/ActionSheetIOS.js

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const ActionSheetIOS = {
4646
+cancelButtonIndex?: ?number,
4747
+anchor?: ?number,
4848
+tintColor?: number | string,
49+
+userInterfaceStyle?: string,
4950
|},
5051
callback: (buttonIndex: number) => void,
5152
) {

Libraries/ActionSheetIOS/NativeActionSheetManager.js

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export interface Spec extends TurboModule {
2424
+cancelButtonIndex?: ?number,
2525
+anchor?: ?number,
2626
+tintColor?: ?number,
27+
+userInterfaceStyle?: ?string,
2728
|},
2829
callback: (buttonIndex: number) => void,
2930
) => void;
@@ -35,6 +36,7 @@ export interface Spec extends TurboModule {
3536
+anchor?: ?number,
3637
+tintColor?: ?number,
3738
+excludedActivityTypes?: ?Array<string>,
39+
+userInterfaceStyle?: ?string,
3840
|},
3941
failureCallback: (error: {|
4042
+domain: string,

Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h

+12
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ namespace JS {
117117
folly::Optional<double> cancelButtonIndex() const;
118118
folly::Optional<double> anchor() const;
119119
folly::Optional<double> tintColor() const;
120+
NSString *userInterfaceStyle() const;
120121

121122
SpecShowActionSheetWithOptionsOptions(NSDictionary *const v) : _v(v) {}
122123
private:
@@ -138,6 +139,7 @@ namespace JS {
138139
folly::Optional<double> anchor() const;
139140
folly::Optional<double> tintColor() const;
140141
folly::Optional<facebook::react::LazyVector<NSString *>> excludedActivityTypes() const;
142+
NSString *userInterfaceStyle() const;
141143

142144
SpecShowShareActionSheetWithOptionsOptions(NSDictionary *const v) : _v(v) {}
143145
private:
@@ -2935,6 +2937,11 @@ inline folly::Optional<double> JS::NativeActionSheetManager::SpecShowActionSheet
29352937
id const p = _v[@"tintColor"];
29362938
return RCTBridgingToOptionalDouble(p);
29372939
}
2940+
inline NSString *JS::NativeActionSheetManager::SpecShowActionSheetWithOptionsOptions::userInterfaceStyle() const
2941+
{
2942+
id const p = _v[@"userInterfaceStyle"];
2943+
return RCTBridgingToString(p);
2944+
}
29382945
inline NSString *JS::NativeActionSheetManager::SpecShowShareActionSheetWithOptionsOptions::message() const
29392946
{
29402947
id const p = _v[@"message"];
@@ -2965,6 +2972,11 @@ inline folly::Optional<facebook::react::LazyVector<NSString *>> JS::NativeAction
29652972
id const p = _v[@"excludedActivityTypes"];
29662973
return RCTBridgingToOptionalVec(p, ^NSString *(id itemValue_0) { return RCTBridgingToString(itemValue_0); });
29672974
}
2975+
inline NSString *JS::NativeActionSheetManager::SpecShowShareActionSheetWithOptionsOptions::userInterfaceStyle() const
2976+
{
2977+
id const p = _v[@"userInterfaceStyle"];
2978+
return RCTBridgingToString(p);
2979+
}
29682980
inline NSString *JS::NativeActionSheetManager::SpecShowShareActionSheetWithOptionsFailureCallbackError::domain() const
29692981
{
29702982
id const p = _v[@"domain"];

React/CoreModules/RCTActionSheetManager.mm

+30
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,21 @@ - (void)presentViewController:(UIViewController *)alertController
129129
}
130130

131131
alertController.view.tintColor = tintColor;
132+
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
133+
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
134+
if (@available(iOS 13.0, *)) {
135+
NSString *userInterfaceStyle = [RCTConvert NSString:options.userInterfaceStyle()];
136+
137+
if (userInterfaceStyle == nil || [userInterfaceStyle isEqualToString:@""]) {
138+
alertController.overrideUserInterfaceStyle = UIUserInterfaceStyleUnspecified;
139+
} else if ([userInterfaceStyle isEqualToString:@"dark"]) {
140+
alertController.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;
141+
} else if ([userInterfaceStyle isEqualToString:@"light"]) {
142+
alertController.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
143+
}
144+
}
145+
#endif
146+
132147
[self presentViewController:alertController onParentViewController:controller anchorViewTag:anchorViewTag];
133148
}
134149

@@ -191,6 +206,21 @@ - (void)presentViewController:(UIViewController *)alertController
191206
NSNumber *anchorViewTag = [RCTConvert NSNumber:options.anchor() ? @(*options.anchor()) : nil];
192207
shareController.view.tintColor = [RCTConvert UIColor:options.tintColor() ? @(*options.tintColor()) : nil];
193208

209+
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
210+
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
211+
if (@available(iOS 13.0, *)) {
212+
NSString *userInterfaceStyle = [RCTConvert NSString:options.userInterfaceStyle()];
213+
214+
if (userInterfaceStyle == nil || [userInterfaceStyle isEqualToString:@""]) {
215+
shareController.overrideUserInterfaceStyle = UIUserInterfaceStyleUnspecified;
216+
} else if ([userInterfaceStyle isEqualToString:@"dark"]) {
217+
shareController.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;
218+
} else if ([userInterfaceStyle isEqualToString:@"light"]) {
219+
shareController.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
220+
}
221+
}
222+
#endif
223+
194224
[self presentViewController:shareController onParentViewController:controller anchorViewTag:anchorViewTag];
195225
}
196226

React/CoreModules/RCTDevLoadingView.mm

+5-2
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,13 @@ -(void)showMessage:(NSString *)message color:(UIColor *)color backgroundColor:(U
103103
self->_window.backgroundColor = backgroundColor;
104104
self->_window.hidden = NO;
105105

106+
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
107+
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
106108
if (@available(iOS 13.0, *)) {
107-
id scene = [[RCTSharedApplication() valueForKey:@"connectedScenes"] anyObject];
108-
[self->_window setValue:scene forKey:@"windowScene"];
109+
UIWindowScene *scene = (UIWindowScene *)RCTSharedApplication().connectedScenes.anyObject;
110+
self->_window.windowScene = scene;
109111
}
112+
#endif
110113
});
111114
}
112115

0 commit comments

Comments
 (0)