Skip to content

Commit 2c3ab3b

Browse files
committed
fix: remove UIImplementation usage from SafeAreaView
UIImplementation has been deleted from react-native core. The dispatchViewUpdates call was already a no-op (fully stubbed), so removing it along with the waitForReactLayout helper that only existed to synchronize with that dispatch.
1 parent 93b7a32 commit 2c3ab3b

1 file changed

Lines changed: 0 additions & 50 deletions

File tree

android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaView.kt

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
package com.th3rdwave.safeareacontext
22

33
import android.content.Context
4-
import android.util.Log
54
import android.view.View
65
import android.view.ViewTreeObserver
76
import com.facebook.react.bridge.Arguments
87
import com.facebook.react.uimanager.StateWrapper
98
import com.facebook.react.uimanager.UIManagerModule
109
import com.facebook.react.views.view.ReactViewGroup
11-
import java.util.concurrent.locks.ReentrantLock
12-
import kotlin.concurrent.withLock
13-
14-
private const val MAX_WAIT_TIME_NANO = 500000000L // 500ms
1510

1611
class SafeAreaView(context: Context?) :
1712
ReactViewGroup(context), ViewTreeObserver.OnPreDrawListener {
@@ -50,54 +45,9 @@ class SafeAreaView(context: Context?) :
5045
val uiManager = reactContext.getNativeModule(UIManagerModule::class.java)
5146
if (uiManager != null) {
5247
uiManager.setViewLocalData(id, localData)
53-
// Sadly there doesn't seem to be a way to properly dirty a yoga node from java, so if we
54-
// are in
55-
// the middle of a layout, we need to recompute it. There is also no way to know whether
56-
// we
57-
// are in the middle of a layout so always do it.
58-
reactContext.runOnNativeModulesQueueThread {
59-
uiManager.uiImplementation.dispatchViewUpdates(-1)
60-
}
61-
waitForReactLayout()
62-
}
63-
}
64-
}
65-
}
66-
67-
private fun waitForReactLayout() {
68-
// Block the main thread until the native module thread is finished with
69-
// its current tasks. To do this we use the done boolean as a lock and enqueue
70-
// a task on the native modules thread. When the task runs we can unblock the
71-
// main thread. This should be safe as long as the native modules thread
72-
// does not block waiting on the main thread.
73-
var done = false
74-
val lock = ReentrantLock()
75-
val condition = lock.newCondition()
76-
val startTime = System.nanoTime()
77-
var waitTime = 0L
78-
getReactContext(this).runOnNativeModulesQueueThread {
79-
lock.withLock {
80-
if (!done) {
81-
done = true
82-
condition.signal()
8348
}
8449
}
8550
}
86-
lock.withLock {
87-
while (!done && waitTime < MAX_WAIT_TIME_NANO) {
88-
try {
89-
condition.awaitNanos(MAX_WAIT_TIME_NANO)
90-
} catch (ex: InterruptedException) {
91-
// In case of an interrupt just give up waiting.
92-
done = true
93-
}
94-
waitTime += System.nanoTime() - startTime
95-
}
96-
}
97-
// Timed out waiting.
98-
if (waitTime >= MAX_WAIT_TIME_NANO) {
99-
Log.w("SafeAreaView", "Timed out waiting for layout.")
100-
}
10151
}
10252

10353
fun setMode(mode: SafeAreaViewMode) {

0 commit comments

Comments
 (0)