From 6d1667cf8661d64ebeba5ceecbdffd587d9008da Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Thu, 9 Feb 2023 00:54:42 -0800 Subject: [PATCH] Back out "Add Appearance.setColorScheme support" Summary: See https://github.com/facebook/react-native/pull/35989#discussion_r1101016329 Changelog: [General][Fixed] - Back out "Add Appearance.setColorScheme support" Reviewed By: jacdebug Differential Revision: D43148056 fbshipit-source-id: 823ab8276207f243b788ce7757839a3e95bdbe07 --- Libraries/Utilities/Appearance.d.ts | 10 ------- Libraries/Utilities/Appearance.js | 11 -------- Libraries/Utilities/NativeAppearance.js | 1 - React/CoreModules/RCTAppearance.h | 1 - React/CoreModules/RCTAppearance.mm | 26 ------------------- .../modules/appearance/AppearanceModule.java | 12 --------- .../facebook/react/modules/appearance/BUCK | 1 - .../main/java/com/facebook/react/shell/BUCK | 1 - 8 files changed, 63 deletions(-) diff --git a/Libraries/Utilities/Appearance.d.ts b/Libraries/Utilities/Appearance.d.ts index 2b8428e0d7d..7d2faf69d8c 100644 --- a/Libraries/Utilities/Appearance.d.ts +++ b/Libraries/Utilities/Appearance.d.ts @@ -28,16 +28,6 @@ export namespace Appearance { */ export function getColorScheme(): ColorSchemeName; - /** - * Set the color scheme preference. This is useful for overriding the default - * color scheme preference for the app. Note that this will not change the - * appearance of the system UI, only the appearance of the app. - * Only available on iOS 13+ and Android 10+. - */ - export function setColorScheme( - scheme: ColorSchemeName | null | undefined, - ): void; - /** * Add an event handler that is fired when appearance preferences change. */ diff --git a/Libraries/Utilities/Appearance.js b/Libraries/Utilities/Appearance.js index 69817442085..54d03dd1820 100644 --- a/Libraries/Utilities/Appearance.js +++ b/Libraries/Utilities/Appearance.js @@ -85,17 +85,6 @@ module.exports = { return nativeColorScheme; }, - setColorScheme(colorScheme: ?ColorSchemeName): void { - const nativeColorScheme = colorScheme == null ? 'unspecified' : colorScheme; - - invariant( - colorScheme === 'dark' || colorScheme === 'light' || colorScheme == null, - "Unrecognized color scheme. Did you mean 'dark', 'light' or null?", - ); - - NativeAppearance?.setColorScheme?.(nativeColorScheme); - }, - /** * Add an event handler that is fired when appearance preferences change. */ diff --git a/Libraries/Utilities/NativeAppearance.js b/Libraries/Utilities/NativeAppearance.js index 786790f5987..cb8688f14e2 100644 --- a/Libraries/Utilities/NativeAppearance.js +++ b/Libraries/Utilities/NativeAppearance.js @@ -26,7 +26,6 @@ export interface Spec extends TurboModule { // types. /* 'light' | 'dark' */ +getColorScheme: () => ?string; - +setColorScheme?: (colorScheme: string) => void; // RCTEventEmitter +addListener: (eventName: string) => void; diff --git a/React/CoreModules/RCTAppearance.h b/React/CoreModules/RCTAppearance.h index caa842d72f6..d8bb18b89ac 100644 --- a/React/CoreModules/RCTAppearance.h +++ b/React/CoreModules/RCTAppearance.h @@ -8,7 +8,6 @@ #import #import -#import #import RCT_EXTERN void RCTEnableAppearancePreference(BOOL enabled); diff --git a/React/CoreModules/RCTAppearance.mm b/React/CoreModules/RCTAppearance.mm index 72257c8fa1b..71259d4a98d 100644 --- a/React/CoreModules/RCTAppearance.mm +++ b/React/CoreModules/RCTAppearance.mm @@ -10,7 +10,6 @@ #import #import #import -#import #import "CoreModulesPlugins.h" @@ -69,20 +68,6 @@ NSString *RCTColorSchemePreference(UITraitCollection *traitCollection) return RCTAppearanceColorSchemeLight; } -@implementation RCTConvert (UIUserInterfaceStyle) - -RCT_ENUM_CONVERTER( - UIUserInterfaceStyle, - (@{ - @"light" : @(UIUserInterfaceStyleLight), - @"dark" : @(UIUserInterfaceStyleDark), - @"unspecified" : @(UIUserInterfaceStyleUnspecified) - }), - UIUserInterfaceStyleUnspecified, - integerValue); - -@end - @interface RCTAppearance () @end @@ -107,17 +92,6 @@ RCT_EXPORT_MODULE(Appearance) return std::make_shared(params); } -RCT_EXPORT_METHOD(setColorScheme : (NSString *)style) -{ - UIUserInterfaceStyle userInterfaceStyle = [RCTConvert UIUserInterfaceStyle:style]; - NSArray<__kindof UIWindow *> *windows = RCTSharedApplication().windows; - if (@available(iOS 13.0, *)) { - for (UIWindow *window in windows) { - window.overrideUserInterfaceStyle = userInterfaceStyle; - } - } -} - RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSString *, getColorScheme) { if (_currentColorScheme == nil) { diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/appearance/AppearanceModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/appearance/AppearanceModule.java index 301a8deff1b..e64bbe122c6 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/appearance/AppearanceModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/appearance/AppearanceModule.java @@ -11,7 +11,6 @@ import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatDelegate; import com.facebook.fbreact.specs.NativeAppearanceSpec; import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.ReactApplicationContext; @@ -67,17 +66,6 @@ public class AppearanceModule extends NativeAppearanceSpec { return "light"; } - @Override - public void setColorScheme(String style) { - if (style == "dark") { - AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); - } else if (style == "light") { - AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); - } else if (style == "unspecified") { - AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM); - } - } - @Override public String getColorScheme() { // Attempt to use the Activity context first in order to get the most up to date diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/appearance/BUCK b/ReactAndroid/src/main/java/com/facebook/react/modules/appearance/BUCK index 044b4c8d094..4cb4e081946 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/appearance/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/appearance/BUCK @@ -14,7 +14,6 @@ rn_android_library( deps = [ react_native_dep("third-party/java/jsr-305:jsr-305"), react_native_dep("third-party/android/androidx:annotation"), - react_native_dep("third-party/android/androidx:appcompat"), react_native_target("java/com/facebook/react/bridge:bridge"), react_native_target("java/com/facebook/react/common:common"), react_native_target("java/com/facebook/react/module/annotations:annotations"), diff --git a/ReactAndroid/src/main/java/com/facebook/react/shell/BUCK b/ReactAndroid/src/main/java/com/facebook/react/shell/BUCK index 5621dd31762..b64122b9d39 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/shell/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/shell/BUCK @@ -15,7 +15,6 @@ rn_android_library( react_native_dep("libraries/fresco/fresco-react-native:imagepipeline"), react_native_dep("libraries/soloader/java/com/facebook/soloader:soloader"), react_native_dep("third-party/android/androidx:annotation"), - react_native_dep("third-party/android/androidx:appcompat"), react_native_dep("third-party/android/androidx:core"), react_native_dep("third-party/android/androidx:fragment"), react_native_dep("third-party/android/androidx:legacy-support-core-utils"),