rn-system-bar 3.2.5 → 3.2.6
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/android/src/main/java/com/systembar/SystemBarModule.kt +0 -64
- package/index.ts +0 -1
- package/ios/SystemBarModule.m +0 -5
- package/ios/SystemBarModule.swift +0 -53
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -2
- package/lib/src/SystemBar.d.ts +1 -10
- package/lib/src/SystemBar.js +1 -27
- package/lib/src/types.d.ts +0 -9
- package/lib/src/useSystemBar.d.ts +1 -9
- package/lib/src/useSystemBar.js +1 -28
- package/package.json +1 -1
- package/src/SystemBar.ts +0 -33
- package/src/types.ts +0 -15
- package/src/useSystemBar.ts +0 -31
|
@@ -17,7 +17,6 @@ import android.media.AudioManager
|
|
|
17
17
|
import android.net.ConnectivityManager
|
|
18
18
|
import android.net.NetworkCapabilities
|
|
19
19
|
import android.net.NetworkRequest
|
|
20
|
-
import android.os.BatteryManager
|
|
21
20
|
import android.os.Build
|
|
22
21
|
import android.os.Handler
|
|
23
22
|
import android.os.Looper
|
|
@@ -581,68 +580,6 @@ class SystemBarModule(
|
|
|
581
580
|
networkCallback = null
|
|
582
581
|
}
|
|
583
582
|
|
|
584
|
-
// ═══════════════════════════════════════════════
|
|
585
|
-
// BATTERY
|
|
586
|
-
// ═══════════════════════════════════════════════
|
|
587
|
-
|
|
588
|
-
private fun buildBatteryMap(): WritableMap {
|
|
589
|
-
val map = Arguments.createMap()
|
|
590
|
-
val intent = reactContext.registerReceiver(null, IntentFilter(Intent.ACTION_BATTERY_CHANGED))
|
|
591
|
-
|
|
592
|
-
val level = intent?.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) ?: -1
|
|
593
|
-
val scale = intent?.getIntExtra(BatteryManager.EXTRA_SCALE, 100) ?: 100
|
|
594
|
-
val pct = if (scale > 0) (level * 100 / scale) else -1
|
|
595
|
-
|
|
596
|
-
val status = intent?.getIntExtra(BatteryManager.EXTRA_STATUS, BatteryManager.BATTERY_STATUS_UNKNOWN)
|
|
597
|
-
val state = when (status) {
|
|
598
|
-
BatteryManager.BATTERY_STATUS_CHARGING -> "charging"
|
|
599
|
-
BatteryManager.BATTERY_STATUS_FULL -> "full"
|
|
600
|
-
BatteryManager.BATTERY_STATUS_DISCHARGING,
|
|
601
|
-
BatteryManager.BATTERY_STATUS_NOT_CHARGING -> "discharging"
|
|
602
|
-
else -> "unknown"
|
|
603
|
-
}
|
|
604
|
-
val isCharging = state == "charging" || state == "full"
|
|
605
|
-
|
|
606
|
-
map.putInt("level", pct)
|
|
607
|
-
map.putString("state", state)
|
|
608
|
-
map.putBoolean("isCharging", isCharging)
|
|
609
|
-
map.putBoolean("isLow", pct in 0..20 && !isCharging)
|
|
610
|
-
return map
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
@ReactMethod
|
|
614
|
-
fun getBatteryInfo(promise: Promise) {
|
|
615
|
-
try { promise.resolve(buildBatteryMap()) }
|
|
616
|
-
catch (e: Exception) { promise.reject("BATTERY_ERROR", e.message, e) }
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
private var batteryReceiver: BroadcastReceiver? = null
|
|
620
|
-
|
|
621
|
-
@ReactMethod
|
|
622
|
-
fun startBatteryListener() {
|
|
623
|
-
if (batteryReceiver != null) return
|
|
624
|
-
val receiver = object : BroadcastReceiver() {
|
|
625
|
-
override fun onReceive(ctx: Context?, intent: Intent?) {
|
|
626
|
-
emit("SystemBar_BatteryChange", buildBatteryMap())
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
batteryReceiver = receiver
|
|
630
|
-
val filter = IntentFilter().apply {
|
|
631
|
-
addAction(Intent.ACTION_BATTERY_CHANGED)
|
|
632
|
-
addAction(Intent.ACTION_BATTERY_LOW)
|
|
633
|
-
addAction(Intent.ACTION_BATTERY_OKAY)
|
|
634
|
-
addAction(Intent.ACTION_POWER_CONNECTED)
|
|
635
|
-
addAction(Intent.ACTION_POWER_DISCONNECTED)
|
|
636
|
-
}
|
|
637
|
-
reactContext.registerReceiver(receiver, filter)
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
@ReactMethod
|
|
641
|
-
fun stopBatteryListener() {
|
|
642
|
-
batteryReceiver?.let { try { reactContext.unregisterReceiver(it) } catch (_: Exception) {} }
|
|
643
|
-
batteryReceiver = null
|
|
644
|
-
}
|
|
645
|
-
|
|
646
583
|
// ═══════════════════════════════════════════════
|
|
647
584
|
// HAPTICS
|
|
648
585
|
// ═══════════════════════════════════════════════
|
|
@@ -729,7 +666,6 @@ class SystemBarModule(
|
|
|
729
666
|
stopVolumeListener()
|
|
730
667
|
stopSystemScreencastListener()
|
|
731
668
|
stopNetworkListener()
|
|
732
|
-
stopBatteryListener()
|
|
733
669
|
stopFontScaleListener()
|
|
734
670
|
}
|
|
735
671
|
}
|
package/index.ts
CHANGED
package/ios/SystemBarModule.m
CHANGED
|
@@ -28,11 +28,6 @@ RCT_EXTERN_METHOD(getNetworkInfo:(RCTPromiseResolveBlock)resolve rejecter:(RCTPr
|
|
|
28
28
|
RCT_EXTERN_METHOD(startNetworkListener)
|
|
29
29
|
RCT_EXTERN_METHOD(stopNetworkListener)
|
|
30
30
|
|
|
31
|
-
// Battery
|
|
32
|
-
RCT_EXTERN_METHOD(getBatteryInfo:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
33
|
-
RCT_EXTERN_METHOD(startBatteryListener)
|
|
34
|
-
RCT_EXTERN_METHOD(stopBatteryListener)
|
|
35
|
-
|
|
36
31
|
// Haptics
|
|
37
32
|
RCT_EXTERN_METHOD(haptic:(NSString *)pattern)
|
|
38
33
|
|
|
@@ -16,7 +16,6 @@ class SystemBarModule: RCTEventEmitter {
|
|
|
16
16
|
override func supportedEvents() -> [String]! {
|
|
17
17
|
return [
|
|
18
18
|
"SystemBar_NetworkChange",
|
|
19
|
-
"SystemBar_BatteryChange",
|
|
20
19
|
"SystemBar_SystemScreencastChange",
|
|
21
20
|
"SystemBar_FontScaleChange",
|
|
22
21
|
]
|
|
@@ -26,7 +25,6 @@ class SystemBarModule: RCTEventEmitter {
|
|
|
26
25
|
|
|
27
26
|
// ── Listeners state ────────────────────────
|
|
28
27
|
private var networkMonitor: NWPathMonitor?
|
|
29
|
-
private var batteryObservers: [NSObjectProtocol] = []
|
|
30
28
|
private var screencastObserver: NSObjectProtocol?
|
|
31
29
|
private var fontScaleObserver: NSObjectProtocol?
|
|
32
30
|
private var hasListeners = false
|
|
@@ -149,57 +147,6 @@ class SystemBarModule: RCTEventEmitter {
|
|
|
149
147
|
networkMonitor = nil
|
|
150
148
|
}
|
|
151
149
|
|
|
152
|
-
// ═══════════════════════════════════════════════
|
|
153
|
-
// BATTERY
|
|
154
|
-
// ═══════════════════════════════════════════════
|
|
155
|
-
|
|
156
|
-
private func currentBatteryMap() -> [String: Any] {
|
|
157
|
-
UIDevice.current.isBatteryMonitoringEnabled = true
|
|
158
|
-
let raw = UIDevice.current.batteryLevel // -1 if unknown
|
|
159
|
-
let level = raw >= 0 ? Int(raw * 100) : -1
|
|
160
|
-
let state: String
|
|
161
|
-
switch UIDevice.current.batteryState {
|
|
162
|
-
case .charging: state = "charging"
|
|
163
|
-
case .full: state = "full"
|
|
164
|
-
case .unplugged: state = "discharging"
|
|
165
|
-
default: state = "unknown"
|
|
166
|
-
}
|
|
167
|
-
let isCharging = state == "charging" || state == "full"
|
|
168
|
-
return [
|
|
169
|
-
"level": level,
|
|
170
|
-
"state": state,
|
|
171
|
-
"isCharging": isCharging,
|
|
172
|
-
"isLow": level >= 0 && level <= 20 && !isCharging,
|
|
173
|
-
]
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
@objc
|
|
177
|
-
func getBatteryInfo(_ resolve: @escaping RCTPromiseResolveBlock,
|
|
178
|
-
rejecter reject: RCTPromiseRejectBlock) {
|
|
179
|
-
UIDevice.current.isBatteryMonitoringEnabled = true
|
|
180
|
-
resolve(currentBatteryMap())
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
@objc func startBatteryListener() {
|
|
184
|
-
UIDevice.current.isBatteryMonitoringEnabled = true
|
|
185
|
-
let nc = NotificationCenter.default
|
|
186
|
-
batteryObservers = [
|
|
187
|
-
nc.addObserver(forName: UIDevice.batteryLevelDidChangeNotification,
|
|
188
|
-
object: nil, queue: .main) { [weak self] _ in
|
|
189
|
-
self?.emit("SystemBar_BatteryChange", body: self?.currentBatteryMap() ?? [:])
|
|
190
|
-
},
|
|
191
|
-
nc.addObserver(forName: UIDevice.batteryStateDidChangeNotification,
|
|
192
|
-
object: nil, queue: .main) { [weak self] _ in
|
|
193
|
-
self?.emit("SystemBar_BatteryChange", body: self?.currentBatteryMap() ?? [:])
|
|
194
|
-
},
|
|
195
|
-
]
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
@objc func stopBatteryListener() {
|
|
199
|
-
batteryObservers.forEach { NotificationCenter.default.removeObserver($0) }
|
|
200
|
-
batteryObservers = []
|
|
201
|
-
UIDevice.current.isBatteryMonitoringEnabled = false
|
|
202
|
-
}
|
|
203
150
|
|
|
204
151
|
// ═══════════════════════════════════════════════
|
|
205
152
|
// HAPTIC FEEDBACK
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from "./src/SystemBar";
|
|
2
2
|
export * from "./src/types";
|
|
3
3
|
export { setGlobalThemeMode, useTheme } from "./src/useTheme";
|
|
4
|
-
export {
|
|
4
|
+
export { useFontScale, useNetwork, useScreencast, useSystemBar, useSystemScreencast, useTheme as useThemeHook, useThemeSystemBar, } from "./src/useSystemBar";
|
|
5
5
|
export type { SystemBarConfig, ThemedSystemBarConfig, } from "./src/useSystemBar";
|
package/lib/index.js
CHANGED
|
@@ -17,7 +17,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
17
17
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.useThemeSystemBar = exports.useThemeHook = exports.useSystemScreencast = exports.useSystemBar = exports.useScreencast = exports.useNetwork = exports.useFontScale = exports.
|
|
20
|
+
exports.useThemeSystemBar = exports.useThemeHook = exports.useSystemScreencast = exports.useSystemBar = exports.useScreencast = exports.useNetwork = exports.useFontScale = exports.useTheme = exports.setGlobalThemeMode = void 0;
|
|
21
21
|
// All imperative JS/TS APIs
|
|
22
22
|
__exportStar(require("./src/SystemBar"), exports);
|
|
23
23
|
// All TypeScript types
|
|
@@ -28,7 +28,6 @@ Object.defineProperty(exports, "setGlobalThemeMode", { enumerable: true, get: fu
|
|
|
28
28
|
Object.defineProperty(exports, "useTheme", { enumerable: true, get: function () { return useTheme_1.useTheme; } });
|
|
29
29
|
// React hooks
|
|
30
30
|
var useSystemBar_1 = require("./src/useSystemBar");
|
|
31
|
-
Object.defineProperty(exports, "useBattery", { enumerable: true, get: function () { return useSystemBar_1.useBattery; } });
|
|
32
31
|
Object.defineProperty(exports, "useFontScale", { enumerable: true, get: function () { return useSystemBar_1.useFontScale; } });
|
|
33
32
|
Object.defineProperty(exports, "useNetwork", { enumerable: true, get: function () { return useSystemBar_1.useNetwork; } });
|
|
34
33
|
Object.defineProperty(exports, "useScreencast", { enumerable: true, get: function () { return useSystemBar_1.useScreencast; } });
|
package/lib/src/SystemBar.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { FontScaleInfo, HapticPattern, NavigationBarBehavior, NavigationBarButtonStyle, NavigationBarColorValue, NavigationBarStyle, NavigationBarVisibility, NetworkInfo, Orientation, StatusBarColorValue, StatusBarStyle, SystemScreencastInfo, VolumeStream } from "./types";
|
|
2
2
|
export declare const setNavigationBarColor: (color: NavigationBarColorValue) => void;
|
|
3
3
|
export declare const setNavigationBarVisibility: (mode: NavigationBarVisibility) => void;
|
|
4
4
|
export declare const setNavigationBarButtonStyle: (style: NavigationBarButtonStyle) => void;
|
|
@@ -36,15 +36,6 @@ export declare const getNetworkInfo: () => Promise<NetworkInfo>;
|
|
|
36
36
|
* @returns unsubscribe function
|
|
37
37
|
*/
|
|
38
38
|
export declare const onNetworkChange: (callback: (info: NetworkInfo) => void) => (() => void);
|
|
39
|
-
/**
|
|
40
|
-
* One-shot snapshot of the current battery state.
|
|
41
|
-
*/
|
|
42
|
-
export declare const getBatteryInfo: () => Promise<BatteryInfo>;
|
|
43
|
-
/**
|
|
44
|
-
* Subscribe to battery level / state changes.
|
|
45
|
-
* @returns unsubscribe function
|
|
46
|
-
*/
|
|
47
|
-
export declare const onBatteryChange: (callback: (info: BatteryInfo) => void) => (() => void);
|
|
48
39
|
/**
|
|
49
40
|
* Trigger a haptic feedback pattern.
|
|
50
41
|
* iOS: UIFeedbackGenerator. Android: Vibrator.
|
package/lib/src/SystemBar.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// All APIs → native Kotlin (Android) / Swift (iOS)
|
|
5
5
|
// ─────────────────────────────────────────────
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.onScreencastChange = exports.getScreencastInfo = exports.onFontScaleChange = exports.getFontScaleInfo = exports.onSystemScreencastChange = exports.getSystemScreencastInfo = exports.haptic = exports.
|
|
7
|
+
exports.onScreencastChange = exports.getScreencastInfo = exports.onFontScaleChange = exports.getFontScaleInfo = exports.onSystemScreencastChange = exports.getSystemScreencastInfo = exports.haptic = exports.onNetworkChange = exports.getNetworkInfo = exports.setOrientation = exports.setSecureScreen = exports.immersiveMode = exports.keepScreenOn = exports.onVolumeChange = exports.setVolumeHUDVisible = exports.getVolume = exports.setVolume = exports.onBrightnessChange = exports.getBrightness = exports.setBrightness = exports.setStatusBarVisibility = exports.setStatusBarStyle = exports.setStatusBarColor = exports.setNavigationBarBehavior = exports.setNavigationBarStyle = exports.setNavigationBarButtonStyle = exports.setNavigationBarVisibility = exports.setNavigationBarColor = void 0;
|
|
8
8
|
const react_native_1 = require("react-native");
|
|
9
9
|
const { SystemBar: Native } = react_native_1.NativeModules;
|
|
10
10
|
const isAndroid = react_native_1.Platform.OS === "android";
|
|
@@ -201,32 +201,6 @@ const onNetworkChange = (callback) => {
|
|
|
201
201
|
};
|
|
202
202
|
exports.onNetworkChange = onNetworkChange;
|
|
203
203
|
// ═══════════════════════════════════════════════
|
|
204
|
-
// BATTERY
|
|
205
|
-
// ═══════════════════════════════════════════════
|
|
206
|
-
/**
|
|
207
|
-
* One-shot snapshot of the current battery state.
|
|
208
|
-
*/
|
|
209
|
-
const getBatteryInfo = () => {
|
|
210
|
-
checkNative("getBatteryInfo");
|
|
211
|
-
return Native.getBatteryInfo();
|
|
212
|
-
};
|
|
213
|
-
exports.getBatteryInfo = getBatteryInfo;
|
|
214
|
-
/**
|
|
215
|
-
* Subscribe to battery level / state changes.
|
|
216
|
-
* @returns unsubscribe function
|
|
217
|
-
*/
|
|
218
|
-
const onBatteryChange = (callback) => {
|
|
219
|
-
checkNative();
|
|
220
|
-
const { DeviceEventEmitter } = require("react-native");
|
|
221
|
-
Native.startBatteryListener();
|
|
222
|
-
const sub = DeviceEventEmitter.addListener("SystemBar_BatteryChange", callback);
|
|
223
|
-
return () => {
|
|
224
|
-
sub.remove();
|
|
225
|
-
Native.stopBatteryListener();
|
|
226
|
-
};
|
|
227
|
-
};
|
|
228
|
-
exports.onBatteryChange = onBatteryChange;
|
|
229
|
-
// ═══════════════════════════════════════════════
|
|
230
204
|
// HAPTICS
|
|
231
205
|
// ═══════════════════════════════════════════════
|
|
232
206
|
/**
|
package/lib/src/types.d.ts
CHANGED
|
@@ -51,15 +51,6 @@ export interface NetworkInfo {
|
|
|
51
51
|
/** Cellular generation e.g. "4g" | "5g" — Android only; null on iOS. */
|
|
52
52
|
cellularGeneration: string | null;
|
|
53
53
|
}
|
|
54
|
-
export type BatteryState = "charging" | "discharging" | "full" | "unknown";
|
|
55
|
-
export interface BatteryInfo {
|
|
56
|
-
/** Battery level 0–100, or -1 if unknown. */
|
|
57
|
-
level: number;
|
|
58
|
-
state: BatteryState;
|
|
59
|
-
isCharging: boolean;
|
|
60
|
-
/** True when level ≤ 20 and not charging. */
|
|
61
|
-
isLow: boolean;
|
|
62
|
-
}
|
|
63
54
|
export type HapticPattern = "light" | "medium" | "heavy" | "success" | "warning" | "error" | "selection";
|
|
64
55
|
export interface FontScaleInfo {
|
|
65
56
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { FontScaleInfo, NavigationBarBehavior, NavigationBarButtonStyle, NavigationBarColorValue, NavigationBarStyle, NavigationBarVisibility, NetworkInfo, Orientation, ScreencastInfo, StatusBarColorValue, StatusBarStyle, SystemScreencastInfo, ThemeMode, ThemeState } from "./types";
|
|
2
2
|
export interface SystemBarConfig {
|
|
3
3
|
navigationBarColor?: NavigationBarColorValue;
|
|
4
4
|
navigationBarVisibility?: NavigationBarVisibility;
|
|
@@ -34,14 +34,6 @@ export declare const useScreencast: () => ScreencastInfo;
|
|
|
34
34
|
* const { isConnected, type } = useNetwork();
|
|
35
35
|
*/
|
|
36
36
|
export declare const useNetwork: () => NetworkInfo;
|
|
37
|
-
/**
|
|
38
|
-
* Subscribe to battery state. Fires immediately with the current snapshot,
|
|
39
|
-
* then on every level / state change.
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* const { level, isCharging, isLow } = useBattery();
|
|
43
|
-
*/
|
|
44
|
-
export declare const useBattery: () => BatteryInfo;
|
|
45
37
|
/**
|
|
46
38
|
* Subscribe to system font scale changes (accessibility text size).
|
|
47
39
|
*
|
package/lib/src/useSystemBar.js
CHANGED
|
@@ -36,7 +36,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
36
36
|
};
|
|
37
37
|
})();
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.useFontScale = exports.
|
|
39
|
+
exports.useFontScale = exports.useNetwork = exports.useScreencast = exports.useSystemScreencast = exports.useTheme = exports.useThemeSystemBar = exports.useSystemBar = void 0;
|
|
40
40
|
const react_1 = require("react");
|
|
41
41
|
const SystemBar = __importStar(require("./SystemBar"));
|
|
42
42
|
const useTheme_1 = require("./useTheme");
|
|
@@ -170,33 +170,6 @@ const useNetwork = () => {
|
|
|
170
170
|
};
|
|
171
171
|
exports.useNetwork = useNetwork;
|
|
172
172
|
// ─────────────────────────────────────────────
|
|
173
|
-
// useBattery
|
|
174
|
-
// ─────────────────────────────────────────────
|
|
175
|
-
/**
|
|
176
|
-
* Subscribe to battery state. Fires immediately with the current snapshot,
|
|
177
|
-
* then on every level / state change.
|
|
178
|
-
*
|
|
179
|
-
* @example
|
|
180
|
-
* const { level, isCharging, isLow } = useBattery();
|
|
181
|
-
*/
|
|
182
|
-
const useBattery = () => {
|
|
183
|
-
const [info, setInfo] = (0, react_1.useState)({
|
|
184
|
-
level: -1,
|
|
185
|
-
state: "unknown",
|
|
186
|
-
isCharging: false,
|
|
187
|
-
isLow: false,
|
|
188
|
-
});
|
|
189
|
-
(0, react_1.useEffect)(() => {
|
|
190
|
-
SystemBar.getBatteryInfo()
|
|
191
|
-
.then(setInfo)
|
|
192
|
-
.catch(() => { });
|
|
193
|
-
const unsub = SystemBar.onBatteryChange(setInfo);
|
|
194
|
-
return () => unsub();
|
|
195
|
-
}, []);
|
|
196
|
-
return info;
|
|
197
|
-
};
|
|
198
|
-
exports.useBattery = useBattery;
|
|
199
|
-
// ─────────────────────────────────────────────
|
|
200
173
|
// useFontScale
|
|
201
174
|
// ─────────────────────────────────────────────
|
|
202
175
|
/**
|
package/package.json
CHANGED
package/src/SystemBar.ts
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
import { NativeModules, Platform } from "react-native";
|
|
7
7
|
|
|
8
8
|
import type {
|
|
9
|
-
BatteryInfo,
|
|
10
9
|
FontScaleInfo,
|
|
11
10
|
HapticPattern,
|
|
12
11
|
NavigationBarBehavior,
|
|
@@ -247,38 +246,6 @@ export const onNetworkChange = (
|
|
|
247
246
|
};
|
|
248
247
|
};
|
|
249
248
|
|
|
250
|
-
// ═══════════════════════════════════════════════
|
|
251
|
-
// BATTERY
|
|
252
|
-
// ═══════════════════════════════════════════════
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* One-shot snapshot of the current battery state.
|
|
256
|
-
*/
|
|
257
|
-
export const getBatteryInfo = (): Promise<BatteryInfo> => {
|
|
258
|
-
checkNative("getBatteryInfo");
|
|
259
|
-
return Native.getBatteryInfo();
|
|
260
|
-
};
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Subscribe to battery level / state changes.
|
|
264
|
-
* @returns unsubscribe function
|
|
265
|
-
*/
|
|
266
|
-
export const onBatteryChange = (
|
|
267
|
-
callback: (info: BatteryInfo) => void,
|
|
268
|
-
): (() => void) => {
|
|
269
|
-
checkNative();
|
|
270
|
-
const { DeviceEventEmitter } = require("react-native");
|
|
271
|
-
Native.startBatteryListener();
|
|
272
|
-
const sub = DeviceEventEmitter.addListener(
|
|
273
|
-
"SystemBar_BatteryChange",
|
|
274
|
-
callback,
|
|
275
|
-
);
|
|
276
|
-
return () => {
|
|
277
|
-
sub.remove();
|
|
278
|
-
Native.stopBatteryListener();
|
|
279
|
-
};
|
|
280
|
-
};
|
|
281
|
-
|
|
282
249
|
// ═══════════════════════════════════════════════
|
|
283
250
|
// HAPTICS
|
|
284
251
|
// ═══════════════════════════════════════════════
|
package/src/types.ts
CHANGED
|
@@ -92,21 +92,6 @@ export interface NetworkInfo {
|
|
|
92
92
|
cellularGeneration: string | null;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
// ─────────────────────────────────────────────
|
|
96
|
-
// Battery
|
|
97
|
-
// ─────────────────────────────────────────────
|
|
98
|
-
|
|
99
|
-
export type BatteryState = "charging" | "discharging" | "full" | "unknown";
|
|
100
|
-
|
|
101
|
-
export interface BatteryInfo {
|
|
102
|
-
/** Battery level 0–100, or -1 if unknown. */
|
|
103
|
-
level: number;
|
|
104
|
-
state: BatteryState;
|
|
105
|
-
isCharging: boolean;
|
|
106
|
-
/** True when level ≤ 20 and not charging. */
|
|
107
|
-
isLow: boolean;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
95
|
// ─────────────────────────────────────────────
|
|
111
96
|
// Haptics
|
|
112
97
|
// ─────────────────────────────────────────────
|
package/src/useSystemBar.ts
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
import { useEffect, useState } from "react";
|
|
6
6
|
import * as SystemBar from "./SystemBar";
|
|
7
7
|
import type {
|
|
8
|
-
BatteryInfo,
|
|
9
8
|
FontScaleInfo,
|
|
10
9
|
NavigationBarBehavior,
|
|
11
10
|
NavigationBarButtonStyle,
|
|
@@ -207,36 +206,6 @@ export const useNetwork = (): NetworkInfo => {
|
|
|
207
206
|
return info;
|
|
208
207
|
};
|
|
209
208
|
|
|
210
|
-
// ─────────────────────────────────────────────
|
|
211
|
-
// useBattery
|
|
212
|
-
// ─────────────────────────────────────────────
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Subscribe to battery state. Fires immediately with the current snapshot,
|
|
216
|
-
* then on every level / state change.
|
|
217
|
-
*
|
|
218
|
-
* @example
|
|
219
|
-
* const { level, isCharging, isLow } = useBattery();
|
|
220
|
-
*/
|
|
221
|
-
export const useBattery = (): BatteryInfo => {
|
|
222
|
-
const [info, setInfo] = useState<BatteryInfo>({
|
|
223
|
-
level: -1,
|
|
224
|
-
state: "unknown",
|
|
225
|
-
isCharging: false,
|
|
226
|
-
isLow: false,
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
useEffect(() => {
|
|
230
|
-
SystemBar.getBatteryInfo()
|
|
231
|
-
.then(setInfo)
|
|
232
|
-
.catch(() => {});
|
|
233
|
-
const unsub = SystemBar.onBatteryChange(setInfo);
|
|
234
|
-
return () => unsub();
|
|
235
|
-
}, []);
|
|
236
|
-
|
|
237
|
-
return info;
|
|
238
|
-
};
|
|
239
|
-
|
|
240
209
|
// ─────────────────────────────────────────────
|
|
241
210
|
// useFontScale
|
|
242
211
|
// ─────────────────────────────────────────────
|