Skip to content

Commit

Permalink
Support onConfigurationChanged in Bridgeless (#43463)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #43463

Implement `onConfigurationChanged` in Bridgeless by adding it to ReactHostImpl

Changelog:
[Android][Breaking] Implement onConfigurationChanged in Bridgeless

Reviewed By: cortinico, RSNara

Differential Revision: D54792399

fbshipit-source-id: 6851daca815f486f4d839e128a1d740d3fec1996
  • Loading branch information
arushikesarwani94 authored and facebook-github-bot committed Mar 13, 2024
1 parent 5807ada commit b2e1db0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
3 changes: 3 additions & 0 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public class com/facebook/react/ReactDelegate {
public fun loadApp (Ljava/lang/String;)V
public fun onActivityResult (IILandroid/content/Intent;Z)V
public fun onBackPressed ()Z
public fun onConfigurationChanged (Landroid/content/res/Configuration;)V
public fun onHostDestroy ()V
public fun onHostPause ()V
public fun onHostResume ()V
Expand Down Expand Up @@ -199,6 +200,7 @@ public abstract interface class com/facebook/react/ReactHost {
public abstract fun getReactQueueConfiguration ()Lcom/facebook/react/bridge/queue/ReactQueueConfiguration;
public abstract fun onActivityResult (Landroid/app/Activity;IILandroid/content/Intent;)V
public abstract fun onBackPressed ()Z
public abstract fun onConfigurationChanged (Landroid/content/Context;)V
public abstract fun onHostDestroy ()V
public abstract fun onHostDestroy (Landroid/app/Activity;)V
public abstract fun onHostPause ()V
Expand Down Expand Up @@ -3639,6 +3641,7 @@ public class com/facebook/react/runtime/ReactHostImpl : com/facebook/react/React
public fun getReactQueueConfiguration ()Lcom/facebook/react/bridge/queue/ReactQueueConfiguration;
public fun onActivityResult (Landroid/app/Activity;IILandroid/content/Intent;)V
public fun onBackPressed ()Z
public fun onConfigurationChanged (Landroid/content/Context;)V
public fun onHostDestroy ()V
public fun onHostDestroy (Landroid/app/Activity;)V
public fun onHostPause ()V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,7 @@ public void onWindowFocusChanged(boolean hasFocus) {
}

public void onConfigurationChanged(Configuration newConfig) {
if (ReactFeatureFlags.enableBridgelessArchitecture) {
// TODO T156475655: support onConfigurationChanged
} else {
if (getReactNativeHost().hasInstance()) {
getReactInstanceManager().onConfigurationChanged(getContext(), newConfig);
}
}
mReactDelegate.onConfigurationChanged(newConfig);
}

public void requestPermissions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import android.app.Activity;
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 @@ -172,6 +173,17 @@ public void onWindowFocusChanged(boolean hasFocus) {
}
}

public void onConfigurationChanged(Configuration newConfig) {
if (ReactFeatureFlags.enableBridgelessArchitecture) {
mReactHost.onConfigurationChanged(Assertions.assertNotNull(mActivity));
} else {
if (getReactNativeHost().hasInstance()) {
getReactInstanceManager()
.onConfigurationChanged(Assertions.assertNotNull(mActivity), newConfig);
}
}
}

public void loadApp() {
loadApp(mMainComponentName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ public interface ReactHost {
/* This method will give JS the opportunity to receive intents via Linking. */
public fun onNewIntent(intent: Intent)

public fun onConfigurationChanged(context: Context)

public fun addBeforeDestroyListener(onBeforeDestroy: () -> Unit)

public fun removeBeforeDestroyListener(onBeforeDestroy: () -> Unit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import com.facebook.react.interfaces.TaskInterface;
import com.facebook.react.interfaces.exceptionmanager.ReactJsExceptionHandler;
import com.facebook.react.interfaces.fabric.ReactSurface;
import com.facebook.react.modules.appearance.AppearanceModule;
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.facebook.react.runtime.internal.bolts.Continuation;
Expand Down Expand Up @@ -699,6 +700,20 @@ public void onNewIntent(Intent intent) {
new ReactNoCrashSoftException("Tried to access onNewIntent while context is not ready"));
}

@ThreadConfined(UI)
@Override
public void onConfigurationChanged(Context updatedContext) {
ReactContext currentReactContext = getCurrentReactContext();
if (currentReactContext != null) {
AppearanceModule appearanceModule =
currentReactContext.getNativeModule(AppearanceModule.class);

if (appearanceModule != null) {
appearanceModule.onConfigurationChanged(updatedContext);
}
}
}

@Nullable
JavaScriptContextHolder getJavaScriptContextHolder() {
final ReactInstance reactInstance = mReactInstanceTaskRef.get().getResult();
Expand Down

0 comments on commit b2e1db0

Please sign in to comment.