@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.
@@ -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 var spanningChangedListeners: MutableList<Listener> = CopyOnWriteArrayList()
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
- // Create a snapshot to avoid ConcurrentModificationException when listeners modify the list during callbacks
701
- for (listener in spanningChangedListeners.toList()) {
702
- listener.callback(isSpanning)
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/react-native-device-utils",
3
- "version": "1.1.18",
3
+ "version": "1.1.19",
4
4
  "description": "react-native-device-utils",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",