Skip to content

Commit 8fe7607

Browse files
authored
chore(Android, SafeArea): remove legacy architecture related code (#3778)
## Description This PR removes legacy architecture related code from SafeArea related files. Closes software-mansion/react-native-screens-labs#1032 --> ## Changes - remove `SafeAreaViewLocalData.kt` and `SafeAreaViewShadowNode.kt` - remove unnecessary imports and conditions ## Before & after - visual documentation N/A ## Test plan Build the app and check if it runs correctly. ## Checklist - [ ] Included code example that can be used to test this change. - [ ] Updated / created local changelog entries in relevant test files. - [ ] For visual changes, included screenshots / GIFs / recordings documenting the change. - [ ] For API changes, updated relevant public types. - [x] Ensured that CI passes
1 parent 8205d0e commit 8fe7607

5 files changed

Lines changed: 2 additions & 209 deletions

File tree

android/src/main/java/com/swmansion/rnscreens/safearea/SafeAreaView.kt

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package com.swmansion.rnscreens.safearea
44

55
import android.annotation.SuppressLint
66
import android.os.Build
7-
import android.util.Log
87
import android.view.View
98
import android.view.ViewTreeObserver
109
import androidx.core.graphics.Insets
@@ -15,17 +14,8 @@ import com.facebook.react.bridge.Arguments
1514
import com.facebook.react.uimanager.PixelUtil
1615
import com.facebook.react.uimanager.StateWrapper
1716
import com.facebook.react.uimanager.ThemedReactContext
18-
import com.facebook.react.uimanager.UIManagerHelper.getReactContext
19-
import com.facebook.react.uimanager.UIManagerModule
2017
import com.facebook.react.views.view.ReactViewGroup
21-
import com.swmansion.rnscreens.BuildConfig
22-
import com.swmansion.rnscreens.safearea.paper.SafeAreaViewEdges
23-
import com.swmansion.rnscreens.safearea.paper.SafeAreaViewLocalData
2418
import java.lang.ref.WeakReference
25-
import java.util.concurrent.locks.ReentrantLock
26-
import kotlin.concurrent.withLock
27-
28-
private const val MAX_WAIT_TIME_NANO = 500000000L // 500ms
2919

3020
@SuppressLint("ViewConstructor") // Should never be recreated
3121
class SafeAreaView(
@@ -173,7 +163,7 @@ class SafeAreaView(
173163
)
174164

175165
val stateWrapper = getStateWrapper()
176-
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED && stateWrapper != null) {
166+
if (stateWrapper != null) {
177167
val insets = Arguments.createMap()
178168
insets.putDouble("left", PixelUtil.toDIPFromPixel(safeAreaInsets.left).toDouble())
179169
insets.putDouble("top", PixelUtil.toDIPFromPixel(safeAreaInsets.top).toDouble())
@@ -184,60 +174,6 @@ class SafeAreaView(
184174
newState.putMap("insets", insets)
185175

186176
stateWrapper.updateState(newState)
187-
} else if (!BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
188-
val localData =
189-
SafeAreaViewLocalData(
190-
insets = safeAreaInsets,
191-
edges = edges ?: SafeAreaViewEdges.ZERO,
192-
)
193-
val reactContext = getReactContext(this)
194-
val uiManager = reactContext.getNativeModule(UIManagerModule::class.java)
195-
if (uiManager != null) {
196-
uiManager.setViewLocalData(id, localData)
197-
// Sadly there doesn't seem to be a way to properly dirty a yoga node from java, so
198-
// if we are in the middle of a layout, we need to recompute it. There is also no
199-
// way to know whether we are in the middle of a layout so always do it.
200-
reactContext.runOnNativeModulesQueueThread {
201-
uiManager.uiImplementation.dispatchViewUpdates(-1)
202-
}
203-
waitForReactLayout()
204-
}
205-
}
206-
}
207-
208-
private fun waitForReactLayout() {
209-
// Block the main thread until the native module thread is finished with
210-
// its current tasks. To do this we use the done boolean as a lock and enqueue
211-
// a task on the native modules thread. When the task runs we can unblock the
212-
// main thread. This should be safe as long as the native modules thread
213-
// does not block waiting on the main thread.
214-
var done = false
215-
val lock = ReentrantLock()
216-
val condition = lock.newCondition()
217-
val startTime = System.nanoTime()
218-
var waitTime = 0L
219-
getReactContext(this).runOnNativeModulesQueueThread {
220-
lock.withLock {
221-
if (!done) {
222-
done = true
223-
condition.signal()
224-
}
225-
}
226-
}
227-
lock.withLock {
228-
while (!done && waitTime < MAX_WAIT_TIME_NANO) {
229-
try {
230-
condition.awaitNanos(MAX_WAIT_TIME_NANO)
231-
} catch (ex: InterruptedException) {
232-
// In case of an interrupt just give up waiting.
233-
done = true
234-
}
235-
waitTime += System.nanoTime() - startTime
236-
}
237-
}
238-
// Timed out waiting.
239-
if (waitTime >= MAX_WAIT_TIME_NANO) {
240-
Log.w(TAG, "Timed out waiting for layout.")
241177
}
242178
}
243179

android/src/main/java/com/swmansion/rnscreens/safearea/paper/SafeAreaViewEdges.kt renamed to android/src/main/java/com/swmansion/rnscreens/safearea/SafeAreaViewEdges.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Implementation adapted from `react-native-safe-area-context`:
22
// https://github.com/AppAndFlow/react-native-safe-area-context/tree/v5.6.1
3-
package com.swmansion.rnscreens.safearea.paper
3+
package com.swmansion.rnscreens.safearea
44

55
import com.facebook.react.bridge.ReadableMap
66

android/src/main/java/com/swmansion/rnscreens/safearea/SafeAreaViewManager.kt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ import com.facebook.react.uimanager.StateWrapper
1010
import com.facebook.react.uimanager.ThemedReactContext
1111
import com.facebook.react.uimanager.ViewGroupManager
1212
import com.facebook.react.uimanager.ViewManagerDelegate
13-
import com.facebook.react.uimanager.annotations.ReactProp
1413
import com.facebook.react.viewmanagers.RNSSafeAreaViewManagerDelegate
1514
import com.facebook.react.viewmanagers.RNSSafeAreaViewManagerInterface
16-
import com.swmansion.rnscreens.safearea.paper.SafeAreaViewEdges
17-
import com.swmansion.rnscreens.safearea.paper.SafeAreaViewShadowNode
1815

1916
@ReactModule(name = SafeAreaViewManager.REACT_CLASS)
2017
class SafeAreaViewManager :
@@ -28,11 +25,6 @@ class SafeAreaViewManager :
2825

2926
override fun getDelegate() = delegate
3027

31-
override fun createShadowNodeInstance() = SafeAreaViewShadowNode()
32-
33-
override fun getShadowNodeClass() = SafeAreaViewShadowNode::class.java
34-
35-
@ReactProp(name = "edges")
3628
override fun setEdges(
3729
view: SafeAreaView,
3830
value: ReadableMap?,
@@ -42,7 +34,6 @@ class SafeAreaViewManager :
4234
}
4335
}
4436

45-
@ReactProp(name = "insetType")
4637
override fun setInsetType(
4738
view: SafeAreaView,
4839
value: String?,

android/src/main/java/com/swmansion/rnscreens/safearea/paper/SafeAreaViewLocalData.kt

Lines changed: 0 additions & 10 deletions
This file was deleted.

android/src/main/java/com/swmansion/rnscreens/safearea/paper/SafeAreaViewShadowNode.kt

Lines changed: 0 additions & 124 deletions
This file was deleted.

0 commit comments

Comments
 (0)