@onekeyfe/react-native-device-utils 1.1.17 → 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
 
@@ -786,17 +793,22 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
786
793
 
787
794
  // MARK: - User Interface Style
788
795
 
789
- override fun setUserInterfaceStyle(style: String) {
796
+ override fun setUserInterfaceStyle(style: UserInterfaceStyle) {
797
+ val styleString = when (style) {
798
+ UserInterfaceStyle.LIGHT -> "light"
799
+ UserInterfaceStyle.DARK -> "dark"
800
+ UserInterfaceStyle.UNSPECIFIED -> "unspecified"
801
+ }
790
802
  try {
791
803
  val context = NitroModules.applicationContext
792
804
  if (context != null) {
793
805
  val prefs = PreferenceManager.getDefaultSharedPreferences(context)
794
- prefs.edit().putString(PREF_KEY_UI_STYLE, style).apply()
806
+ prefs.edit().putString(PREF_KEY_UI_STYLE, styleString).apply()
795
807
  }
796
808
  } catch (e: Exception) {
797
809
  // Ignore save errors
798
810
  }
799
- applyUserInterfaceStyle(style)
811
+ applyUserInterfaceStyle(styleString)
800
812
  }
801
813
 
802
814
  // MARK: - Background Color
@@ -69,9 +69,9 @@ class ReactNativeDeviceUtils: HybridReactNativeDeviceUtilsSpec {
69
69
  }
70
70
 
71
71
 
72
- public func setUserInterfaceStyle(style: String) throws -> Void {
73
- UserDefaults.standard.set(style, forKey: ReactNativeDeviceUtils.userInterfaceStyleKey)
74
- applyUserInterfaceStyle(style)
72
+ public func setUserInterfaceStyle(style: UserInterfaceStyle) throws -> Void {
73
+ UserDefaults.standard.set(style.stringValue, forKey: ReactNativeDeviceUtils.userInterfaceStyleKey)
74
+ applyUserInterfaceStyle(style.stringValue)
75
75
  }
76
76
 
77
77
  public func changeBackgroundColor(r: Double, g: Double, b: Double, a: Double) throws -> Void {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/react-native-device-utils",
3
- "version": "1.1.17",
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",