Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Moving towards UIWindowScene support #25425

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions Libraries/ActionSheetIOS/ActionSheetIOS.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'use strict';

import RCTActionSheetManager from './NativeActionSheetManager';
import ReactNative from '../Renderer/shims/ReactNative';

const invariant = require('invariant');
const processColor = require('../StyleSheet/processColor');
Expand Down Expand Up @@ -40,11 +41,13 @@ const ActionSheetIOS = {
options: {|
+title?: ?string,
+message?: ?string,
+options: Array<string>,
+options: ?Array<string>,
// Supports Array<number> as well.
+destructiveButtonIndex?: ?number,
+cancelButtonIndex?: ?number,
+anchor?: ?number,
+tintColor?: number | string,
+tintColor?: ?number | string,
+surface?: mixed,
|},
callback: (buttonIndex: number) => void,
) {
Expand All @@ -55,10 +58,11 @@ const ActionSheetIOS = {
invariant(typeof callback === 'function', 'Must provide a valid callback');
invariant(RCTActionSheetManager, "ActionSheetManager does't exist");

const {tintColor, ...remainingOptions} = options;
const {tintColor, surface, ...remainingOptions} = options;
const reactTag = ReactNative.findNodeHandle(surface) ?? -1;

RCTActionSheetManager.showActionSheetWithOptions(
{...remainingOptions, tintColor: processColor(tintColor)},
{...remainingOptions, reactTag, tintColor: processColor(tintColor)},
callback,
);
},
Expand Down Expand Up @@ -87,9 +91,17 @@ const ActionSheetIOS = {
* See http://facebook.github.io/react-native/docs/actionsheetios.html#showshareactionsheetwithoptions
*/
showShareActionSheetWithOptions(
options: Object,
options: {|
+message?: ?string,
+url?: ?string,
+subject?: ?string,
+anchor?: ?number,
+tintColor?: ?number | string,
+excludedActivityTypes?: ?Array<string>,
+surface?: mixed,
|},
failureCallback: Function,
successCallback: Function,
successCallback: (completed: boolean, activityType: ?string) => void,
) {
invariant(
typeof options === 'object' && options !== null,
Expand All @@ -104,8 +116,16 @@ const ActionSheetIOS = {
'Must provide a valid successCallback',
);
invariant(RCTActionSheetManager, "ActionSheetManager does't exist");

const {tintColor, surface, ...remainingOptions} = options;
const reactTag = ReactNative.findNodeHandle(surface) ?? -1;

RCTActionSheetManager.showShareActionSheetWithOptions(
{...options, tintColor: processColor(options.tintColor)},
{
...remainingOptions,
reactTag,
tintColor: processColor(options.tintColor),
},
failureCallback,
successCallback,
);
Expand Down
2 changes: 2 additions & 0 deletions Libraries/ActionSheetIOS/NativeActionSheetManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface Spec extends TurboModule {
+cancelButtonIndex?: ?number,
+anchor?: ?number,
+tintColor?: ?number,
+reactTag?: number,
|},
callback: (buttonIndex: number) => void,
) => void;
Expand All @@ -36,6 +37,7 @@ export interface Spec extends TurboModule {
+anchor?: ?number,
+tintColor?: ?number,
+excludedActivityTypes?: ?Array<string>,
+reactTag?: number,
|},
failureCallback: (error: {|
+domain: string,
Expand Down
13 changes: 9 additions & 4 deletions Libraries/ActionSheetIOS/RCTActionSheetManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ - (void)presentViewController:(UIViewController *)alertController
destructiveButtonIndices = @[destructiveButtonIndex];
}

UIViewController *controller = RCTPresentedViewController();
NSNumber *reactTag = options[@"reactTag"] ? [RCTConvert NSNumber:options[@"reactTag"]] : @-1;
UIView *view = [self.bridge.uiManager viewForReactTag:reactTag];
UIViewController *controller = RCTPresentedViewController(view.window);

if (controller == nil) {
RCTLogError(@"Tried to display action sheet but there is no application window. options: %@", options);
Expand All @@ -86,7 +88,7 @@ - (void)presentViewController:(UIViewController *)alertController
* defaults to centering the share popup on screen without any arrows.
*/
NSNumber *anchorViewTag = [RCTConvert NSNumber:options[@"anchor"]];

UIAlertController *alertController =
[UIAlertController alertControllerWithTitle:title
message:message
Expand Down Expand Up @@ -162,7 +164,10 @@ - (void)presentViewController:(UIViewController *)alertController
shareController.excludedActivityTypes = excludedActivityTypes;
}

UIViewController *controller = RCTPresentedViewController();
NSNumber *reactTag = options[@"reactTag"] ? [RCTConvert NSNumber:options[@"reactTag"]] : @-1;
UIView *view = [self.bridge.uiManager viewForReactTag:reactTag];
UIViewController *controller = RCTPresentedViewController(view.window);

shareController.completionWithItemsHandler = ^(NSString *activityType, BOOL completed, __unused NSArray *returnedItems, NSError *activityError) {
if (activityError) {
failureCallback(activityError);
Expand All @@ -173,7 +178,7 @@ - (void)presentViewController:(UIViewController *)alertController

NSNumber *anchorViewTag = [RCTConvert NSNumber:options[@"anchor"]];
shareController.view.tintColor = [RCTConvert UIColor:options[@"tintColor"]];

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

Expand Down
22 changes: 16 additions & 6 deletions Libraries/Alert/Alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import NativeDialogManagerAndroid, {
type DialogOptions,
} from '../NativeModules/specs/NativeDialogManagerAndroid';
import RCTAlertManager from './RCTAlertManager';
import ReactNative from '../Renderer/shims/ReactNative';

export type AlertType =
| 'default'
Expand All @@ -29,8 +30,13 @@ export type Buttons = Array<{
}>;

type Options = {
cancelable?: ?boolean,
onDismiss?: ?() => void,
+cancelable?: ?boolean,
+onDismiss?: ?() => void,
+surface?: mixed,
};

type PromptOptions = {
surface?: mixed,
};

/**
Expand All @@ -43,10 +49,12 @@ class Alert {
title: ?string,
message?: ?string,
buttons?: Buttons,
options?: Options,
options?: Options = {},
): void {
if (Platform.OS === 'ios') {
Alert.prompt(title, message, buttons, 'default');
Alert.prompt(title, message, buttons, 'default', undefined, undefined, {
surface: options.surface,
});
} else if (Platform.OS === 'android') {
if (!NativeDialogManagerAndroid) {
return;
Expand All @@ -59,7 +67,7 @@ class Alert {
cancelable: false,
};

if (options && options.cancelable) {
if (options.cancelable) {
config.cancelable = options.cancelable;
}
// At most three buttons (neutral, negative, positive). Ignore rest.
Expand Down Expand Up @@ -92,7 +100,7 @@ class Alert {
buttonPositive.onPress && buttonPositive.onPress();
}
} else if (action === constants.dismissed) {
options && options.onDismiss && options.onDismiss();
options.onDismiss && options.onDismiss();
}
};
const onError = errorMessage => console.warn(errorMessage);
Expand All @@ -107,6 +115,7 @@ class Alert {
type?: ?AlertType = 'plain-text',
defaultValue?: string,
keyboardType?: string,
options?: PromptOptions = {},
): void {
if (Platform.OS === 'ios') {
if (typeof type === 'function') {
Expand Down Expand Up @@ -163,6 +172,7 @@ class Alert {
cancelButtonKey,
destructiveButtonKey,
keyboardType,
reactTag: ReactNative.findNodeHandle(options.surface) ?? -1,
},
(id, value) => {
const cb = callbacks[id];
Expand Down
1 change: 1 addition & 0 deletions Libraries/Alert/NativeAlertManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type Args = {|
cancelButtonKey?: string,
destructiveButtonKey?: string,
keyboardType?: string,
reactTag?: number,
|};

export interface Spec extends TurboModule {
Expand Down
12 changes: 10 additions & 2 deletions Libraries/Components/StatusBar/NativeStatusBarManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,20 @@ export interface Spec extends TurboModule {
* - 'dark-content' (iOS and Android)
* - 'light-content' (iOS)
*/
+setStyle: (statusBarStyle?: ?string, animated?: ?boolean) => void;
+setStyle: (
statusBarStyle?: ?string,
animated?: ?boolean,
reactTag?: number,
) => void;
/**
* - withAnimation is iOS only
* - withAnimation can be: 'none' | 'fade' | 'slide'
*/
+setHidden: (hidden: boolean, withAnimation?: ?string) => void;
+setHidden: (
hidden: boolean,
withAnimation?: ?string,
reactTag?: number,
) => void;
}

export default (TurboModuleRegistry.getEnforcing<Spec>(
Expand Down
Loading