rn-system-bar 1.0.0

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.
@@ -0,0 +1,48 @@
1
+ buildscript {
2
+ ext {
3
+ kotlinVersion = "1.9.22"
4
+ }
5
+
6
+ repositories {
7
+ google()
8
+ mavenCentral()
9
+ }
10
+
11
+ dependencies {
12
+ classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
13
+ }
14
+ }
15
+
16
+ apply plugin: "com.android.library"
17
+ apply plugin: "org.jetbrains.kotlin.android"
18
+
19
+ android {
20
+ namespace "com.systemnavigationbar"
21
+
22
+ compileSdkVersion 34
23
+
24
+ defaultConfig {
25
+ minSdkVersion 21
26
+ targetSdkVersion 34
27
+ }
28
+
29
+ buildTypes {
30
+ release {
31
+ minifyEnabled false
32
+ }
33
+ }
34
+
35
+ lintOptions {
36
+ disable "GradleCompatible"
37
+ }
38
+ }
39
+
40
+ repositories {
41
+ google()
42
+ mavenCentral()
43
+ }
44
+
45
+ dependencies {
46
+ implementation "com.facebook.react:react-native:+"
47
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:1.9.22"
48
+ }
@@ -0,0 +1,2 @@
1
+ android.useAndroidX=true
2
+ kotlin.code.style=official
@@ -0,0 +1,4 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+ package="com.systemnavigationbar">
3
+
4
+ </manifest>
@@ -0,0 +1,137 @@
1
+ package com.systemnavigationbar
2
+
3
+ import android.app.Activity
4
+ import android.content.Context
5
+ import android.content.pm.ActivityInfo
6
+ import android.graphics.Color
7
+ import android.media.AudioManager
8
+ import android.view.View
9
+ import android.view.WindowManager
10
+ import com.facebook.react.bridge.*
11
+
12
+ class SystemNavigationBarModule(private val reactContext: ReactApplicationContext)
13
+ : ReactContextBaseJavaModule(reactContext) {
14
+
15
+ override fun getName(): String {
16
+ return "SystemNavigationBar"
17
+ }
18
+
19
+ private fun activity(): Activity? {
20
+ return currentActivity
21
+ }
22
+
23
+ @ReactMethod
24
+ fun setBackgroundColorAsync(color: String) {
25
+ val act = activity() ?: return
26
+
27
+ act.runOnUiThread {
28
+ val c = Color.parseColor(color)
29
+ act.window.navigationBarColor = c
30
+ act.window.statusBarColor = c
31
+ }
32
+ }
33
+
34
+ @ReactMethod
35
+ fun setVisibilityAsync(mode: String) {
36
+ val act = activity() ?: return
37
+
38
+ act.runOnUiThread {
39
+ if (mode == "hidden") {
40
+ act.window.decorView.systemUiVisibility =
41
+ View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
42
+ View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
43
+ } else {
44
+ act.window.decorView.systemUiVisibility =
45
+ View.SYSTEM_UI_FLAG_VISIBLE
46
+ }
47
+ }
48
+ }
49
+
50
+ @ReactMethod
51
+ fun setBrightness(level: Float) {
52
+ val act = activity() ?: return
53
+
54
+ act.runOnUiThread {
55
+ val lp = act.window.attributes
56
+ lp.screenBrightness = level
57
+ act.window.attributes = lp
58
+ }
59
+ }
60
+
61
+ @ReactMethod
62
+ fun getBrightness(promise: Promise) {
63
+ val act = activity() ?: return
64
+ promise.resolve(act.window.attributes.screenBrightness)
65
+ }
66
+
67
+ @ReactMethod
68
+ fun keepScreenOn(enable: Boolean) {
69
+ val act = activity() ?: return
70
+
71
+ act.runOnUiThread {
72
+ if (enable) {
73
+ act.window.addFlags(
74
+ WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
75
+ )
76
+ } else {
77
+ act.window.clearFlags(
78
+ WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
79
+ )
80
+ }
81
+ }
82
+ }
83
+
84
+ @ReactMethod
85
+ fun setOrientation(mode: String) {
86
+ val act = activity() ?: return
87
+
88
+ act.runOnUiThread {
89
+ when (mode) {
90
+ "portrait" ->
91
+ act.requestedOrientation =
92
+ ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
93
+
94
+ "landscape" ->
95
+ act.requestedOrientation =
96
+ ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
97
+
98
+ "auto" ->
99
+ act.requestedOrientation =
100
+ ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
101
+ }
102
+ }
103
+ }
104
+
105
+ @ReactMethod
106
+ fun setVolume(level: Float) {
107
+ val audioManager =
108
+ reactContext.getSystemService(Context.AUDIO_SERVICE)
109
+ as AudioManager
110
+
111
+ val max =
112
+ audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC)
113
+
114
+ val vol = (level * max).toInt()
115
+
116
+ audioManager.setStreamVolume(
117
+ AudioManager.STREAM_MUSIC,
118
+ vol,
119
+ 0
120
+ )
121
+ }
122
+
123
+ @ReactMethod
124
+ fun getVolume(promise: Promise) {
125
+ val audioManager =
126
+ reactContext.getSystemService(Context.AUDIO_SERVICE)
127
+ as AudioManager
128
+
129
+ val max =
130
+ audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC)
131
+
132
+ val current =
133
+ audioManager.getStreamVolume(AudioManager.STREAM_MUSIC)
134
+
135
+ promise.resolve(current.toFloat() / max)
136
+ }
137
+ }
@@ -0,0 +1,22 @@
1
+ package com.systemnavigationbar
2
+
3
+ import com.facebook.react.ReactPackage
4
+ import com.facebook.react.bridge.*
5
+ import com.facebook.react.uimanager.ViewManager
6
+
7
+ class SystemNavigationBarPackage : ReactPackage {
8
+
9
+ override fun createNativeModules(
10
+ reactContext: ReactApplicationContext
11
+ ): List<NativeModule> {
12
+
13
+ return listOf(SystemNavigationBarModule(reactContext))
14
+ }
15
+
16
+ override fun createViewManagers(
17
+ reactContext: ReactApplicationContext
18
+ ): List<ViewManager<*, *>> {
19
+
20
+ return emptyList()
21
+ }
22
+ }
package/index.ts ADDED
@@ -0,0 +1,25 @@
1
+ import { NativeModules } from "react-native";
2
+
3
+ const { SystemNavigationBar } = NativeModules;
4
+
5
+ export const setBackgroundColorAsync = (color: string) =>
6
+ SystemNavigationBar.setBackgroundColorAsync(color);
7
+
8
+ export const setVisibilityAsync = (mode: "visible" | "hidden") =>
9
+ SystemNavigationBar.setVisibilityAsync(mode);
10
+
11
+ export const setBrightness = (level: number) =>
12
+ SystemNavigationBar.setBrightness(level);
13
+
14
+ export const getBrightness = () => SystemNavigationBar.getBrightness();
15
+
16
+ export const setVolume = (level: number) =>
17
+ SystemNavigationBar.setVolume(level);
18
+
19
+ export const getVolume = () => SystemNavigationBar.getVolume();
20
+
21
+ export const keepScreenOn = (enable: boolean) =>
22
+ SystemNavigationBar.keepScreenOn(enable);
23
+
24
+ export const setOrientation = (mode: "portrait" | "landscape" | "auto") =>
25
+ SystemNavigationBar.setOrientation(mode);
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "rn-system-bar",
3
+ "version": "1.0.0",
4
+ "description": "React Native system navigation bar controller",
5
+ "main": "index.ts",
6
+ "types": "types.ts",
7
+ "react-native": "index.ts",
8
+ "keywords": [
9
+ "react-native",
10
+ "navigation-bar",
11
+ "status-bar",
12
+ "brightness",
13
+ "volume"
14
+ ],
15
+ "author": "Yadav Official",
16
+ "license": "MIT"
17
+ }
package/types.ts ADDED
@@ -0,0 +1,3 @@
1
+ export type NavigationBarVisibility = "visible" | "hidden";
2
+
3
+ export type Orientation = "portrait" | "landscape" | "auto";