Skip to content
Permalink
Browse files
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
  • Loading branch information
Arjan-Zuidema authored and facebook-github-bot committed Feb 28, 2020
1 parent 061f54e commit 0a9cc34dd82a3a7dba576997ebd424b12876dbaa
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
@@ -46,6 +46,7 @@ const ActionSheetIOS = {
+cancelButtonIndex?: ?number,
+anchor?: ?number,
+tintColor?: number | string,
+userInterfaceStyle?: string,
|},
callback: (buttonIndex: number) => void,
) {
@@ -24,6 +24,7 @@ export interface Spec extends TurboModule {
+cancelButtonIndex?: ?number,
+anchor?: ?number,
+tintColor?: ?number,
+userInterfaceStyle?: ?string,
|},
callback: (buttonIndex: number) => void,
) => void;
@@ -35,6 +36,7 @@ export interface Spec extends TurboModule {
+anchor?: ?number,
+tintColor?: ?number,
+excludedActivityTypes?: ?Array<string>,
+userInterfaceStyle?: ?string,
|},
failureCallback: (error: {|
+domain: string,
@@ -117,6 +117,7 @@ namespace JS {
folly::Optional<double> cancelButtonIndex() const;
folly::Optional<double> anchor() const;
folly::Optional<double> tintColor() const;
NSString *userInterfaceStyle() const;

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

SpecShowShareActionSheetWithOptionsOptions(NSDictionary *const v) : _v(v) {}
private:
@@ -2935,6 +2937,11 @@ inline folly::Optional<double> JS::NativeActionSheetManager::SpecShowActionSheet
id const p = _v[@"tintColor"];
return RCTBridgingToOptionalDouble(p);
}
inline NSString *JS::NativeActionSheetManager::SpecShowActionSheetWithOptionsOptions::userInterfaceStyle() const
{
id const p = _v[@"userInterfaceStyle"];
return RCTBridgingToString(p);
}
inline NSString *JS::NativeActionSheetManager::SpecShowShareActionSheetWithOptionsOptions::message() const
{
id const p = _v[@"message"];
@@ -2965,6 +2972,11 @@ inline folly::Optional<facebook::react::LazyVector<NSString *>> JS::NativeAction
id const p = _v[@"excludedActivityTypes"];
return RCTBridgingToOptionalVec(p, ^NSString *(id itemValue_0) { return RCTBridgingToString(itemValue_0); });
}
inline NSString *JS::NativeActionSheetManager::SpecShowShareActionSheetWithOptionsOptions::userInterfaceStyle() const
{
id const p = _v[@"userInterfaceStyle"];
return RCTBridgingToString(p);
}
inline NSString *JS::NativeActionSheetManager::SpecShowShareActionSheetWithOptionsFailureCallbackError::domain() const
{
id const p = _v[@"domain"];
@@ -129,6 +129,21 @@ - (void)presentViewController:(UIViewController *)alertController
}

alertController.view.tintColor = tintColor;
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
if (@available(iOS 13.0, *)) {
NSString *userInterfaceStyle = [RCTConvert NSString:options.userInterfaceStyle()];

if (userInterfaceStyle == nil || [userInterfaceStyle isEqualToString:@""]) {
alertController.overrideUserInterfaceStyle = UIUserInterfaceStyleUnspecified;
} else if ([userInterfaceStyle isEqualToString:@"dark"]) {
alertController.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;
} else if ([userInterfaceStyle isEqualToString:@"light"]) {
alertController.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
}
}
#endif

[self presentViewController:alertController onParentViewController:controller anchorViewTag:anchorViewTag];
}

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

#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
if (@available(iOS 13.0, *)) {
NSString *userInterfaceStyle = [RCTConvert NSString:options.userInterfaceStyle()];

if (userInterfaceStyle == nil || [userInterfaceStyle isEqualToString:@""]) {
shareController.overrideUserInterfaceStyle = UIUserInterfaceStyleUnspecified;
} else if ([userInterfaceStyle isEqualToString:@"dark"]) {
shareController.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;
} else if ([userInterfaceStyle isEqualToString:@"light"]) {
shareController.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
}
}
#endif

[self presentViewController:shareController onParentViewController:controller anchorViewTag:anchorViewTag];
}

@@ -103,10 +103,13 @@ -(void)showMessage:(NSString *)message color:(UIColor *)color backgroundColor:(U
self->_window.backgroundColor = backgroundColor;
self->_window.hidden = NO;

#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
if (@available(iOS 13.0, *)) {
id scene = [[RCTSharedApplication() valueForKey:@"connectedScenes"] anyObject];
[self->_window setValue:scene forKey:@"windowScene"];
UIWindowScene *scene = (UIWindowScene *)RCTSharedApplication().connectedScenes.anyObject;
self->_window.windowScene = scene;
}
#endif
});
}

0 comments on commit 0a9cc34

Please sign in to comment.