@onekeyfe/react-native-device-utils 1.1.18 → 1.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/android/src/main/java/com/margelo/nitro/reactnativedeviceutils/ReactNativeDeviceUtils.kt
CHANGED
|
@@ -6,6 +6,7 @@ import android.content.pm.PackageManager
|
|
|
6
6
|
import android.graphics.Color
|
|
7
7
|
import android.graphics.Rect
|
|
8
8
|
import android.os.Build
|
|
9
|
+
import android.util.Log
|
|
9
10
|
import androidx.preference.PreferenceManager
|
|
10
11
|
import androidx.core.content.ContextCompat
|
|
11
12
|
import androidx.core.util.Consumer
|
|
@@ -220,7 +221,7 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
|
|
|
220
221
|
private var layoutInfoConsumer: Consumer<WindowLayoutInfo>? = null
|
|
221
222
|
private var windowInfoTracker: WindowInfoTracker? = null
|
|
222
223
|
private var callbackAdapter: WindowInfoTrackerCallbackAdapter? = null
|
|
223
|
-
private
|
|
224
|
+
private val spanningChangedListeners: CopyOnWriteArrayList<Listener> = CopyOnWriteArrayList()
|
|
224
225
|
private var isObservingLayoutChanges = false
|
|
225
226
|
private var nextListenerId = 0.0
|
|
226
227
|
private var isDualScreenDeviceDetected: Boolean? = null
|
|
@@ -697,9 +698,15 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
|
|
|
697
698
|
}
|
|
698
699
|
|
|
699
700
|
fun callSpanningChangedListeners(isSpanning: Boolean) {
|
|
700
|
-
//
|
|
701
|
-
|
|
702
|
-
|
|
701
|
+
// CopyOnWriteArrayList provides snapshot-based iteration that never throws
|
|
702
|
+
// ConcurrentModificationException, even if listeners are added/removed during iteration.
|
|
703
|
+
// Do NOT call .toList() here as it creates a regular ArrayList that is not thread-safe.
|
|
704
|
+
for (listener in spanningChangedListeners) {
|
|
705
|
+
try {
|
|
706
|
+
listener.callback(isSpanning)
|
|
707
|
+
} catch (e: Exception) {
|
|
708
|
+
Log.e("OneKey", "Error in spanning listener callback", e)
|
|
709
|
+
}
|
|
703
710
|
}
|
|
704
711
|
}
|
|
705
712
|
|