Skip to content

Commit e02e7b1

Browse files
j-piaseckifacebook-github-bot
authored andcommitted
Request layout on configuration change only when the font scale has changed (#53984)
Summary: Pull Request resolved: #53984 Changelog: [ANDROID][CHANGED] - Request layout on configuration change only when the font scale has changed Wraps call to `requestLayout` in a condition to only run layout when the font scale has changed to prevent it from executing in response to other configuration changes. Reviewed By: Abbondanzo Differential Revision: D83546632 fbshipit-source-id: 41a5199dd2ef72b8f6257637c1d35d4a790ea006
1 parent af904e5 commit e02e7b1

File tree

1 file changed

+7
-2
lines changed
  • packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime

1 file changed

+7
-2
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import com.facebook.react.runtime.internal.bolts.Task
6161
import com.facebook.react.runtime.internal.bolts.TaskCompletionSource
6262
import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder
6363
import com.facebook.react.uimanager.DisplayMetricsHolder
64+
import com.facebook.react.uimanager.PixelUtil
6465
import com.facebook.react.uimanager.events.BlackHoleEventDispatcher
6566
import com.facebook.react.uimanager.events.EventDispatcher
6667
import com.facebook.react.views.imagehelper.ResourceDrawableIdHelper
@@ -647,10 +648,14 @@ public class ReactHostImpl(
647648
val currentReactContext = this.currentReactContext
648649
if (currentReactContext != null) {
649650
if (ReactNativeFeatureFlags.enableFontScaleChangesUpdatingLayout()) {
651+
val previousFontScale = PixelUtil.toPixelFromSP(1.0)
650652
DisplayMetricsHolder.initDisplayMetrics(currentReactContext)
653+
val newFontScale = PixelUtil.toPixelFromSP(1.0)
651654

652-
synchronized(attachedSurfaces) {
653-
attachedSurfaces.forEach { surface -> surface.view?.requestLayout() }
655+
if (previousFontScale != newFontScale) {
656+
synchronized(attachedSurfaces) {
657+
attachedSurfaces.forEach { surface -> surface.view?.requestLayout() }
658+
}
654659
}
655660
}
656661

0 commit comments

Comments
 (0)