rn-system-bar 3.1.4 → 3.1.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.
|
@@ -340,13 +340,41 @@ class SystemBarModule(
|
|
|
340
340
|
|
|
341
341
|
@ReactMethod
|
|
342
342
|
fun setOrientation(mode: String) {
|
|
343
|
+
// "auto" → always unspecified (follow system auto-rotate toggle unconditionally)
|
|
344
|
+
if (mode == "auto") {
|
|
345
|
+
activity()?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
|
|
346
|
+
return
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// For a specific orientation: check if the device's auto-rotate toggle is ON.
|
|
350
|
+
// auto-rotate ON → use sensor-based variant so the device can still rotate
|
|
351
|
+
// within the requested axis (portrait ↔ reverse-portrait, etc.)
|
|
352
|
+
// auto-rotate OFF → hard-lock to the exact orientation requested
|
|
353
|
+
val autoRotateOn = Settings.System.getInt(
|
|
354
|
+
reactContext.contentResolver,
|
|
355
|
+
Settings.System.ACCELEROMETER_ROTATION,
|
|
356
|
+
0 // default = locked (off)
|
|
357
|
+
) == 1
|
|
358
|
+
|
|
343
359
|
activity()?.requestedOrientation = when (mode) {
|
|
344
|
-
"portrait"
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
360
|
+
"portrait" ->
|
|
361
|
+
if (autoRotateOn) ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
|
|
362
|
+
else ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
|
363
|
+
|
|
364
|
+
"landscape" ->
|
|
365
|
+
if (autoRotateOn) ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
|
|
366
|
+
else ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
|
|
367
|
+
|
|
368
|
+
"landscape-left" ->
|
|
369
|
+
// Reverse landscape — no sensor variant; honour toggle by using full sensor landscape
|
|
370
|
+
if (autoRotateOn) ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
|
|
371
|
+
else ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
|
|
372
|
+
|
|
373
|
+
"landscape-right" ->
|
|
374
|
+
if (autoRotateOn) ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
|
|
375
|
+
else ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
|
|
376
|
+
|
|
377
|
+
else -> ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
|
|
350
378
|
}
|
|
351
379
|
}
|
|
352
380
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rn-system-bar",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.6",
|
|
4
4
|
"description": "Control Android & iOS system bars, brightness, volume, orientation and screen flags from React Native.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"react-native": "lib/index.js",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"specs/",
|
|
28
28
|
"android/",
|
|
29
29
|
"ios/",
|
|
30
|
+
"plugin/",
|
|
30
31
|
"rn-system-bar.podspec"
|
|
31
32
|
],
|
|
32
33
|
"peerDependencies": {
|
|
@@ -38,9 +39,15 @@
|
|
|
38
39
|
"npm:prepublish": "npm publish --access public",
|
|
39
40
|
"installing": "cd .. && npm install rn-system-bar@latest && cd rn-system-bar"
|
|
40
41
|
},
|
|
42
|
+
"expo": {
|
|
43
|
+
"plugins": [
|
|
44
|
+
"./plugin/withRnSystemBar"
|
|
45
|
+
]
|
|
46
|
+
},
|
|
41
47
|
"devDependencies": {
|
|
42
48
|
"@types/react": "^19.2.14",
|
|
43
49
|
"@types/react-native": "^0.72.8",
|
|
50
|
+
"rimraf": "^6.0.1",
|
|
44
51
|
"typescript": "^5.9.3"
|
|
45
52
|
}
|
|
46
53
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ─────────────────────────────────────────────
|
|
3
|
+
// rn-system-bar · Expo Config Plugin
|
|
4
|
+
// plugin/withRnSystemBar.js (compiled from withRnSystemBar.ts)
|
|
5
|
+
//
|
|
6
|
+
// Automatically wires the native module into
|
|
7
|
+
// an Expo-managed (EAS Build) project.
|
|
8
|
+
//
|
|
9
|
+
// What it does:
|
|
10
|
+
// Android → ensures WRITE_SETTINGS permission is
|
|
11
|
+
// declared in AndroidManifest.xml so
|
|
12
|
+
// setBrightness() works without crashing.
|
|
13
|
+
// iOS → no-op (Swift module is auto-linked).
|
|
14
|
+
// ─────────────────────────────────────────────
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
|
|
17
|
+
const config_plugins_1 = require("@expo/config-plugins");
|
|
18
|
+
|
|
19
|
+
const { getMainApplicationOrThrow } = config_plugins_1.AndroidConfig.Manifest;
|
|
20
|
+
|
|
21
|
+
// ── Permission tag we need ───────────────────
|
|
22
|
+
const WRITE_SETTINGS = "android.permission.WRITE_SETTINGS";
|
|
23
|
+
|
|
24
|
+
// ── withAndroidPermission ────────────────────
|
|
25
|
+
// Adds <uses-permission android:name="android.permission.WRITE_SETTINGS" />
|
|
26
|
+
// to AndroidManifest.xml if it is not already present.
|
|
27
|
+
const withRnSystemBarAndroid = (config) =>
|
|
28
|
+
(0, config_plugins_1.withAndroidManifest)(config, (mod) => {
|
|
29
|
+
const manifest = mod.modResults;
|
|
30
|
+
|
|
31
|
+
// Ensure the top-level <manifest> permissions array exists
|
|
32
|
+
if (!Array.isArray(manifest.manifest["uses-permission"])) {
|
|
33
|
+
manifest.manifest["uses-permission"] = [];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const permissions = manifest.manifest["uses-permission"];
|
|
37
|
+
|
|
38
|
+
const alreadyAdded = permissions.some(
|
|
39
|
+
(p) => p.$?.["android:name"] === WRITE_SETTINGS
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
if (!alreadyAdded) {
|
|
43
|
+
permissions.push({ $: { "android:name": WRITE_SETTINGS } });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return mod;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// ── Main plugin ──────────────────────────────
|
|
50
|
+
const withRnSystemBar = (config) => {
|
|
51
|
+
// Apply Android manifest modifications
|
|
52
|
+
config = withRnSystemBarAndroid(config);
|
|
53
|
+
// iOS: auto-linking handles everything — nothing to patch
|
|
54
|
+
return config;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// createRunOncePlugin ensures the plugin runs exactly once
|
|
58
|
+
// even if the user lists it multiple times in app.json.
|
|
59
|
+
exports.default = (0, config_plugins_1.createRunOncePlugin)(
|
|
60
|
+
withRnSystemBar,
|
|
61
|
+
"rn-system-bar", // plugin name (must match package name)
|
|
62
|
+
"3.1.5" // plugin version (keep in sync with package.json)
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
module.exports = exports.default;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────
|
|
2
|
+
// rn-system-bar · Expo Config Plugin
|
|
3
|
+
// plugin/withRnSystemBar.ts
|
|
4
|
+
//
|
|
5
|
+
// Automatically wires the native module into
|
|
6
|
+
// an Expo-managed (EAS Build) project.
|
|
7
|
+
//
|
|
8
|
+
// What it does:
|
|
9
|
+
// Android → ensures WRITE_SETTINGS permission is
|
|
10
|
+
// declared in AndroidManifest.xml so
|
|
11
|
+
// setBrightness() works without crashing.
|
|
12
|
+
// iOS → no-op (Swift module is auto-linked).
|
|
13
|
+
// ─────────────────────────────────────────────
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
AndroidConfig,
|
|
17
|
+
ConfigPlugin,
|
|
18
|
+
createRunOncePlugin,
|
|
19
|
+
withAndroidManifest,
|
|
20
|
+
} from "@expo/config-plugins";
|
|
21
|
+
|
|
22
|
+
const { getMainApplicationOrThrow } = AndroidConfig.Manifest;
|
|
23
|
+
|
|
24
|
+
// ── Permission tag we need ───────────────────
|
|
25
|
+
const WRITE_SETTINGS = "android.permission.WRITE_SETTINGS";
|
|
26
|
+
|
|
27
|
+
// ── withAndroidPermission ────────────────────
|
|
28
|
+
// Adds <uses-permission android:name="android.permission.WRITE_SETTINGS" />
|
|
29
|
+
// to AndroidManifest.xml if it is not already present.
|
|
30
|
+
const withRnSystemBarAndroid: ConfigPlugin = (config) =>
|
|
31
|
+
withAndroidManifest(config, (mod) => {
|
|
32
|
+
const manifest = mod.modResults;
|
|
33
|
+
|
|
34
|
+
// Ensure the top-level <manifest> permissions array exists
|
|
35
|
+
if (!Array.isArray(manifest.manifest["uses-permission"])) {
|
|
36
|
+
manifest.manifest["uses-permission"] = [];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const permissions = manifest.manifest["uses-permission"] as Array<{
|
|
40
|
+
$: { "android:name": string };
|
|
41
|
+
}>;
|
|
42
|
+
|
|
43
|
+
const alreadyAdded = permissions.some(
|
|
44
|
+
(p) => p.$?.["android:name"] === WRITE_SETTINGS,
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
if (!alreadyAdded) {
|
|
48
|
+
permissions.push({ $: { "android:name": WRITE_SETTINGS } });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return mod;
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// ── Main plugin ──────────────────────────────
|
|
55
|
+
const withRnSystemBar: ConfigPlugin = (config) => {
|
|
56
|
+
// Apply Android manifest modifications
|
|
57
|
+
config = withRnSystemBarAndroid(config);
|
|
58
|
+
// iOS: auto-linking handles everything — nothing to patch
|
|
59
|
+
return config;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// createRunOncePlugin ensures the plugin runs exactly once
|
|
63
|
+
// even if the user lists it multiple times in app.json.
|
|
64
|
+
export default createRunOncePlugin(
|
|
65
|
+
withRnSystemBar,
|
|
66
|
+
"rn-system-bar", // plugin name (must match package name)
|
|
67
|
+
"3.1.6", // plugin version (keep in sync with package.json)
|
|
68
|
+
);
|