@onekeyfe/react-native-device-utils 1.1.18 → 1.1.20

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.
@@ -21,6 +21,7 @@ Pod::Spec.new do |s|
21
21
 
22
22
  s.dependency 'React-jsi'
23
23
  s.dependency 'React-callinvoker'
24
+ s.dependency 'ReactNativeNativeLogger'
24
25
 
25
26
  load 'nitrogen/generated/ios/ReactNativeDeviceUtils+autolinking.rb'
26
27
  add_nitrogen_files(s)
@@ -133,4 +133,6 @@ dependencies {
133
133
  implementation "androidx.appcompat:appcompat:1.7.1"
134
134
  // AndroidX Preference for PreferenceManager
135
135
  implementation "androidx.preference:preference-ktx:1.2.1"
136
+
137
+ implementation project(":react-native-native-logger")
136
138
  }
@@ -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 com.margelo.nitro.nativelogger.OneKeyLog
9
10
  import androidx.preference.PreferenceManager
10
11
  import androidx.core.content.ContextCompat
11
12
  import androidx.core.util.Consumer
@@ -215,12 +216,12 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
215
216
  )
216
217
  }
217
218
 
218
- private var windowLayoutInfo: WindowLayoutInfo? = null
219
+ @Volatile private var windowLayoutInfo: WindowLayoutInfo? = null
219
220
  private var isSpanning = false
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
@@ -236,10 +237,14 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
236
237
  try {
237
238
  val context = NitroModules.applicationContext ?: return
238
239
  val prefs = PreferenceManager.getDefaultSharedPreferences(context)
239
- val style = prefs.getString(PREF_KEY_UI_STYLE, null) ?: return
240
+ val style = prefs.getString(PREF_KEY_UI_STYLE, null) ?: run {
241
+ OneKeyLog.debug("DeviceUtils", "No saved UI style found")
242
+ return
243
+ }
244
+ OneKeyLog.info("DeviceUtils", "Restored UI style: $style")
240
245
  applyUserInterfaceStyle(style)
241
246
  } catch (e: Exception) {
242
- // Ignore restore errors
247
+ OneKeyLog.warn("DeviceUtils", "Failed to restore UI style: ${e.message}")
243
248
  }
244
249
  }
245
250
 
@@ -283,6 +288,7 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
283
288
  saveFoldableStatus(true)
284
289
  }
285
290
  isDualScreenDeviceDetected = hasFolding
291
+ OneKeyLog.info("DeviceUtils", "Foldable detected: $hasFolding (${Build.MANUFACTURER} ${Build.MODEL})")
286
292
  return isDualScreenDeviceDetected!!
287
293
  }
288
294
  isDualScreenDeviceDetected = false
@@ -575,7 +581,7 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
575
581
  // Check device model name to determine if it's a foldable device
576
582
  return isFoldableDeviceByName()
577
583
  } catch (e: Exception) {
578
- // WindowManager library not available or device doesn't support foldables
584
+ OneKeyLog.warn("DeviceUtils", "Foldable detection failed: ${e.message}")
579
585
  return false
580
586
  }
581
587
  }
@@ -697,9 +703,15 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
697
703
  }
698
704
 
699
705
  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)
706
+ // CopyOnWriteArrayList provides snapshot-based iteration that never throws
707
+ // ConcurrentModificationException, even if listeners are added/removed during iteration.
708
+ // Do NOT call .toList() here as it creates a regular ArrayList that is not thread-safe.
709
+ for (listener in spanningChangedListeners) {
710
+ try {
711
+ listener.callback(isSpanning)
712
+ } catch (e: Exception) {
713
+ OneKeyLog.error("DeviceUtils", "Error in spanning listener callback: ${e.message}")
714
+ }
703
715
  }
704
716
  }
705
717
 
@@ -747,7 +759,7 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
747
759
  layoutInfoConsumer!!
748
760
  )
749
761
  } catch (e: Exception) {
750
- // Window tracking not supported on this device/API level, ignore
762
+ OneKeyLog.warn("DeviceUtils", "Window tracking setup failed: ${e.message}")
751
763
  }
752
764
  }
753
765
  }
@@ -780,6 +792,7 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
780
792
 
781
793
  // Emit event if spanning state changed
782
794
  if (wasSpanning != this.isSpanning) {
795
+ OneKeyLog.info("DeviceUtils", "Spanning state changed: $wasSpanning -> ${this.isSpanning}")
783
796
  this.callSpanningChangedListeners(this.isSpanning)
784
797
  }
785
798
  }
@@ -792,6 +805,7 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
792
805
  UserInterfaceStyle.DARK -> "dark"
793
806
  UserInterfaceStyle.UNSPECIFIED -> "unspecified"
794
807
  }
808
+ OneKeyLog.info("DeviceUtils", "Set UI style: $styleString")
795
809
  try {
796
810
  val context = NitroModules.applicationContext
797
811
  if (context != null) {
@@ -819,7 +833,7 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
819
833
  val rootView = activity.window.decorView
820
834
  rootView.rootView.setBackgroundColor(Color.argb(alpha, red, green, blue))
821
835
  } catch (e: Exception) {
822
- e.printStackTrace()
836
+ OneKeyLog.error("DeviceUtils", "Failed to change background color: ${e.message}")
823
837
  }
824
838
  }
825
839
  }
@@ -1,5 +1,6 @@
1
1
  import NitroModules
2
2
  import UIKit
3
+ import ReactNativeNativeLogger
3
4
 
4
5
  class ReactNativeDeviceUtils: HybridReactNativeDeviceUtilsSpec {
5
6
 
@@ -12,8 +13,10 @@ class ReactNativeDeviceUtils: HybridReactNativeDeviceUtilsSpec {
12
13
 
13
14
  private func restoreUserInterfaceStyle() {
14
15
  guard let style = UserDefaults.standard.string(forKey: ReactNativeDeviceUtils.userInterfaceStyleKey) else {
16
+ OneKeyLog.debug("DeviceUtils", "No saved UI style found")
15
17
  return
16
18
  }
19
+ OneKeyLog.info("DeviceUtils", "Restored UI style: \(style)")
17
20
  applyUserInterfaceStyle(style)
18
21
  }
19
22
 
@@ -70,6 +73,7 @@ class ReactNativeDeviceUtils: HybridReactNativeDeviceUtilsSpec {
70
73
 
71
74
 
72
75
  public func setUserInterfaceStyle(style: UserInterfaceStyle) throws -> Void {
76
+ OneKeyLog.info("DeviceUtils", "Set UI style: \(style.stringValue)")
73
77
  UserDefaults.standard.set(style.stringValue, forKey: ReactNativeDeviceUtils.userInterfaceStyleKey)
74
78
  applyUserInterfaceStyle(style.stringValue)
75
79
  }
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.20",
4
4
  "description": "react-native-device-utils",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",