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

Addressing various issues with the Appearance API (#28823) #29106

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 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
4 changes: 3 additions & 1 deletion React/CoreModules/RCTAppearance.mm
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ - (dispatch_queue_t)methodQueue

RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSString *, getColorScheme)
{
_currentColorScheme = RCTColorSchemePreference(nil);
if (_currentColorScheme == nil) {
_currentColorScheme = RCTColorSchemePreference(nil);
}
Comment on lines +92 to +94
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this change probably makes sense, it doesn't solve the issues with overrideUserInterfaceStyle in a brownfield app for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @koenpunt, if you have time to throw up a repo with a brownfield project that's broken (or hit me with some repro steps) I could probably take a look at brownfield a bit deeper sometime this week 👍 .

return _currentColorScheme;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.facebook.react;

import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.KeyEvent;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -120,6 +121,12 @@ public void onWindowFocusChanged(boolean hasFocus) {
mDelegate.onWindowFocusChanged(hasFocus);
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDelegate.onConfigurationChanged(newConfig);
}

protected final ReactNativeHost getReactNativeHost() {
return mDelegate.getReactNativeHost();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.res.Configuration;
mrbrentkelly marked this conversation as resolved.
Show resolved Hide resolved
mrbrentkelly marked this conversation as resolved.
Show resolved Hide resolved
mrbrentkelly marked this conversation as resolved.
Show resolved Hide resolved
import android.content.Context;
import android.content.Intent;
import android.os.Build;
Expand Down Expand Up @@ -154,6 +155,12 @@ public void onWindowFocusChanged(boolean hasFocus) {
}
}

public void onConfigurationChanged(Configuration newConfig) {
if (getReactNativeHost().hasInstance()) {
getReactInstanceManager().onConfigurationChanged(getContext(), newConfig);
}
}

@TargetApi(Build.VERSION_CODES.M)
public void requestPermissions(
String[] permissions, int requestCode, PermissionListener listener) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package com.facebook.react.modules.appearance;

import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -74,7 +75,11 @@ public String getName() {

@Override
public String getColorScheme() {
mColorScheme = colorSchemeForCurrentConfiguration(getReactApplicationContext());
// Attempt to use the Activity context first in order to get the most up to date
mrbrentkelly marked this conversation as resolved.
Show resolved Hide resolved
mrbrentkelly marked this conversation as resolved.
Show resolved Hide resolved
// scheme. This covers the scenario when AppCompatDelegate.setDefaultNightMode()
// is called directly (which can occur in Brownfield apps for example).
Activity activity = getCurrentActivity();
mrbrentkelly marked this conversation as resolved.
Show resolved Hide resolved
mrbrentkelly marked this conversation as resolved.
Show resolved Hide resolved
mColorScheme = colorSchemeForCurrentConfiguration(activity != null ? activity : getReactApplicationContext());
return mColorScheme;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

package com.facebook.react.uiapp;

import android.content.res.Configuration;
import static com.facebook.react.uiapp.RNTesterApplication.IS_FABRIC_ENABLED;
import android.os.Bundle;
import androidx.annotation.Nullable;
import com.facebook.react.ReactActivity;
Expand Down Expand Up @@ -64,14 +64,4 @@ protected ReactActivityDelegate createReactActivityDelegate() {
protected String getMainComponentName() {
return "RNTesterApp";
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
ReactInstanceManager instanceManager = getReactInstanceManager();

if (instanceManager != null) {
instanceManager.onConfigurationChanged(this, newConfig);
}
}
}