Skip to content

Commit be71e8b

Browse files
committed
change ui flags on UI thread
1 parent 2257b1c commit be71e8b

1 file changed

Lines changed: 31 additions & 15 deletions

File tree

android/src/main/java/com/stellarscript/system/ui/flags/SystemUiFlagsModule.java

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.facebook.react.bridge.ReactApplicationContext;
99
import com.facebook.react.bridge.ReactContextBaseJavaModule;
1010
import com.facebook.react.bridge.ReactMethod;
11+
import com.facebook.react.bridge.UiThreadUtil;
1112
import com.facebook.react.common.MapBuilder;
1213

1314
import java.util.Map;
@@ -56,29 +57,44 @@ public Map<String, Object> getConstants() {
5657

5758
@ReactMethod
5859
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+
});
6470
}
6571

6672
@ReactMethod
6773
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+
});
7283
}
7384

7485
@ReactMethod
7586
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+
});
8298
}
8399

84100
}

0 commit comments

Comments
 (0)