rn-system-bar 3.2.4 → 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/AndroidManifest.xml +9 -1
- package/android/src/main/java/com/systembar/SystemBarModule.kt +159 -0
- 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
|
@@ -6,4 +6,12 @@
|
|
|
6
6
|
android:name="android.permission.WRITE_SETTINGS"
|
|
7
7
|
tools:ignore="ProtectedPermissions" />
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
<!-- Required for network state / listener -->
|
|
10
|
+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
|
11
|
+
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
|
12
|
+
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
|
|
13
|
+
|
|
14
|
+
<!-- Required for haptic feedback / vibration -->
|
|
15
|
+
<uses-permission android:name="android.permission.VIBRATE" />
|
|
16
|
+
|
|
17
|
+
</manifest>
|
|
@@ -10,13 +10,21 @@ import android.content.Context
|
|
|
10
10
|
import android.content.Intent
|
|
11
11
|
import android.content.IntentFilter
|
|
12
12
|
import android.content.pm.ActivityInfo
|
|
13
|
+
import android.content.res.Configuration
|
|
13
14
|
import android.graphics.Color
|
|
14
15
|
import android.hardware.display.DisplayManager
|
|
15
16
|
import android.media.AudioManager
|
|
17
|
+
import android.net.ConnectivityManager
|
|
18
|
+
import android.net.NetworkCapabilities
|
|
19
|
+
import android.net.NetworkRequest
|
|
16
20
|
import android.os.Build
|
|
17
21
|
import android.os.Handler
|
|
18
22
|
import android.os.Looper
|
|
23
|
+
import android.os.VibrationEffect
|
|
24
|
+
import android.os.Vibrator
|
|
25
|
+
import android.os.VibratorManager
|
|
19
26
|
import android.provider.Settings
|
|
27
|
+
import android.util.DisplayMetrics
|
|
20
28
|
import android.view.View
|
|
21
29
|
import android.view.WindowInsets
|
|
22
30
|
import android.view.WindowInsetsController
|
|
@@ -503,10 +511,161 @@ class SystemBarModule(
|
|
|
503
511
|
displayListener = null
|
|
504
512
|
}
|
|
505
513
|
|
|
514
|
+
|
|
515
|
+
// ═══════════════════════════════════════════════
|
|
516
|
+
// NETWORK
|
|
517
|
+
// ═══════════════════════════════════════════════
|
|
518
|
+
|
|
519
|
+
private fun connectivityManager() =
|
|
520
|
+
reactContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
|
521
|
+
|
|
522
|
+
private fun buildNetworkMap(): WritableMap {
|
|
523
|
+
val cm = connectivityManager()
|
|
524
|
+
val map = Arguments.createMap()
|
|
525
|
+
|
|
526
|
+
val net = cm.activeNetwork
|
|
527
|
+
val caps = if (net != null) cm.getNetworkCapabilities(net) else null
|
|
528
|
+
|
|
529
|
+
val isConnected = caps != null &&
|
|
530
|
+
(caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) ||
|
|
531
|
+
caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED))
|
|
532
|
+
|
|
533
|
+
val type = when {
|
|
534
|
+
caps == null -> "none"
|
|
535
|
+
caps.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) -> "wifi"
|
|
536
|
+
caps.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) -> "cellular"
|
|
537
|
+
caps.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET) -> "ethernet"
|
|
538
|
+
else -> "unknown"
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
map.putString("type", type)
|
|
542
|
+
map.putBoolean("isConnected", isConnected)
|
|
543
|
+
val airplaneMode = Settings.Global.getInt(
|
|
544
|
+
reactContext.contentResolver, Settings.Global.AIRPLANE_MODE_ON, 0) == 1
|
|
545
|
+
map.putBoolean("isAirplaneMode", airplaneMode)
|
|
546
|
+
map.putNull("ssid")
|
|
547
|
+
map.putNull("cellularGeneration")
|
|
548
|
+
return map
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
@ReactMethod
|
|
552
|
+
fun getNetworkInfo(promise: Promise) {
|
|
553
|
+
try { promise.resolve(buildNetworkMap()) }
|
|
554
|
+
catch (e: Exception) { promise.reject("NETWORK_ERROR", e.message, e) }
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
private var networkCallback: ConnectivityManager.NetworkCallback? = null
|
|
558
|
+
|
|
559
|
+
@ReactMethod
|
|
560
|
+
fun startNetworkListener() {
|
|
561
|
+
if (networkCallback != null) return
|
|
562
|
+
val cb = object : ConnectivityManager.NetworkCallback() {
|
|
563
|
+
override fun onAvailable(network: android.net.Network) { emit("SystemBar_NetworkChange", buildNetworkMap()) }
|
|
564
|
+
override fun onLost(network: android.net.Network) { emit("SystemBar_NetworkChange", buildNetworkMap()) }
|
|
565
|
+
override fun onCapabilitiesChanged(
|
|
566
|
+
network: android.net.Network,
|
|
567
|
+
caps: NetworkCapabilities
|
|
568
|
+
) { emit("SystemBar_NetworkChange", buildNetworkMap()) }
|
|
569
|
+
}
|
|
570
|
+
networkCallback = cb
|
|
571
|
+
val request = NetworkRequest.Builder().build()
|
|
572
|
+
connectivityManager().registerNetworkCallback(request, cb)
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
@ReactMethod
|
|
576
|
+
fun stopNetworkListener() {
|
|
577
|
+
networkCallback?.let {
|
|
578
|
+
try { connectivityManager().unregisterNetworkCallback(it) } catch (_: Exception) {}
|
|
579
|
+
}
|
|
580
|
+
networkCallback = null
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
// ═══════════════════════════════════════════════
|
|
584
|
+
// HAPTICS
|
|
585
|
+
// ═══════════════════════════════════════════════
|
|
586
|
+
|
|
587
|
+
private fun vibrator(): Vibrator =
|
|
588
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
589
|
+
(reactContext.getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager)
|
|
590
|
+
.defaultVibrator
|
|
591
|
+
} else {
|
|
592
|
+
@Suppress("DEPRECATION")
|
|
593
|
+
reactContext.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
@ReactMethod
|
|
597
|
+
fun haptic(pattern: String) {
|
|
598
|
+
try {
|
|
599
|
+
val vib = vibrator()
|
|
600
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
601
|
+
val effect = when (pattern) {
|
|
602
|
+
"light" -> VibrationEffect.createOneShot(30, 80)
|
|
603
|
+
"medium" -> VibrationEffect.createOneShot(50, 150)
|
|
604
|
+
"heavy" -> VibrationEffect.createOneShot(80, 255)
|
|
605
|
+
"success" -> VibrationEffect.createWaveform(longArrayOf(0, 40, 60, 40), intArrayOf(0, 180, 0, 255), -1)
|
|
606
|
+
"warning" -> VibrationEffect.createWaveform(longArrayOf(0, 60, 40, 60), intArrayOf(0, 200, 0, 200), -1)
|
|
607
|
+
"error" -> VibrationEffect.createWaveform(longArrayOf(0, 80, 40, 80, 40, 80), intArrayOf(0, 255, 0, 255, 0, 255), -1)
|
|
608
|
+
"selection" -> VibrationEffect.createOneShot(20, 60)
|
|
609
|
+
else -> VibrationEffect.createOneShot(50, 150)
|
|
610
|
+
}
|
|
611
|
+
vib.vibrate(effect)
|
|
612
|
+
} else {
|
|
613
|
+
@Suppress("DEPRECATION")
|
|
614
|
+
vib.vibrate(when (pattern) {
|
|
615
|
+
"light" -> 30L
|
|
616
|
+
"heavy" -> 80L
|
|
617
|
+
"selection" -> 20L
|
|
618
|
+
else -> 50L
|
|
619
|
+
})
|
|
620
|
+
}
|
|
621
|
+
} catch (_: Exception) {}
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
// ═══════════════════════════════════════════════
|
|
625
|
+
// FONT SCALE
|
|
626
|
+
// ═══════════════════════════════════════════════
|
|
627
|
+
|
|
628
|
+
private fun buildFontScaleMap(): WritableMap {
|
|
629
|
+
val map = Arguments.createMap()
|
|
630
|
+
val config = reactContext.resources.configuration
|
|
631
|
+
val metrics = reactContext.resources.displayMetrics
|
|
632
|
+
map.putDouble("fontScale", config.fontScale.toDouble())
|
|
633
|
+
map.putDouble("density", metrics.density.toDouble())
|
|
634
|
+
return map
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
@ReactMethod
|
|
638
|
+
fun getFontScaleInfo(promise: Promise) {
|
|
639
|
+
try { promise.resolve(buildFontScaleMap()) }
|
|
640
|
+
catch (e: Exception) { promise.reject("FONTSCALE_ERROR", e.message, e) }
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
private var fontScaleReceiver: BroadcastReceiver? = null
|
|
644
|
+
|
|
645
|
+
@ReactMethod
|
|
646
|
+
fun startFontScaleListener() {
|
|
647
|
+
if (fontScaleReceiver != null) return
|
|
648
|
+
val receiver = object : BroadcastReceiver() {
|
|
649
|
+
override fun onReceive(ctx: Context?, intent: Intent?) {
|
|
650
|
+
emit("SystemBar_FontScaleChange", buildFontScaleMap())
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
fontScaleReceiver = receiver
|
|
654
|
+
reactContext.registerReceiver(receiver, IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED))
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
@ReactMethod
|
|
658
|
+
fun stopFontScaleListener() {
|
|
659
|
+
fontScaleReceiver?.let { try { reactContext.unregisterReceiver(it) } catch (_: Exception) {} }
|
|
660
|
+
fontScaleReceiver = null
|
|
661
|
+
}
|
|
662
|
+
|
|
506
663
|
// ── Cleanup ───────────────────────────────────
|
|
507
664
|
override fun onCatalystInstanceDestroy() {
|
|
508
665
|
stopBrightnessListener()
|
|
509
666
|
stopVolumeListener()
|
|
510
667
|
stopSystemScreencastListener()
|
|
668
|
+
stopNetworkListener()
|
|
669
|
+
stopFontScaleListener()
|
|
511
670
|
}
|
|
512
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
|
// ─────────────────────────────────────────────
|