@kontextso/sdk-react-native 3.2.0-rc.3 → 3.2.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kontextso/sdk-react-native",
3
- "version": "3.2.0-rc.3",
3
+ "version": "3.2.1",
4
4
  "description": "Kontext SDK for React Native",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -20,6 +20,13 @@ ErrorUtils.setGlobalHandler((error, isFatal) => {
20
20
  }
21
21
  })
22
22
 
23
+ const batteryLevelToPercent = (level: unknown): number | undefined => {
24
+ if (typeof level !== 'number' || !isFinite(level)) return undefined
25
+ if (level < 0) return undefined
26
+
27
+ return Math.max(0, Math.min(100, Math.round(level * 100)))
28
+ }
29
+
23
30
  const getDevice = async (): Promise<DeviceConfig> => {
24
31
  try {
25
32
  const powerState = await DeviceInfo.getPowerState()
@@ -79,7 +86,7 @@ const getDevice = async (): Promise<DeviceConfig> => {
79
86
  orientation: screen.width > screen.height ? 'landscape' : 'portrait',
80
87
  },
81
88
  power: {
82
- batteryLevel: powerState.batteryLevel,
89
+ batteryLevel: batteryLevelToPercent(powerState.batteryLevel),
83
90
  batteryState: powerState.batteryState,
84
91
  lowPowerMode: powerState.lowPowerMode,
85
92
  },