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] UIViewController-based status bar management #25919

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9cc5b5e
[Modal] Modernize Modal to use RootTagContext
radex Jun 28, 2019
7c3913c
[StatusBar] Support UIWindowScene APIs - WIP
radex Jun 28, 2019
55a8a68
[ios] RCTPresentedViewController - make window explicit
radex Jun 28, 2019
4601e22
[ios] pass rootTag to Alert, ActionSheetIOS
radex Jun 28, 2019
43259a4
Don't rely on UIAppDelegate.window
radex Jun 28, 2019
7b329fb
[ios] clean up
radex Jun 28, 2019
41db410
Merge branch 'master' of https://github.com/facebook/react-native int…
radex Jun 28, 2019
5938026
Merge branch 'master' into per-uiscene-statusbar
radex Aug 2, 2019
5724e11
[uiscene] rootTag -> any surface (root tag, host object, component ref)
radex Aug 2, 2019
303e7a7
fix imports
radex Aug 2, 2019
e3dd976
fix potential crash
radex Aug 2, 2019
47e2475
Add RNTester examples of passing surface
radex Aug 2, 2019
dc44848
fix types
radex Aug 2, 2019
1b90cb8
fix types - take 2
radex Aug 2, 2019
2a28625
fix types - take 3
radex Aug 2, 2019
6fa1bb3
RCTRootViewController
radex Aug 2, 2019
d3f63dd
RCTStatusBarManager - use view controller-based status bar management
radex Aug 2, 2019
bbe3f9c
Update template
radex Aug 2, 2019
4ca185d
fix types - take 4
radex Aug 2, 2019
0989f93
Merge branch 'per-uiscene-statusbar' into root-view-controller
radex Aug 2, 2019
e699526
i give up, flow
radex Aug 2, 2019
76cc618
Merge branch 'master' into per-uiscene-statusbar
hramos Aug 22, 2019
2090958
Merge branch 'master' into root-view-controller
hramos Aug 22, 2019
ccfb397
unbreak merge?
radex Sep 27, 2019
b45fec4
Merge remote-tracking branch 'facebook/master' into per-uiscene-statu…
radex Sep 27, 2019
2267b91
Alert - make options read-only
radex Sep 27, 2019
1800be9
fix some flow issues
radex Sep 27, 2019
e6f5e93
fix flow issues
radex Sep 27, 2019
b539e51
Merge branch 'per-uiscene-statusbar' into root-view-controller
radex Sep 27, 2019
125aedb
fix merge
radex Sep 27, 2019
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