Skip to content

Commit

Permalink
Back out "Add Appearance.setColorScheme support"
Browse files Browse the repository at this point in the history
Summary:
See #35989 (comment)

Changelog:
[General][Fixed] - Back out "Add Appearance.setColorScheme support"

Reviewed By: jacdebug

Differential Revision: D43148056

fbshipit-source-id: 823ab8276207f243b788ce7757839a3e95bdbe07
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Feb 9, 2023
1 parent 7c82a3f commit 6d1667c
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 63 deletions.
10 changes: 0 additions & 10 deletions Libraries/Utilities/Appearance.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
11 changes: 0 additions & 11 deletions Libraries/Utilities/Appearance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
1 change: 0 additions & 1 deletion Libraries/Utilities/NativeAppearance.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export interface Spec extends TurboModule {
// types.
/* 'light' | 'dark' */
+getColorScheme: () => ?string;
+setColorScheme?: (colorScheme: string) => void;

// RCTEventEmitter
+addListener: (eventName: string) => void;
Expand Down
1 change: 0 additions & 1 deletion React/CoreModules/RCTAppearance.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#import <UIKit/UIKit.h>

#import <React/RCTBridgeModule.h>
#import <React/RCTConvert.h>
#import <React/RCTEventEmitter.h>

RCT_EXTERN void RCTEnableAppearancePreference(BOOL enabled);
Expand Down
26 changes: 0 additions & 26 deletions React/CoreModules/RCTAppearance.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#import <FBReactNativeSpec/FBReactNativeSpec.h>
#import <React/RCTConstants.h>
#import <React/RCTEventEmitter.h>
#import <React/RCTUtils.h>

#import "CoreModulesPlugins.h"

Expand Down Expand Up @@ -69,20 +68,6 @@ void RCTOverrideAppearancePreference(NSString *const colorSchemeOverride)
return RCTAppearanceColorSchemeLight;
}

@implementation RCTConvert (UIUserInterfaceStyle)

RCT_ENUM_CONVERTER(
UIUserInterfaceStyle,
(@{
@"light" : @(UIUserInterfaceStyleLight),
@"dark" : @(UIUserInterfaceStyleDark),
@"unspecified" : @(UIUserInterfaceStyleUnspecified)
}),
UIUserInterfaceStyleUnspecified,
integerValue);

@end

@interface RCTAppearance () <NativeAppearanceSpec>
@end

Expand All @@ -107,17 +92,6 @@ - (dispatch_queue_t)methodQueue
return std::make_shared<NativeAppearanceSpecJSI>(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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
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;
Expand Down Expand Up @@ -67,17 +66,6 @@ private String colorSchemeForCurrentConfiguration(Context context) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
1 change: 0 additions & 1 deletion ReactAndroid/src/main/java/com/facebook/react/shell/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit 6d1667c

Please sign in to comment.