From b85cb0cf7aa697016fd7b97d570377cb67eef807 Mon Sep 17 00:00:00 2001 From: Logan Daniels Date: Thu, 5 Mar 2020 15:55:10 -0800 Subject: [PATCH] Back out "Moving towards UIWindowScene support" Summary: Original commit changeset: ae2a4478e2e7 Changelog: [Internal] Reviewed By: hramos Differential Revision: D20289851 fbshipit-source-id: 1167ce8f5135411b80630b523c91c10e2b7eece1 --- Libraries/ActionSheetIOS/ActionSheetIOS.js | 23 ++------ .../NativeActionSheetManager.js | 2 - Libraries/Alert/Alert.js | 18 ++----- Libraries/Alert/NativeAlertManager.js | 1 - Libraries/CameraRoll/RCTImagePickerManager.mm | 4 +- .../StatusBar/NativeStatusBarManagerIOS.js | 12 +---- Libraries/Components/StatusBar/StatusBar.js | 53 +++++-------------- .../FBReactNativeSpec-generated.mm | 8 +-- .../FBReactNativeSpec/FBReactNativeSpec.h | 24 +-------- Libraries/Modal/Modal.js | 13 ++--- .../ActionSheetIOS/ActionSheetIOSExample.js | 6 +-- RNTester/js/examples/Alert/AlertExample.js | 17 +----- .../js/examples/StatusBar/StatusBarExample.js | 26 +-------- React/Base/RCTUtils.h | 2 +- React/Base/RCTUtils.m | 5 +- React/CoreModules/RCTActionSheetManager.mm | 10 +--- React/CoreModules/RCTAlertManager.mm | 36 ++++++------- React/CoreModules/RCTDevMenu.mm | 10 ++-- React/CoreModules/RCTPerfMonitor.mm | 4 +- React/CoreModules/RCTStatusBarManager.mm | 31 +++-------- React/Profiler/RCTProfile.m | 8 +-- .../specs/NativeStatusBarManagerIOSSpec.java | 4 +- .../specs/jni/FBReactNativeSpec-generated.cpp | 8 +-- 23 files changed, 89 insertions(+), 236 deletions(-) diff --git a/Libraries/ActionSheetIOS/ActionSheetIOS.js b/Libraries/ActionSheetIOS/ActionSheetIOS.js index 4a2ffabcbbf..e330253df81 100644 --- a/Libraries/ActionSheetIOS/ActionSheetIOS.js +++ b/Libraries/ActionSheetIOS/ActionSheetIOS.js @@ -11,7 +11,6 @@ 'use strict'; import RCTActionSheetManager from './NativeActionSheetManager'; -import ReactNative from '../Renderer/shims/ReactNative'; const invariant = require('invariant'); const processColor = require('../StyleSheet/processColor'); @@ -44,13 +43,12 @@ const ActionSheetIOS = { options: {| +title?: ?string, +message?: ?string, - +options: ?Array, + +options: Array, +destructiveButtonIndex?: ?number | ?Array, +cancelButtonIndex?: ?number, +anchor?: ?number, +tintColor?: ColorValue | ProcessedColorValue, +userInterfaceStyle?: string, - +surface?: mixed, |}, callback: (buttonIndex: number) => void, ) { @@ -61,13 +59,7 @@ const ActionSheetIOS = { invariant(typeof callback === 'function', 'Must provide a valid callback'); invariant(RCTActionSheetManager, "ActionSheetManager does't exist"); - const { - tintColor, - destructiveButtonIndex, - surface, - ...remainingOptions - } = options; - const reactTag = ReactNative.findNodeHandle(surface) ?? -1; + const {tintColor, destructiveButtonIndex, ...remainingOptions} = options; let destructiveButtonIndices = null; if (Array.isArray(destructiveButtonIndex)) { @@ -84,7 +76,6 @@ const ActionSheetIOS = { RCTActionSheetManager.showActionSheetWithOptions( { ...remainingOptions, - reactTag, tintColor: processedTintColor, destructiveButtonIndices, }, @@ -133,16 +124,8 @@ 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( - { - ...remainingOptions, - reactTag, - tintColor: processColor(options.tintColor), - }, + {...options, tintColor: processColor(options.tintColor)}, failureCallback, successCallback, ); diff --git a/Libraries/ActionSheetIOS/NativeActionSheetManager.js b/Libraries/ActionSheetIOS/NativeActionSheetManager.js index 812084decef..063d9147e1d 100644 --- a/Libraries/ActionSheetIOS/NativeActionSheetManager.js +++ b/Libraries/ActionSheetIOS/NativeActionSheetManager.js @@ -25,7 +25,6 @@ export interface Spec extends TurboModule { +anchor?: ?number, +tintColor?: ?number, +userInterfaceStyle?: ?string, - +reactTag?: number, |}, callback: (buttonIndex: number) => void, ) => void; @@ -38,7 +37,6 @@ export interface Spec extends TurboModule { +tintColor?: ?number, +excludedActivityTypes?: ?Array, +userInterfaceStyle?: ?string, - +reactTag?: number, |}, failureCallback: (error: {| +domain: string, diff --git a/Libraries/Alert/Alert.js b/Libraries/Alert/Alert.js index 44dc762c8ef..e6aead18643 100644 --- a/Libraries/Alert/Alert.js +++ b/Libraries/Alert/Alert.js @@ -15,7 +15,6 @@ import NativeDialogManagerAndroid, { type DialogOptions, } from '../NativeModules/specs/NativeDialogManagerAndroid'; import RCTAlertManager from './RCTAlertManager'; -import ReactNative from '../Renderer/shims/ReactNative'; export type AlertType = | 'default' @@ -33,14 +32,9 @@ export type Buttons = Array<{ type Options = { cancelable?: ?boolean, onDismiss?: ?() => void, - surface?: mixed, ... }; -type PromptOptions = { - surface?: mixed, -}; - /** * Launches an alert dialog with the specified title and message. * @@ -51,12 +45,10 @@ class Alert { title: ?string, message?: ?string, buttons?: Buttons, - options?: Options = {}, + options?: Options, ): void { if (Platform.OS === 'ios') { - Alert.prompt(title, message, buttons, 'default', undefined, undefined, { - surface: options.surface, - }); + Alert.prompt(title, message, buttons, 'default'); } else if (Platform.OS === 'android') { if (!NativeDialogManagerAndroid) { return; @@ -69,7 +61,7 @@ class Alert { cancelable: false, }; - if (options.cancelable) { + if (options && options.cancelable) { config.cancelable = options.cancelable; } // At most three buttons (neutral, negative, positive). Ignore rest. @@ -102,7 +94,7 @@ class Alert { buttonPositive.onPress && buttonPositive.onPress(); } } else if (action === constants.dismissed) { - options.onDismiss && options.onDismiss(); + options && options.onDismiss && options.onDismiss(); } }; const onError = errorMessage => console.warn(errorMessage); @@ -117,7 +109,6 @@ class Alert { type?: ?AlertType = 'plain-text', defaultValue?: string, keyboardType?: string, - options?: PromptOptions = {surface: undefined}, ): void { if (Platform.OS === 'ios') { let callbacks = []; @@ -152,7 +143,6 @@ class Alert { cancelButtonKey, destructiveButtonKey, keyboardType, - reactTag: ReactNative.findNodeHandle(options.surface) ?? -1, }, (id, value) => { const cb = callbacks[id]; diff --git a/Libraries/Alert/NativeAlertManager.js b/Libraries/Alert/NativeAlertManager.js index f181fc36ceb..452be85c5b1 100644 --- a/Libraries/Alert/NativeAlertManager.js +++ b/Libraries/Alert/NativeAlertManager.js @@ -22,7 +22,6 @@ export type Args = {| cancelButtonKey?: string, destructiveButtonKey?: string, keyboardType?: string, - reactTag?: number, |}; export interface Spec extends TurboModule { diff --git a/Libraries/CameraRoll/RCTImagePickerManager.mm b/Libraries/CameraRoll/RCTImagePickerManager.mm index 9f5a777edd9..893a33cd320 100644 --- a/Libraries/CameraRoll/RCTImagePickerManager.mm +++ b/Libraries/CameraRoll/RCTImagePickerManager.mm @@ -204,7 +204,7 @@ didFinishPickingMediaWithInfo:(NSDictionary *)info [_pickerCallbacks addObject:callback]; [_pickerCancelCallbacks addObject:cancelCallback]; - UIViewController *rootViewController = RCTPresentedViewController(nil); + UIViewController *rootViewController = RCTPresentedViewController(); [rootViewController presentViewController:imagePicker animated:YES completion:nil]; } @@ -223,7 +223,7 @@ didFinishPickingMediaWithInfo:(NSDictionary *)info [_pickerCallbacks removeObjectAtIndex:index]; [_pickerCancelCallbacks removeObjectAtIndex:index]; - UIViewController *rootViewController = RCTPresentedViewController(nil); + UIViewController *rootViewController = RCTPresentedViewController(); [rootViewController dismissViewControllerAnimated:YES completion:nil]; if (args) { diff --git a/Libraries/Components/StatusBar/NativeStatusBarManagerIOS.js b/Libraries/Components/StatusBar/NativeStatusBarManagerIOS.js index 95298058f89..ecb6d0329ca 100644 --- a/Libraries/Components/StatusBar/NativeStatusBarManagerIOS.js +++ b/Libraries/Components/StatusBar/NativeStatusBarManagerIOS.js @@ -31,19 +31,11 @@ export interface Spec extends TurboModule { * - 'dark-content' * - 'light-content' */ - +setStyle: ( - statusBarStyle?: ?string, - animated: boolean, - reactTag?: number, - ) => void; + +setStyle: (statusBarStyle?: ?string, animated: boolean) => void; /** * - withAnimation can be: 'none' | 'fade' | 'slide' */ - +setHidden: ( - hidden: boolean, - withAnimation: string, - reactTag?: number, - ) => void; + +setHidden: (hidden: boolean, withAnimation: string) => void; } export default (TurboModuleRegistry.getEnforcing( diff --git a/Libraries/Components/StatusBar/StatusBar.js b/Libraries/Components/StatusBar/StatusBar.js index b3016f47eef..81ab87e4d37 100644 --- a/Libraries/Components/StatusBar/StatusBar.js +++ b/Libraries/Components/StatusBar/StatusBar.js @@ -11,8 +11,6 @@ 'use strict'; const Platform = require('../../Utilities/Platform'); -const RootTagContext = require('../../ReactNative/RootTagContext'); -import ReactNative from '../../Renderer/shims/ReactNative'; const React = require('react'); const invariant = require('invariant'); @@ -266,19 +264,11 @@ class StatusBar extends React.Component { * @param animation Optional animation when * changing the status bar hidden property. */ - static setHidden( - hidden: boolean, - animation?: StatusBarAnimation, - surface?: mixed, - ) { + static setHidden(hidden: boolean, animation?: StatusBarAnimation) { animation = animation || 'none'; StatusBar._defaultProps.hidden.value = hidden; if (Platform.OS === 'ios') { - NativeStatusBarManagerIOS.setHidden( - hidden, - animation, - ReactNative.findNodeHandle(surface) ?? -1, - ); + NativeStatusBarManagerIOS.setHidden(hidden, animation); } else if (Platform.OS === 'android') { NativeStatusBarManagerAndroid.setHidden(hidden); } @@ -289,19 +279,11 @@ class StatusBar extends React.Component { * @param style Status bar style to set * @param animated Animate the style change. */ - static setBarStyle( - style: StatusBarStyle, - animated?: boolean, - surface?: mixed, - ) { + static setBarStyle(style: StatusBarStyle, animated?: boolean) { animated = animated || false; StatusBar._defaultProps.barStyle.value = style; if (Platform.OS === 'ios') { - NativeStatusBarManagerIOS.setStyle( - style, - animated, - ReactNative.findNodeHandle(surface) ?? -1, - ); + NativeStatusBarManagerIOS.setStyle(style, animated); } else if (Platform.OS === 'android') { NativeStatusBarManagerAndroid.setStyle(style); } @@ -310,7 +292,6 @@ class StatusBar extends React.Component { /** * Control the visibility of the network activity indicator * @param visible Show the indicator. - * @platform ios */ static setNetworkActivityIndicatorVisible(visible: boolean) { if (Platform.OS !== 'ios') { @@ -327,7 +308,6 @@ class StatusBar extends React.Component { * Set the background color for the status bar * @param color Background color. * @param animated Animate the style change. - * @platform android */ static setBackgroundColor(color: string, animated?: boolean) { if (Platform.OS !== 'android') { @@ -355,7 +335,6 @@ class StatusBar extends React.Component { /** * Control the translucency of the status bar * @param translucent Set as translucent. - * @platform android */ static setTranslucent(translucent: boolean) { if (Platform.OS !== 'android') { @@ -372,10 +351,10 @@ class StatusBar extends React.Component { * * @param props Object containing the StatusBar props to use in the stack entry. */ - static pushStackEntry(props: any, surface?: mixed): any { + static pushStackEntry(props: any): any { const entry = createStackEntry(props); StatusBar._propsStack.push(entry); - StatusBar._updatePropsStack(surface); + StatusBar._updatePropsStack(); return entry; } @@ -384,12 +363,12 @@ class StatusBar extends React.Component { * * @param entry Entry returned from `pushStackEntry`. */ - static popStackEntry(entry: any, surface?: mixed) { + static popStackEntry(entry: any) { const index = StatusBar._propsStack.indexOf(entry); if (index !== -1) { StatusBar._propsStack.splice(index, 1); } - StatusBar._updatePropsStack(surface); + StatusBar._updatePropsStack(); } /** @@ -398,13 +377,13 @@ class StatusBar extends React.Component { * @param entry Entry returned from `pushStackEntry` to replace. * @param props Object containing the StatusBar props to use in the replacement stack entry. */ - static replaceStackEntry(entry: any, props: any, surface?: mixed): any { + static replaceStackEntry(entry: any, props: any): any { const newEntry = createStackEntry(props); const index = StatusBar._propsStack.indexOf(entry); if (index !== -1) { StatusBar._propsStack[index] = newEntry; } - StatusBar._updatePropsStack(surface); + StatusBar._updatePropsStack(); return newEntry; } @@ -416,9 +395,6 @@ class StatusBar extends React.Component { showHideTransition: 'fade', }; - // $FlowFixMe (signature-verification-failure) - static contextType = RootTagContext; - _stackEntry = null; componentDidMount() { @@ -426,27 +402,26 @@ class StatusBar extends React.Component { // and always update the native status bar with the props from the top of then // stack. This allows having multiple StatusBar components and the one that is // added last or is deeper in the view hierarchy will have priority. - this._stackEntry = StatusBar.pushStackEntry(this.props, this.context); + this._stackEntry = StatusBar.pushStackEntry(this.props); } componentWillUnmount() { // When a StatusBar is unmounted, remove itself from the stack and update // the native bar with the next props. - StatusBar.popStackEntry(this._stackEntry, this.context); + StatusBar.popStackEntry(this._stackEntry); } componentDidUpdate() { this._stackEntry = StatusBar.replaceStackEntry( this._stackEntry, this.props, - this.context, ); } /** * Updates the native status bar with the props from the stack. */ - static _updatePropsStack = (surface?: mixed) => { + static _updatePropsStack = () => { // Send the update to the native module only once at the end of the frame. clearImmediate(StatusBar._updateImmediate); StatusBar._updateImmediate = setImmediate(() => { @@ -465,7 +440,6 @@ class StatusBar extends React.Component { NativeStatusBarManagerIOS.setStyle( mergedProps.barStyle.value, mergedProps.barStyle.animated || false, - ReactNative.findNodeHandle(surface) ?? -1, ); } if (!oldProps || oldProps.hidden.value !== mergedProps.hidden.value) { @@ -474,7 +448,6 @@ class StatusBar extends React.Component { mergedProps.hidden.animated ? mergedProps.hidden.transition : 'none', - ReactNative.findNodeHandle(surface) ?? -1, ); } diff --git a/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec-generated.mm b/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec-generated.mm index 798f20fd069..0b16070524c 100644 --- a/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec-generated.mm +++ b/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec-generated.mm @@ -2310,11 +2310,11 @@ namespace facebook { } static facebook::jsi::Value __hostFunction_NativeStatusBarManagerIOSSpecJSI_setStyle(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { - return static_cast(turboModule).invokeObjCMethod(rt, VoidKind, "setStyle", @selector(setStyle:animated:reactTag:), args, count); + return static_cast(turboModule).invokeObjCMethod(rt, VoidKind, "setStyle", @selector(setStyle:animated:), args, count); } static facebook::jsi::Value __hostFunction_NativeStatusBarManagerIOSSpecJSI_setHidden(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { - return static_cast(turboModule).invokeObjCMethod(rt, VoidKind, "setHidden", @selector(setHidden:withAnimation:reactTag:), args, count); + return static_cast(turboModule).invokeObjCMethod(rt, VoidKind, "setHidden", @selector(setHidden:withAnimation:), args, count); } static facebook::jsi::Value __hostFunction_NativeStatusBarManagerIOSSpecJSI_getConstants(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { @@ -2337,10 +2337,10 @@ namespace facebook { methodMap_["removeListeners"] = MethodMetadata {1, __hostFunction_NativeStatusBarManagerIOSSpecJSI_removeListeners}; - methodMap_["setStyle"] = MethodMetadata {3, __hostFunction_NativeStatusBarManagerIOSSpecJSI_setStyle}; + methodMap_["setStyle"] = MethodMetadata {2, __hostFunction_NativeStatusBarManagerIOSSpecJSI_setStyle}; - methodMap_["setHidden"] = MethodMetadata {3, __hostFunction_NativeStatusBarManagerIOSSpecJSI_setHidden}; + methodMap_["setHidden"] = MethodMetadata {2, __hostFunction_NativeStatusBarManagerIOSSpecJSI_setHidden}; methodMap_["getConstants"] = MethodMetadata {0, __hostFunction_NativeStatusBarManagerIOSSpecJSI_getConstants}; diff --git a/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h b/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h index 8045a3a00da..a6cdf54b5df 100644 --- a/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h +++ b/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h @@ -118,7 +118,6 @@ namespace JS { folly::Optional anchor() const; folly::Optional tintColor() const; NSString *userInterfaceStyle() const; - folly::Optional reactTag() const; SpecShowActionSheetWithOptionsOptions(NSDictionary *const v) : _v(v) {} private: @@ -141,7 +140,6 @@ namespace JS { folly::Optional tintColor() const; folly::Optional> excludedActivityTypes() const; NSString *userInterfaceStyle() const; - folly::Optional reactTag() const; SpecShowShareActionSheetWithOptionsOptions(NSDictionary *const v) : _v(v) {} private: @@ -206,7 +204,6 @@ namespace JS { NSString *cancelButtonKey() const; NSString *destructiveButtonKey() const; NSString *keyboardType() const; - folly::Optional reactTag() const; Args(NSDictionary *const v) : _v(v) {} private: @@ -2489,11 +2486,9 @@ namespace JS { - (void)addListener:(NSString *)eventType; - (void)removeListeners:(double)count; - (void)setStyle:(NSString * _Nullable)statusBarStyle - animated:(BOOL)animated - reactTag:(double)reactTag; + animated:(BOOL)animated; - (void)setHidden:(BOOL)hidden - withAnimation:(NSString *)withAnimation - reactTag:(double)reactTag; + withAnimation:(NSString *)withAnimation; - (facebook::react::ModuleConstants)constantsToExport; - (facebook::react::ModuleConstants)getConstants; @@ -2947,11 +2942,6 @@ inline NSString *JS::NativeActionSheetManager::SpecShowActionSheetWithOptionsOpt id const p = _v[@"userInterfaceStyle"]; return RCTBridgingToString(p); } -inline folly::Optional JS::NativeActionSheetManager::SpecShowActionSheetWithOptionsOptions::reactTag() const -{ - id const p = _v[@"reactTag"]; - return RCTBridgingToOptionalDouble(p); -} inline NSString *JS::NativeActionSheetManager::SpecShowShareActionSheetWithOptionsOptions::message() const { id const p = _v[@"message"]; @@ -2987,11 +2977,6 @@ inline NSString *JS::NativeActionSheetManager::SpecShowShareActionSheetWithOptio id const p = _v[@"userInterfaceStyle"]; return RCTBridgingToString(p); } -inline folly::Optional JS::NativeActionSheetManager::SpecShowShareActionSheetWithOptionsOptions::reactTag() const -{ - id const p = _v[@"reactTag"]; - return RCTBridgingToOptionalDouble(p); -} inline NSString *JS::NativeActionSheetManager::SpecShowShareActionSheetWithOptionsFailureCallbackError::domain() const { id const p = _v[@"domain"]; @@ -3052,11 +3037,6 @@ inline NSString *JS::NativeAlertManager::Args::keyboardType() const id const p = _v[@"keyboardType"]; return RCTBridgingToString(p); } -inline folly::Optional JS::NativeAlertManager::Args::reactTag() const -{ - id const p = _v[@"reactTag"]; - return RCTBridgingToOptionalDouble(p); -} inline bool JS::NativeAnimatedModule::EndResult::finished() const { id const p = _v[@"finished"]; diff --git a/Libraries/Modal/Modal.js b/Libraries/Modal/Modal.js index 0b01dc44849..c588ec5b6ee 100644 --- a/Libraries/Modal/Modal.js +++ b/Libraries/Modal/Modal.js @@ -11,7 +11,6 @@ 'use strict'; const AppContainer = require('../ReactNative/AppContainer'); -const RootTagContext = require('../ReactNative/RootTagContext'); const I18nManager = require('../ReactNative/I18nManager'); const PropTypes = require('prop-types'); const React = require('react'); @@ -147,6 +146,10 @@ class Modal extends React.Component { hardwareAccelerated: false, }; + static contextTypes: any | {|rootTag: React$PropType$Primitive|} = { + rootTag: PropTypes.number, + }; + _identifier: number; _eventSubscription: ?EmitterSubscription; @@ -214,11 +217,9 @@ class Modal extends React.Component { } const innerChildren = __DEV__ ? ( - - {rootTag => ( - {this.props.children} - )} - + + {this.props.children} + ) : ( this.props.children ); diff --git a/RNTester/js/examples/ActionSheetIOS/ActionSheetIOSExample.js b/RNTester/js/examples/ActionSheetIOS/ActionSheetIOSExample.js index 15749a029dc..c1130357829 100644 --- a/RNTester/js/examples/ActionSheetIOS/ActionSheetIOSExample.js +++ b/RNTester/js/examples/ActionSheetIOS/ActionSheetIOSExample.js @@ -169,7 +169,7 @@ class ShareActionSheetExample extends React.Component< (completed, method) => { let text; if (completed) { - text = `Shared via ${method || 'null'}`; + text = `Shared via ${method}`; } else { text = "You didn't share"; } @@ -212,7 +212,7 @@ class ShareScreenshotExample extends React.Component< (completed, method) => { let text; if (completed) { - text = `Shared via ${method || 'null'}`; + text = `Shared via ${method}`; } else { text = "You didn't share"; } @@ -270,7 +270,7 @@ class ShareScreenshotAnchorExample extends React.Component< (completed, method) => { let text; if (completed) { - text = `Shared via ${method || 'null'}`; + text = `Shared via ${method}`; } else { text = "You didn't share"; } diff --git a/RNTester/js/examples/Alert/AlertExample.js b/RNTester/js/examples/Alert/AlertExample.js index 5ffe67edb27..4e362a525f9 100644 --- a/RNTester/js/examples/Alert/AlertExample.js +++ b/RNTester/js/examples/Alert/AlertExample.js @@ -31,13 +31,9 @@ const alertMessage = type Props = $ReadOnly<{||}>; class SimpleAlertExampleBlock extends React.Component { - viewRef: React.MutableRefObject | void> = React.createRef(); - render() { return ( - + Alert.alert('Alert Title', alertMessage)}> @@ -124,17 +120,6 @@ class SimpleAlertExampleBlock extends React.Component { Alert without title - - Alert.alert('Surfaced!', alertMessage, null, { - surface: this.viewRef.current, - }) - }> - - Alert with surface passed - - ); } diff --git a/RNTester/js/examples/StatusBar/StatusBarExample.js b/RNTester/js/examples/StatusBar/StatusBarExample.js index db901838855..60510df9db0 100644 --- a/RNTester/js/examples/StatusBar/StatusBarExample.js +++ b/RNTester/js/examples/StatusBar/StatusBarExample.js @@ -11,6 +11,7 @@ 'use strict'; const React = require('react'); + const { StatusBar, StyleSheet, @@ -257,14 +258,9 @@ class StatusBarTranslucentExample extends React.Component< } class StatusBarStaticIOSExample extends React.Component<{...}> { - // $FlowFixMe - viewRef: React.MutableRefObject | void> = React.createRef(); - render() { return ( - + { @@ -283,15 +279,6 @@ class StatusBarStaticIOSExample extends React.Component<{...}> { setHidden(false, 'fade') - { - StatusBar.setHidden(true, 'fade', this.viewRef.current); - }}> - - setHidden(true, 'fade', componentRef) - - { @@ -310,15 +297,6 @@ class StatusBarStaticIOSExample extends React.Component<{...}> { setBarStyle('light-content', true) - { - StatusBar.setBarStyle('default', false, this.viewRef.current); - }}> - - setBarStyle('default', false, componentRef) - - { diff --git a/React/Base/RCTUtils.h b/React/Base/RCTUtils.h index 8e6ebdfda59..9159d3d820e 100644 --- a/React/Base/RCTUtils.h +++ b/React/Base/RCTUtils.h @@ -84,7 +84,7 @@ RCT_EXTERN UIWindow *__nullable RCTKeyWindow(void); // Returns the presented view controller, useful if you need // e.g. to present a modal view controller or alert over it -RCT_EXTERN UIViewController *__nullable RCTPresentedViewController(UIWindow* _Nullable window); +RCT_EXTERN UIViewController *__nullable RCTPresentedViewController(void); // Does this device support force touch (aka 3D Touch)? RCT_EXTERN BOOL RCTForceTouchAvailable(void); diff --git a/React/Base/RCTUtils.m b/React/Base/RCTUtils.m index 31464419a11..c5fd2d8e1ce 100644 --- a/React/Base/RCTUtils.m +++ b/React/Base/RCTUtils.m @@ -505,14 +505,13 @@ UIWindow *__nullable RCTKeyWindow(void) return nil; } -UIViewController *__nullable RCTPresentedViewController(UIWindow* _Nullable window) +UIViewController *__nullable RCTPresentedViewController(void) { if ([RCTUtilsUIOverride hasPresentedViewController]) { return [RCTUtilsUIOverride presentedViewController]; } - UIWindow *keyWindow = window ?: RCTKeyWindow(); - UIViewController *controller = keyWindow.rootViewController; + UIViewController *controller = RCTKeyWindow().rootViewController; UIViewController *presentedController = controller.presentedViewController; while (presentedController && ![presentedController isBeingDismissed]) { controller = presentedController; diff --git a/React/CoreModules/RCTActionSheetManager.mm b/React/CoreModules/RCTActionSheetManager.mm index c17e6a70b51..9ca746a40b6 100644 --- a/React/CoreModules/RCTActionSheetManager.mm +++ b/React/CoreModules/RCTActionSheetManager.mm @@ -80,10 +80,7 @@ RCT_EXPORT_METHOD(showActionSheetWithOptions:(JS::NativeActionSheetManager::Spec destructiveButtonIndices = @[destructiveButtonIndex]; } - NSNumber *reactTag = [RCTConvert NSNumber:options.reactTag() ? @(*options.reactTag()) : @-1]; - UIView *view = [self.bridge.uiManager viewForReactTag:reactTag]; - UIViewController *controller = RCTPresentedViewController(view.window); - + UIViewController *controller = RCTPresentedViewController(); NSNumber *anchor = [RCTConvert NSNumber:options.anchor() ? @(*options.anchor()) : nil]; UIColor *tintColor = [RCTConvert UIColor:options.tintColor() ? @(*options.tintColor()) : nil]; @@ -197,10 +194,7 @@ RCT_EXPORT_METHOD(showShareActionSheetWithOptions:(JS::NativeActionSheetManager: shareController.excludedActivityTypes = excludedActivityTypes; } - NSNumber *reactTag = [RCTConvert NSNumber:options.reactTag() ? @(*options.reactTag()) : @-1]; - UIView *view = [self.bridge.uiManager viewForReactTag:reactTag]; - UIViewController *controller = RCTPresentedViewController(view.window); - + UIViewController *controller = RCTPresentedViewController(); shareController.completionWithItemsHandler = ^(NSString *activityType, BOOL completed, __unused NSArray *returnedItems, NSError *activityError) { if (activityError) { failureCallback(@[RCTJSErrorFromNSError(activityError)]); diff --git a/React/CoreModules/RCTAlertManager.mm b/React/CoreModules/RCTAlertManager.mm index d293cf115f6..91c236a6da1 100644 --- a/React/CoreModules/RCTAlertManager.mm +++ b/React/CoreModules/RCTAlertManager.mm @@ -12,7 +12,6 @@ #import #import #import -#import #import #import "CoreModulesPlugins.h" @@ -37,8 +36,6 @@ RCT_ENUM_CONVERTER(RCTAlertViewStyle, (@{ NSHashTable *_alertControllers; } -@synthesize bridge = _bridge; - RCT_EXPORT_MODULE() - (dispatch_queue_t)methodQueue @@ -78,7 +75,6 @@ RCT_EXPORT_METHOD(alertWithArgs:(JS::NativeAlertManager::Args &)args NSString *cancelButtonKey = [RCTConvert NSString:args.cancelButtonKey()]; NSString *destructiveButtonKey = [RCTConvert NSString:args.destructiveButtonKey()]; UIKeyboardType keyboardType = [RCTConvert UIKeyboardType:args.keyboardType()]; - NSNumber *reactTag = [RCTConvert NSNumber:args.reactTag() ? @(*args.reactTag()) : @-1]; if (!title && !message) { RCTLogError(@"Must specify either an alert title, or message, or both"); @@ -98,6 +94,21 @@ RCT_EXPORT_METHOD(alertWithArgs:(JS::NativeAlertManager::Args &)args } } + UIViewController *presentingController = RCTPresentedViewController(); + if (presentingController == nil) { + RCTLogError(@"Tried to display alert view but there is no application window. args: %@", @{ + @"title": args.title() ?: [NSNull null], + @"message": args.message() ?: [NSNull null], + @"buttons": RCTConvertOptionalVecToArray(args.buttons(), ^id(id element) { return element; }) ?: [NSNull null], + @"type": args.type() ?: [NSNull null], + @"defaultValue": args.defaultValue() ?: [NSNull null], + @"cancelButtonKey": args.cancelButtonKey() ?: [NSNull null], + @"destructiveButtonKey": args.destructiveButtonKey() ?: [NSNull null], + @"keyboardType": args.keyboardType() ?: [NSNull null], + }); + return; + } + UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:nil @@ -180,23 +191,6 @@ RCT_EXPORT_METHOD(alertWithArgs:(JS::NativeAlertManager::Args &)args [_alertControllers addObject:alertController]; dispatch_async(dispatch_get_main_queue(), ^{ - UIView *view = [self.bridge.uiManager viewForReactTag:reactTag]; - UIViewController *presentingController = RCTPresentedViewController(view.window); - - if (presentingController == nil) { - RCTLogError(@"Tried to display alert view but there is no application window. args: %@", @{ - @"title": args.title() ?: [NSNull null], - @"message": args.message() ?: [NSNull null], - @"buttons": RCTConvertOptionalVecToArray(args.buttons(), ^id(id element) { return element; }) ?: [NSNull null], - @"type": args.type() ?: [NSNull null], - @"defaultValue": args.defaultValue() ?: [NSNull null], - @"cancelButtonKey": args.cancelButtonKey() ?: [NSNull null], - @"destructiveButtonKey": args.destructiveButtonKey() ?: [NSNull null], - @"keyboardType": args.keyboardType() ?: [NSNull null], - }); - return; - } - [presentingController presentViewController:alertController animated:YES completion:nil]; }); } diff --git a/React/CoreModules/RCTDevMenu.mm b/React/CoreModules/RCTDevMenu.mm index 2d275cb6ca9..69ff839faa7 100644 --- a/React/CoreModules/RCTDevMenu.mm +++ b/React/CoreModules/RCTDevMenu.mm @@ -241,7 +241,7 @@ RCT_EXPORT_MODULE() dismissViewControllerAnimated:YES completion:nil]; }]]; - [RCTPresentedViewController(nil) presentViewController:alertController + [RCTPresentedViewController() presentViewController:alertController animated:YES completion:NULL]; }]]; @@ -266,7 +266,7 @@ RCT_EXPORT_MODULE() [RCTInspectorDevServerHelper attachDebugger:@"ReactNative" withBundleURL:bridge.bundleURL - withView:RCTPresentedViewController(nil)]; + withView:RCTPresentedViewController()]; #endif }]]; } @@ -313,7 +313,7 @@ RCT_EXPORT_MODULE() dismissViewControllerAnimated:YES completion:nil]; }]]; - [RCTPresentedViewController(nil) presentViewController:alertController + [RCTPresentedViewController() presentViewController:alertController animated:YES completion:NULL]; } else { @@ -388,7 +388,7 @@ RCT_EXPORT_MODULE() handler:^(__unused UIAlertAction *action) { return; }]]; - [RCTPresentedViewController(nil) presentViewController:alertController animated:YES completion:NULL]; + [RCTPresentedViewController() presentViewController:alertController animated:YES completion:NULL]; }]]; [items addObjectsFromArray:_extraMenuItems]; @@ -425,7 +425,7 @@ RCT_EXPORT_METHOD(show) handler:[self alertActionHandlerForDevItem:nil]]]; _presentedItems = items; - [RCTPresentedViewController(nil) presentViewController:_actionSheet animated:YES completion:nil]; + [RCTPresentedViewController() presentViewController:_actionSheet animated:YES completion:nil]; [_bridge enqueueJSCall:@"RCTNativeAppEventEmitter" method:@"emit" diff --git a/React/CoreModules/RCTPerfMonitor.mm b/React/CoreModules/RCTPerfMonitor.mm index a3504ec9f22..62e8d711ace 100644 --- a/React/CoreModules/RCTPerfMonitor.mm +++ b/React/CoreModules/RCTPerfMonitor.mm @@ -329,7 +329,9 @@ RCT_EXPORT_MODULE() [self updateStats]; - [RCTKeyWindow() addSubview:self.container]; + UIWindow *window = RCTSharedApplication().delegate.window; + [window addSubview:self.container]; + _uiDisplayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(threadUpdate:)]; diff --git a/React/CoreModules/RCTStatusBarManager.mm b/React/CoreModules/RCTStatusBarManager.mm index b93805a426f..2f74040625c 100644 --- a/React/CoreModules/RCTStatusBarManager.mm +++ b/React/CoreModules/RCTStatusBarManager.mm @@ -8,10 +8,8 @@ #import "RCTStatusBarManager.h" #import "CoreModulesPlugins.h" -#import #import #import -#import #import #if !TARGET_OS_TV @@ -151,50 +149,37 @@ RCT_EXPORT_METHOD(getHeight : (RCTResponseSenderBlock)callback) } ]); } -RCT_EXPORT_METHOD(setStyle:(NSString *)style - animated:(BOOL)animated - reactTag:(double)reactTag) +RCT_EXPORT_METHOD(setStyle : (NSString *)style animated : (BOOL)animated) { UIStatusBarStyle statusBarStyle = [RCTConvert UIStatusBarStyle:style]; if (RCTViewControllerBasedStatusBarAppearance()) { RCTLogError(@"RCTStatusBarManager module requires that the \ UIViewControllerBasedStatusBarAppearance key in the Info.plist is set to NO"); - return; - } - - // TODO (T62270453): Add proper support for UIScenes (this requires view controller based status bar management) + } else { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - [RCTSharedApplication() setStatusBarStyle:statusBarStyle - animated:animated]; + [RCTSharedApplication() setStatusBarStyle:statusBarStyle animated:animated]; + } #pragma clang diagnostic pop } -RCT_EXPORT_METHOD(setHidden:(BOOL)hidden - withAnimation:(NSString *)withAnimation - reactTag:(double)reactTag) +RCT_EXPORT_METHOD(setHidden : (BOOL)hidden withAnimation : (NSString *)withAnimation) { UIStatusBarAnimation animation = [RCTConvert UIStatusBarAnimation:withAnimation]; if (RCTViewControllerBasedStatusBarAppearance()) { RCTLogError(@"RCTStatusBarManager module requires that the \ UIViewControllerBasedStatusBarAppearance key in the Info.plist is set to NO"); - return; - } - - // TODO (T62270453): Add proper support for UIScenes (this requires view controller based status bar management) + } else { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - [RCTSharedApplication() setStatusBarHidden:hidden - withAnimation:animation]; + [RCTSharedApplication() setStatusBarHidden:hidden withAnimation:animation]; #pragma clang diagnostic pop + } } RCT_EXPORT_METHOD(setNetworkActivityIndicatorVisible : (BOOL)visible) { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" RCTSharedApplication().networkActivityIndicatorVisible = visible; -#pragma clang diagnostic pop } - (facebook::react::ModuleConstants)getConstants diff --git a/React/Profiler/RCTProfile.m b/React/Profiler/RCTProfile.m index a43c77099e6..d201f86a184 100644 --- a/React/Profiler/RCTProfile.m +++ b/React/Profiler/RCTProfile.m @@ -401,9 +401,9 @@ void RCTProfileUnhookModules(RCTBridge *bridge) }; RCTProfileControlsWindow.hidden = YES; dispatch_async(dispatch_get_main_queue(), ^{ - [RCTPresentedViewController(nil) presentViewController:activityViewController - animated:YES - completion:nil]; + [[[[RCTSharedApplication() delegate] window] rootViewController] presentViewController:activityViewController + animated:YES + completion:nil]; }); #endif }); @@ -777,7 +777,7 @@ void RCTProfileSendResult(RCTBridge *bridge, NSString *route, NSData *data) [alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:nil]]; - [RCTPresentedViewController(nil) presentViewController:alertController animated:YES completion:nil]; + [RCTPresentedViewController() presentViewController:alertController animated:YES completion:nil]; }); #endif } diff --git a/ReactAndroid/src/main/java/com/facebook/fbreact/specs/NativeStatusBarManagerIOSSpec.java b/ReactAndroid/src/main/java/com/facebook/fbreact/specs/NativeStatusBarManagerIOSSpec.java index 1dcb9e2d087..908930e76d6 100644 --- a/ReactAndroid/src/main/java/com/facebook/fbreact/specs/NativeStatusBarManagerIOSSpec.java +++ b/ReactAndroid/src/main/java/com/facebook/fbreact/specs/NativeStatusBarManagerIOSSpec.java @@ -40,10 +40,10 @@ public abstract class NativeStatusBarManagerIOSSpec extends ReactContextBaseJava public abstract void removeListeners(double count); @ReactMethod - public abstract void setHidden(boolean hidden, String withAnimation, double reactTag); + public abstract void setHidden(boolean hidden, String withAnimation); @ReactMethod - public abstract void setStyle(@Nullable String statusBarStyle, boolean animated, double reactTag); + public abstract void setStyle(@Nullable String statusBarStyle, boolean animated); @ReactMethod public abstract void addListener(String eventType); diff --git a/ReactAndroid/src/main/java/com/facebook/fbreact/specs/jni/FBReactNativeSpec-generated.cpp b/ReactAndroid/src/main/java/com/facebook/fbreact/specs/jni/FBReactNativeSpec-generated.cpp index d7ddd8d19d4..d3e521352b9 100644 --- a/ReactAndroid/src/main/java/com/facebook/fbreact/specs/jni/FBReactNativeSpec-generated.cpp +++ b/ReactAndroid/src/main/java/com/facebook/fbreact/specs/jni/FBReactNativeSpec-generated.cpp @@ -2029,11 +2029,11 @@ namespace facebook { } static facebook::jsi::Value __hostFunction_NativeStatusBarManagerIOSSpecJSI_setStyle(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { - return static_cast(turboModule).invokeJavaMethod(rt, VoidKind, "setStyle", "(Ljava/lang/String;ZD)V", args, count); + return static_cast(turboModule).invokeJavaMethod(rt, VoidKind, "setStyle", "(Ljava/lang/String;Z)V", args, count); } static facebook::jsi::Value __hostFunction_NativeStatusBarManagerIOSSpecJSI_setHidden(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { - return static_cast(turboModule).invokeJavaMethod(rt, VoidKind, "setHidden", "(ZLjava/lang/String;D)V", args, count); + return static_cast(turboModule).invokeJavaMethod(rt, VoidKind, "setHidden", "(ZLjava/lang/String;)V", args, count); } static facebook::jsi::Value __hostFunction_NativeStatusBarManagerIOSSpecJSI_getConstants(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { @@ -2056,10 +2056,10 @@ namespace facebook { methodMap_["removeListeners"] = MethodMetadata {1, __hostFunction_NativeStatusBarManagerIOSSpecJSI_removeListeners}; - methodMap_["setStyle"] = MethodMetadata {3, __hostFunction_NativeStatusBarManagerIOSSpecJSI_setStyle}; + methodMap_["setStyle"] = MethodMetadata {2, __hostFunction_NativeStatusBarManagerIOSSpecJSI_setStyle}; - methodMap_["setHidden"] = MethodMetadata {3, __hostFunction_NativeStatusBarManagerIOSSpecJSI_setHidden}; + methodMap_["setHidden"] = MethodMetadata {2, __hostFunction_NativeStatusBarManagerIOSSpecJSI_setHidden}; methodMap_["getConstants"] = MethodMetadata {0, __hostFunction_NativeStatusBarManagerIOSSpecJSI_getConstants};