@onekeyfe/react-native-device-utils 1.1.19 → 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,7 +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
+ import com.margelo.nitro.nativelogger.OneKeyLog
10
10
  import androidx.preference.PreferenceManager
11
11
  import androidx.core.content.ContextCompat
12
12
  import androidx.core.util.Consumer
@@ -216,7 +216,7 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
216
216
  )
217
217
  }
218
218
 
219
- private var windowLayoutInfo: WindowLayoutInfo? = null
219
+ @Volatile private var windowLayoutInfo: WindowLayoutInfo? = null
220
220
  private var isSpanning = false
221
221
  private var layoutInfoConsumer: Consumer<WindowLayoutInfo>? = null
222
222
  private var windowInfoTracker: WindowInfoTracker? = null
@@ -237,10 +237,14 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
237
237
  try {
238
238
  val context = NitroModules.applicationContext ?: return
239
239
  val prefs = PreferenceManager.getDefaultSharedPreferences(context)
240
- 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")
241
245
  applyUserInterfaceStyle(style)
242
246
  } catch (e: Exception) {
243
- // Ignore restore errors
247
+ OneKeyLog.warn("DeviceUtils", "Failed to restore UI style: ${e.message}")
244
248
  }
245
249
  }
246
250
 
@@ -284,6 +288,7 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
284
288
  saveFoldableStatus(true)
285
289
  }
286
290
  isDualScreenDeviceDetected = hasFolding
291
+ OneKeyLog.info("DeviceUtils", "Foldable detected: $hasFolding (${Build.MANUFACTURER} ${Build.MODEL})")
287
292
  return isDualScreenDeviceDetected!!
288
293
  }
289
294
  isDualScreenDeviceDetected = false
@@ -576,7 +581,7 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
576
581
  // Check device model name to determine if it's a foldable device
577
582
  return isFoldableDeviceByName()
578
583
  } catch (e: Exception) {
579
- // WindowManager library not available or device doesn't support foldables
584
+ OneKeyLog.warn("DeviceUtils", "Foldable detection failed: ${e.message}")
580
585
  return false
581
586
  }
582
587
  }
@@ -705,7 +710,7 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
705
710
  try {
706
711
  listener.callback(isSpanning)
707
712
  } catch (e: Exception) {
708
- Log.e("OneKey", "Error in spanning listener callback", e)
713
+ OneKeyLog.error("DeviceUtils", "Error in spanning listener callback: ${e.message}")
709
714
  }
710
715
  }
711
716
  }
@@ -754,7 +759,7 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
754
759
  layoutInfoConsumer!!
755
760
  )
756
761
  } catch (e: Exception) {
757
- // Window tracking not supported on this device/API level, ignore
762
+ OneKeyLog.warn("DeviceUtils", "Window tracking setup failed: ${e.message}")
758
763
  }
759
764
  }
760
765
  }
@@ -787,6 +792,7 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
787
792
 
788
793
  // Emit event if spanning state changed
789
794
  if (wasSpanning != this.isSpanning) {
795
+ OneKeyLog.info("DeviceUtils", "Spanning state changed: $wasSpanning -> ${this.isSpanning}")
790
796
  this.callSpanningChangedListeners(this.isSpanning)
791
797
  }
792
798
  }
@@ -799,6 +805,7 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
799
805
  UserInterfaceStyle.DARK -> "dark"
800
806
  UserInterfaceStyle.UNSPECIFIED -> "unspecified"
801
807
  }
808
+ OneKeyLog.info("DeviceUtils", "Set UI style: $styleString")
802
809
  try {
803
810
  val context = NitroModules.applicationContext
804
811
  if (context != null) {
@@ -826,7 +833,7 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
826
833
  val rootView = activity.window.decorView
827
834
  rootView.rootView.setBackgroundColor(Color.argb(alpha, red, green, blue))
828
835
  } catch (e: Exception) {
829
- e.printStackTrace()
836
+ OneKeyLog.error("DeviceUtils", "Failed to change background color: ${e.message}")
830
837
  }
831
838
  }
832
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.19",
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",