|
1 | 1 | package com.nh.system.ui.flags;
|
2 | 2 |
|
| 3 | +import android.app.Activity; |
3 | 4 | import android.view.View;
|
4 | 5 |
|
| 6 | +import com.facebook.react.bridge.Callback; |
5 | 7 | import com.facebook.react.bridge.ReactApplicationContext;
|
6 | 8 | import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
| 9 | +import com.facebook.react.bridge.ReactMethod; |
| 10 | +import com.facebook.react.bridge.UiThreadUtil; |
7 | 11 | import com.facebook.react.common.MapBuilder;
|
8 | 12 |
|
9 | 13 | import java.util.Map;
|
@@ -33,4 +37,46 @@ public Map<String, Object> getConstants() {
|
33 | 37 |
|
34 | 38 | return constants;
|
35 | 39 | }
|
| 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 | + } |
36 | 82 | }
|
0 commit comments