Skip to content

Commit d840c02

Browse files
committed
Methods for get, set & update the flags implemented
1 parent 5884f97 commit d840c02

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

android/src/main/java/com/nh/system/ui/flags/SystemUiFlags.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package com.nh.system.ui.flags;
22

3+
import android.app.Activity;
34
import android.view.View;
45

6+
import com.facebook.react.bridge.Callback;
57
import com.facebook.react.bridge.ReactApplicationContext;
68
import com.facebook.react.bridge.ReactContextBaseJavaModule;
9+
import com.facebook.react.bridge.ReactMethod;
10+
import com.facebook.react.bridge.UiThreadUtil;
711
import com.facebook.react.common.MapBuilder;
812

913
import java.util.Map;
@@ -33,4 +37,46 @@ public Map<String, Object> getConstants() {
3337

3438
return constants;
3539
}
40+
41+
@ReactMethod
42+
public void getCurrentSystemUiFlags(final Callback cb) {
43+
UiThreadUtil.runOnUiThread(new Runnable() {
44+
@Override
45+
public void run() {
46+
Activity currentActivity = getCurrentActivity();
47+
if (currentActivity != null) {
48+
int currentSystemUiFlags = currentActivity.getWindow().getDecorView().getSystemUiVisibility();
49+
cb.invoke(currentSystemUiFlags);
50+
}
51+
}
52+
});
53+
}
54+
55+
@ReactMethod
56+
public void setSystemUiFlags(final int systemUiFlags) {
57+
UiThreadUtil.runOnUiThread(new Runnable() {
58+
@Override
59+
public void run() {
60+
Activity currentActivity = getCurrentActivity();
61+
if (currentActivity != null) {
62+
currentActivity.getWindow().getDecorView().setSystemUiVisibility(systemUiFlags);
63+
}
64+
}
65+
});
66+
}
67+
68+
@ReactMethod
69+
public void updateSystemUiFlags(final int systemUiFlags) {
70+
UiThreadUtil.runOnUiThread(new Runnable() {
71+
@Override
72+
public void run() {
73+
Activity currentActivity = getCurrentActivity();
74+
if (currentActivity != null) {
75+
int currentSystemUiFlags = currentActivity.getWindow().getDecorView().getSystemUiVisibility();
76+
int newSystemUiFlags = currentSystemUiFlags | systemUiFlags;
77+
currentActivity.getWindow().getDecorView().setSystemUiVisibility(newSystemUiFlags);
78+
}
79+
}
80+
});
81+
}
3682
}

0 commit comments

Comments
 (0)