Skip to content
Source
Sign inSign up
Open History to see the last commit

expo-modules-core@58.0.30.patch

42 lines1.6 KB

1diff --git a/android/src/main/java/expo/modules/kotlin/views/ExpoView.kt b/android/src/main/java/expo/modules/kotlin/views/ExpoView.kt
2index c732ab4..2e3f40e 100644
3--- a/android/src/main/java/expo/modules/kotlin/views/ExpoView.kt
4+++ b/android/src/main/java/expo/modules/kotlin/views/ExpoView.kt
5@@ -3,6 +3,7 @@ package expo.modules.kotlin.views
6 import android.content.Context
7 import android.graphics.Canvas
8 import android.widget.LinearLayout
9+import androidx.core.view.OneShotPreDrawListener
10 import androidx.annotation.UiThread
11 import com.facebook.react.uimanager.BackgroundStyleApplicator
12 import com.facebook.react.uimanager.StateWrapper
13@@ -47,12 +48,27 @@ abstract class ExpoView(
14 layout(left, top, right, bottom)
15 }
17+ private var isLayoutScheduled = false
19 override fun requestLayout() {
20 super.requestLayout()
21- if (shouldUseAndroidLayout) {
22+ if (shouldUseAndroidLayout && !isLayoutScheduled) {
23 // We need to force measure and layout, because React Native doesn't do it for us.
24- post { measureAndLayout() }
25+ // A posted layout runs after the frame being prepared is drawn, so a view that changes in a
26+ // mount would show unlaid-out content for a frame. The pre-draw listener lays it out before
27+ // that frame instead; the post covers a request that no frame follows.
28+ isLayoutScheduled = true
29+ OneShotPreDrawListener.add(this) { runScheduledLayout() }
30+ post { runScheduledLayout() }
31+ }
32+ }
34+ private fun runScheduledLayout() {
35+ if (!isLayoutScheduled) {
36+ return
37 }
38+ isLayoutScheduled = false
39+ measureAndLayout()
40 }
42 override fun forceLayout() {