rn-system-bar 3.2.3 → 3.2.5

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.
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
  // ─────────────────────────────────────────────
3
3
  // rn-system-bar · SystemBar.ts
4
- // Zero expo-navigation-bar dependency.
5
- // All APIs → native Kotlin / iOS Swift.
4
+ // All APIs → native Kotlin (Android) / Swift (iOS)
6
5
  // ─────────────────────────────────────────────
7
6
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.onAppCastChange = exports.getAppCastInfo = exports.disconnectAppCast = exports.connectAppCast = exports.stopAppCastScan = exports.startAppCastScan = exports.onScreencastChange = exports.getScreencastInfo = exports.onSystemScreencastChange = exports.getSystemScreencastInfo = 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;
7
+ exports.onScreencastChange = exports.getScreencastInfo = exports.onFontScaleChange = exports.getFontScaleInfo = exports.onSystemScreencastChange = exports.getSystemScreencastInfo = exports.haptic = exports.onBatteryChange = exports.getBatteryInfo = 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;
9
8
  const react_native_1 = require("react-native");
10
9
  const { SystemBar: Native } = react_native_1.NativeModules;
11
10
  const isAndroid = react_native_1.Platform.OS === "android";
@@ -24,33 +23,15 @@ const checkNative = (method) => {
24
23
  throw new Error(`[rn-system-bar] Native.${method} not found. Rebuild your project.`);
25
24
  };
26
25
  // ═══════════════════════════════════════════════
27
- // NAVIGATION BAR (Android — 100% native)
26
+ // NAVIGATION BAR (Android only)
28
27
  // ═══════════════════════════════════════════════
29
- /**
30
- * Set the navigation bar background colour.
31
- *
32
- * @param color
33
- * - Any hex string → solid colour e.g. `"#1a1a2e"`
34
- * - `"transparent"` → fully transparent (content draws behind bar)
35
- * - `"translucent"` → semi-transparent (system scrim over content)
36
- *
37
- * @example
38
- * setNavigationBarColor("#000000"); // solid black
39
- * setNavigationBarColor("transparent"); // glass / edge-to-edge
40
- * setNavigationBarColor("translucent"); // frosted glass
41
- */
42
28
  const setNavigationBarColor = (color) => {
43
29
  if (!androidOnly("setNavigationBarColor"))
44
30
  return;
45
31
  checkNative();
46
- Native.setNavigationBarColor(color); // Kotlin handles the special values
32
+ Native.setNavigationBarColor(color);
47
33
  };
48
34
  exports.setNavigationBarColor = setNavigationBarColor;
49
- /**
50
- * Hide or show the navigation bar.
51
- *
52
- * @param mode `"visible"` | `"hidden"`
53
- */
54
35
  const setNavigationBarVisibility = (mode) => {
55
36
  if (!androidOnly("setNavigationBarVisibility"))
56
37
  return;
@@ -80,16 +61,8 @@ const setNavigationBarBehavior = (behavior) => {
80
61
  };
81
62
  exports.setNavigationBarBehavior = setNavigationBarBehavior;
82
63
  // ═══════════════════════════════════════════════
83
- // STATUS BAR (native — no RN StatusBar)
64
+ // STATUS BAR
84
65
  // ═══════════════════════════════════════════════
85
- /**
86
- * Set the status bar background colour (Android only).
87
- *
88
- * @param color
89
- * - Any hex string → solid colour
90
- * - `"transparent"` → fully transparent
91
- * - `"translucent"` → semi-transparent
92
- */
93
66
  const setStatusBarColor = (color) => {
94
67
  if (!androidOnly("setStatusBarColor"))
95
68
  return;
@@ -121,7 +94,8 @@ const getBrightness = () => {
121
94
  };
122
95
  exports.getBrightness = getBrightness;
123
96
  /**
124
- * Subscribe to system brightness changes (polls every 500 ms on Android).
97
+ * Subscribe to system brightness changes.
98
+ * Android: polls every 500 ms. iOS: UIScreen brightness.
125
99
  * @returns unsubscribe function
126
100
  */
127
101
  const onBrightnessChange = (callback) => {
@@ -156,7 +130,7 @@ const setVolumeHUDVisible = (visible) => {
156
130
  };
157
131
  exports.setVolumeHUDVisible = setVolumeHUDVisible;
158
132
  /**
159
- * Subscribe to system volume changes (hardware buttons, other apps).
133
+ * Subscribe to system volume changes.
160
134
  * @returns unsubscribe function
161
135
  */
162
136
  const onVolumeChange = (callback) => {
@@ -201,12 +175,76 @@ const setOrientation = (mode) => {
201
175
  };
202
176
  exports.setOrientation = setOrientation;
203
177
  // ═══════════════════════════════════════════════
204
- // SYSTEM SCREENCAST (external display / HDMI / Miracast)
205
- // Reads DisplayManager — detects any externally mirrored display.
178
+ // NETWORK
179
+ // ═══════════════════════════════════════════════
180
+ /**
181
+ * One-shot snapshot of the current network state.
182
+ */
183
+ const getNetworkInfo = () => {
184
+ checkNative("getNetworkInfo");
185
+ return Native.getNetworkInfo();
186
+ };
187
+ exports.getNetworkInfo = getNetworkInfo;
188
+ /**
189
+ * Subscribe to network changes (connectivity, type).
190
+ * @returns unsubscribe function
191
+ */
192
+ const onNetworkChange = (callback) => {
193
+ checkNative();
194
+ const { DeviceEventEmitter } = require("react-native");
195
+ Native.startNetworkListener();
196
+ const sub = DeviceEventEmitter.addListener("SystemBar_NetworkChange", callback);
197
+ return () => {
198
+ sub.remove();
199
+ Native.stopNetworkListener();
200
+ };
201
+ };
202
+ exports.onNetworkChange = onNetworkChange;
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
+ // HAPTICS
231
+ // ═══════════════════════════════════════════════
232
+ /**
233
+ * Trigger a haptic feedback pattern.
234
+ * iOS: UIFeedbackGenerator. Android: Vibrator.
235
+ *
236
+ * @param pattern "light" | "medium" | "heavy" | "success" | "warning" | "error" | "selection"
237
+ */
238
+ const haptic = (pattern = "medium") => {
239
+ checkNative();
240
+ Native.haptic(pattern);
241
+ };
242
+ exports.haptic = haptic;
243
+ // ═══════════════════════════════════════════════
244
+ // SYSTEM SCREENCAST (external display / HDMI / Miracast / AirPlay)
206
245
  // ═══════════════════════════════════════════════
207
246
  /**
208
247
  * One-shot snapshot of system-level external display state.
209
- * Works on both Android (DisplayManager) and iOS (UIScreen.screens).
210
248
  */
211
249
  const getSystemScreencastInfo = () => {
212
250
  if (!Native || typeof Native.getSystemScreencastInfo !== "function") {
@@ -222,8 +260,7 @@ const getSystemScreencastInfo = () => {
222
260
  };
223
261
  exports.getSystemScreencastInfo = getSystemScreencastInfo;
224
262
  /**
225
- * Subscribe to system external-display changes.
226
- * Fires when an HDMI / Miracast / AirPlay display connects or disconnects.
263
+ * Subscribe to external-display connect / disconnect events.
227
264
  * @returns unsubscribe function
228
265
  */
229
266
  const onSystemScreencastChange = (callback) => {
@@ -237,109 +274,36 @@ const onSystemScreencastChange = (callback) => {
237
274
  };
238
275
  };
239
276
  exports.onSystemScreencastChange = onSystemScreencastChange;
240
- // ─────────────────────────────────────────────
241
- // Legacy aliases (backward compat)
242
- // ─────────────────────────────────────────────
243
- /** @deprecated Use getSystemScreencastInfo() */
244
- exports.getScreencastInfo = exports.getSystemScreencastInfo;
245
- /** @deprecated Use onSystemScreencastChange() */
246
- exports.onScreencastChange = exports.onSystemScreencastChange;
247
277
  // ═══════════════════════════════════════════════
248
- // APP-ONLY CAST (MediaRouter — Chromecast / TV)
249
- // Mirrors only this app's screen — NOT the whole system.
250
- // Flow: startAppCastScan() → onAppCastChange (devices arrive)
251
- // → connectAppCast(deviceId) → onAppCastChange (state = "connected")
252
- // → disconnectAppCast()
278
+ // FONT SCALE
253
279
  // ═══════════════════════════════════════════════
254
280
  /**
255
- * Start scanning for nearby castable devices (Chromecast, TV, etc.).
256
- * Listen for results via `onAppCastChange`.
257
- * Android: uses MediaRouter. iOS: no-op (AirPlay is system-only).
258
- */
259
- const startAppCastScan = () => {
260
- if (!androidOnly("startAppCastScan"))
261
- return;
262
- checkNative();
263
- Native.startAppCastScan();
264
- };
265
- exports.startAppCastScan = startAppCastScan;
266
- /**
267
- * Stop the device discovery scan.
268
- */
269
- const stopAppCastScan = () => {
270
- if (!androidOnly("stopAppCastScan"))
271
- return;
272
- checkNative();
273
- Native.stopAppCastScan();
274
- };
275
- exports.stopAppCastScan = stopAppCastScan;
276
- /**
277
- * Connect to a discovered device and begin casting this app's screen.
278
- * @param deviceId The `id` field from `AppCastDevice` (MediaRouter route ID).
279
- * @param pairingPin Optional PIN string if `requiresPairing` is true.
280
- */
281
- const connectAppCast = (deviceId, pairingPin) => {
282
- if (!androidOnly("connectAppCast"))
283
- return;
284
- checkNative();
285
- Native.connectAppCast(deviceId, pairingPin !== null && pairingPin !== void 0 ? pairingPin : null);
286
- };
287
- exports.connectAppCast = connectAppCast;
288
- /**
289
- * Disconnect the active in-app cast session.
281
+ * One-shot snapshot of the system font scale and screen density.
290
282
  */
291
- const disconnectAppCast = () => {
292
- if (!androidOnly("disconnectAppCast"))
293
- return;
294
- checkNative();
295
- Native.disconnectAppCast();
283
+ const getFontScaleInfo = () => {
284
+ checkNative("getFontScaleInfo");
285
+ return Native.getFontScaleInfo();
296
286
  };
297
- exports.disconnectAppCast = disconnectAppCast;
287
+ exports.getFontScaleInfo = getFontScaleInfo;
298
288
  /**
299
- * Get the current in-app cast snapshot (state + device list).
300
- */
301
- const getAppCastInfo = () => {
302
- if (!isAndroid) {
303
- return Promise.resolve({
304
- state: "idle",
305
- devices: [],
306
- connectedDevice: null,
307
- error: null,
308
- });
309
- }
310
- checkNative();
311
- return Native.getAppCastInfo();
312
- };
313
- exports.getAppCastInfo = getAppCastInfo;
314
- /**
315
- * Subscribe to in-app cast state changes.
316
- * Fires on: device discovered/lost, state changes (scanning → connecting → connected),
317
- * pairing requests, errors.
318
- *
319
- * @example
320
- * const unsub = onAppCastChange((info) => {
321
- * if (info.state === "connected") console.log("Casting to", info.connectedDevice?.name);
322
- * if (info.error) console.warn("Cast error:", info.error);
323
- * });
324
- *
289
+ * Subscribe to font scale / accessibility text size changes.
325
290
  * @returns unsubscribe function
326
291
  */
327
- const onAppCastChange = (callback) => {
328
- if (!isAndroid) {
329
- // iOS: immediately call with idle state, return no-op
330
- callback({
331
- state: "idle",
332
- devices: [],
333
- connectedDevice: null,
334
- error: null,
335
- });
336
- return () => { };
337
- }
292
+ const onFontScaleChange = (callback) => {
338
293
  checkNative();
339
294
  const { DeviceEventEmitter } = require("react-native");
340
- const sub = DeviceEventEmitter.addListener("SystemBar_AppCastChange", callback);
295
+ Native.startFontScaleListener();
296
+ const sub = DeviceEventEmitter.addListener("SystemBar_FontScaleChange", callback);
341
297
  return () => {
342
298
  sub.remove();
299
+ Native.stopFontScaleListener();
343
300
  };
344
301
  };
345
- exports.onAppCastChange = onAppCastChange;
302
+ exports.onFontScaleChange = onFontScaleChange;
303
+ // ─────────────────────────────────────────────
304
+ // Legacy aliases (backward compat)
305
+ // ─────────────────────────────────────────────
306
+ /** @deprecated Use getSystemScreencastInfo() */
307
+ exports.getScreencastInfo = exports.getSystemScreencastInfo;
308
+ /** @deprecated Use onSystemScreencastChange() */
309
+ exports.onScreencastChange = exports.onSystemScreencastChange;
@@ -5,33 +5,22 @@ export type NavigationBarVisibility = "visible" | "hidden";
5
5
  export type StatusBarStyle = "light" | "dark";
6
6
  /**
7
7
  * Navigation bar color value.
8
- *
9
- * - Any CSS hex string solid colour e.g. "#1a1a2e", "#000"
10
- * - `"transparent"` fully transparent (FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS +
11
- * transparent color; content draws behind bar)
12
- * - `"translucent"` → semi-transparent (FLAG_TRANSLUCENT_NAVIGATION)
8
+ * - Any hex string → solid colour e.g. "#1a1a2e"
9
+ * - `"transparent"`fully transparent
10
+ * - `"translucent"` semi-transparent
13
11
  */
14
12
  export type NavigationBarColorValue = string | "transparent" | "translucent";
15
13
  /**
16
14
  * Status bar background color value.
17
- *
18
- * - Any CSS hex string solid colour
19
- * - `"transparent"` fully transparent (draws behind content)
20
- * - `"translucent"` → semi-transparent
15
+ * - Any hex string → solid colour
16
+ * - `"transparent"`fully transparent
17
+ * - `"translucent"` semi-transparent
21
18
  */
22
19
  export type StatusBarColorValue = string | "transparent" | "translucent";
23
- /**
24
- * "system" → follow the OS Appearance (dark/light).
25
- * "dark" → force dark.
26
- * "light" → force light.
27
- */
28
20
  export type ThemeMode = "system" | "dark" | "light";
29
21
  export interface ThemeState {
30
- /** Resolved dark-mode flag. Always a concrete boolean. */
31
22
  isDark: boolean;
32
- /** Currently active override ("system" = following OS). */
33
23
  mode: ThemeMode;
34
- /** Set the override mode. Pass "system" to revert to OS. */
35
24
  setMode: (mode: ThemeMode) => void;
36
25
  }
37
26
  export type Orientation = "portrait" | "landscape" | "landscape-left" | "landscape-right" | "auto";
@@ -41,37 +30,48 @@ export interface ScreencastDisplay {
41
30
  name: string;
42
31
  isValid: boolean;
43
32
  }
44
- /** Result of getSystemScreencastInfo() — physical/HDMI/Miracast external display. */
45
33
  export interface SystemScreencastInfo {
46
34
  isCasting: boolean;
47
35
  displayName: string | null;
48
36
  displays: ScreencastDisplay[];
49
37
  }
50
- /** Connection state of the in-app cast session. */
51
- export type AppCastState = "idle" | "scanning" | "connecting" | "connected" | "disconnecting";
52
- /** A discovered castable device (TV, Chromecast, etc.). */
53
- export interface AppCastDevice {
54
- /** Unique route ID from MediaRouter. */
55
- id: string;
56
- /** Human-readable device name e.g. "Living Room TV". */
57
- name: string;
58
- /** Device description / model string (may be null). */
59
- description: string | null;
60
- /** Signal strength 0–100, or null if unavailable. */
61
- signalStrength: number | null;
62
- /** Whether a pairing/PIN step is required. */
63
- requiresPairing: boolean;
64
- }
65
- /** Full snapshot of in-app cast state. */
66
- export interface AppCastInfo {
67
- state: AppCastState;
68
- /** Devices found during the last scan. */
69
- devices: AppCastDevice[];
70
- /** The device currently connected (or connecting). */
71
- connectedDevice: AppCastDevice | null;
72
- /** Error message from the last failed operation. */
73
- error: string | null;
74
- }
75
38
  /** @deprecated Use SystemScreencastInfo */
76
39
  export interface ScreencastInfo extends SystemScreencastInfo {
77
40
  }
41
+ export type NetworkType = "wifi" | "cellular" | "none" | "unknown";
42
+ export interface NetworkInfo {
43
+ /** Connection medium. */
44
+ type: NetworkType;
45
+ /** True when the device has an active internet connection. */
46
+ isConnected: boolean;
47
+ /** True when airplane mode is on (Android only; always false on iOS). */
48
+ isAirplaneMode: boolean;
49
+ /** Wi-Fi SSID — Android only, requires location permission; null on iOS. */
50
+ ssid: string | null;
51
+ /** Cellular generation e.g. "4g" | "5g" — Android only; null on iOS. */
52
+ cellularGeneration: string | null;
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
+ export type HapticPattern = "light" | "medium" | "heavy" | "success" | "warning" | "error" | "selection";
64
+ export interface FontScaleInfo {
65
+ /**
66
+ * System font scale multiplier (1.0 = default).
67
+ * Android: from Configuration.fontScale.
68
+ * iOS: derived from UIContentSizeCategory.
69
+ */
70
+ fontScale: number;
71
+ /**
72
+ * Screen pixel density.
73
+ * Android: DisplayMetrics.density.
74
+ * iOS: UIScreen.main.scale.
75
+ */
76
+ density: number;
77
+ }
@@ -1,4 +1,4 @@
1
- import type { AppCastInfo, NavigationBarBehavior, NavigationBarButtonStyle, NavigationBarColorValue, NavigationBarStyle, NavigationBarVisibility, Orientation, ScreencastInfo, StatusBarColorValue, StatusBarStyle, SystemScreencastInfo, ThemeMode, ThemeState } from "./types";
1
+ import type { BatteryInfo, 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;
@@ -8,7 +8,6 @@ export interface SystemBarConfig {
8
8
  statusBarColor?: StatusBarColorValue;
9
9
  statusBarStyle?: StatusBarStyle;
10
10
  statusBarVisible?: boolean;
11
- statusBarAnimated?: boolean;
12
11
  keepScreenOn?: boolean;
13
12
  immersiveMode?: boolean;
14
13
  brightness?: number;
@@ -17,34 +16,36 @@ export interface SystemBarConfig {
17
16
  }
18
17
  export declare const useSystemBar: (config: SystemBarConfig) => void;
19
18
  export interface ThemedSystemBarConfig {
20
- /** Config applied when the resolved theme is DARK. */
21
19
  dark?: SystemBarConfig;
22
- /** Config applied when the resolved theme is LIGHT. */
23
20
  light?: SystemBarConfig;
24
- /**
25
- * Static config merged under both themes.
26
- * Theme-specific (dark/light) values always win.
27
- */
28
21
  base?: SystemBarConfig;
29
22
  }
30
23
  export declare const useThemeSystemBar: (config: ThemedSystemBarConfig) => ThemeState;
31
24
  export { useTheme } from "./useTheme";
32
25
  export type { ThemeMode, ThemeState };
33
26
  export declare const useSystemScreencast: () => SystemScreencastInfo;
34
- /** @deprecated Renamed to useSystemScreencast() */
27
+ /** @deprecated Use useSystemScreencast() */
35
28
  export declare const useScreencast: () => ScreencastInfo;
36
- export interface UseAppCastReturn extends AppCastInfo {
37
- /** Start scanning for nearby castable devices (TV, Chromecast, etc.). */
38
- scan: () => void;
39
- /** Stop the device discovery scan. */
40
- stopScan: () => void;
41
- /**
42
- * Connect to a discovered device and begin casting this app's screen.
43
- * @param deviceId The `id` field from `AppCastDevice`.
44
- * @param pairingPin Optional PIN string if `requiresPairing` is true.
45
- */
46
- connect: (deviceId: string, pairingPin?: string) => void;
47
- /** End the active cast session and return to idle. */
48
- disconnect: () => void;
49
- }
50
- export declare const useAppCast: () => UseAppCastReturn;
29
+ /**
30
+ * Subscribe to network state. Fires immediately with the current snapshot,
31
+ * then on every connectivity change.
32
+ *
33
+ * @example
34
+ * const { isConnected, type } = useNetwork();
35
+ */
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
+ /**
46
+ * Subscribe to system font scale changes (accessibility text size).
47
+ *
48
+ * @example
49
+ * const { fontScale, density } = useFontScale();
50
+ */
51
+ export declare const useFontScale: () => FontScaleInfo;