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: https://github.com/facebook/react-native/pull/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
This commit is contained in:
Arjan Zuidema 2020-02-28 00:05:53 -08:00 коммит произвёл Facebook Github Bot
Родитель 061f54e890
Коммит 0a9cc34dd8
5 изменённых файлов: 50 добавлений и 2 удалений

Просмотреть файл

@ -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 @@ RCT_EXPORT_METHOD(showActionSheetWithOptions:(JS::NativeActionSheetManager::Spec
}
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 @@ RCT_EXPORT_METHOD(showShareActionSheetWithOptions:(JS::NativeActionSheetManager:
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 @@ RCT_EXPORT_MODULE()
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
});
}