|
8 | 8 | import com.facebook.react.bridge.ReactApplicationContext; |
9 | 9 | import com.facebook.react.bridge.ReactContextBaseJavaModule; |
10 | 10 | import com.facebook.react.bridge.ReactMethod; |
| 11 | +import com.facebook.react.bridge.UiThreadUtil; |
11 | 12 | import com.facebook.react.common.MapBuilder; |
12 | 13 |
|
13 | 14 | import java.util.Map; |
@@ -56,29 +57,44 @@ public Map<String, Object> getConstants() { |
56 | 57 |
|
57 | 58 | @ReactMethod |
58 | 59 | public void getSystemUiFlags(final Callback callback) { |
59 | | - final Activity currentActivity = SystemUiFlagsModule.this.getCurrentActivity(); |
60 | | - if (currentActivity != null) { |
61 | | - final int flags = currentActivity.getWindow().getDecorView().getSystemUiVisibility(); |
62 | | - callback.invoke(flags); |
63 | | - } |
| 60 | + UiThreadUtil.runOnUiThread(new Runnable() { |
| 61 | + @Override |
| 62 | + public void run() { |
| 63 | + final Activity currentActivity = SystemUiFlagsModule.this.getCurrentActivity(); |
| 64 | + if (currentActivity != null) { |
| 65 | + final int flags = currentActivity.getWindow().getDecorView().getSystemUiVisibility(); |
| 66 | + callback.invoke(flags); |
| 67 | + } |
| 68 | + } |
| 69 | + }); |
64 | 70 | } |
65 | 71 |
|
66 | 72 | @ReactMethod |
67 | 73 | public void setSystemUiFlags(final int flags) { |
68 | | - final Activity currentActivity = SystemUiFlagsModule.this.getCurrentActivity(); |
69 | | - if (currentActivity != null) { |
70 | | - currentActivity.getWindow().getDecorView().setSystemUiVisibility(flags); |
71 | | - } |
| 74 | + UiThreadUtil.runOnUiThread(new Runnable() { |
| 75 | + @Override |
| 76 | + public void run() { |
| 77 | + final Activity currentActivity = SystemUiFlagsModule.this.getCurrentActivity(); |
| 78 | + if (currentActivity != null) { |
| 79 | + currentActivity.getWindow().getDecorView().setSystemUiVisibility(flags); |
| 80 | + } |
| 81 | + } |
| 82 | + }); |
72 | 83 | } |
73 | 84 |
|
74 | 85 | @ReactMethod |
75 | 86 | public void updateSystemUiFlags(final int flags) { |
76 | | - final Activity currentActivity = SystemUiFlagsModule.this.getCurrentActivity(); |
77 | | - if (currentActivity != null) { |
78 | | - final int currentFlags = currentActivity.getWindow().getDecorView().getSystemUiVisibility(); |
79 | | - final int newFlags = currentFlags | flags; |
80 | | - currentActivity.getWindow().getDecorView().setSystemUiVisibility(newFlags); |
81 | | - } |
| 87 | + UiThreadUtil.runOnUiThread(new Runnable() { |
| 88 | + @Override |
| 89 | + public void run() { |
| 90 | + final Activity currentActivity = SystemUiFlagsModule.this.getCurrentActivity(); |
| 91 | + if (currentActivity != null) { |
| 92 | + final int currentFlags = currentActivity.getWindow().getDecorView().getSystemUiVisibility(); |
| 93 | + final int newFlags = currentFlags | flags; |
| 94 | + currentActivity.getWindow().getDecorView().setSystemUiVisibility(newFlags); |
| 95 | + } |
| 96 | + } |
| 97 | + }); |
82 | 98 | } |
83 | 99 |
|
84 | 100 | } |
0 commit comments