Skip to content

Commit 736c3a7

Browse files
committed
Fix setNavbarColo
1 parent 880fa08 commit 736c3a7

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

android/src/main/java/com/tksp/navbarstyle/RNNavbarStyleModule.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,20 @@ public String getName() {
2727

2828
@ReactMethod
2929
public void setNavbarColor(String color, Promise promise) {
30-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
31-
getCurrentActivity().getWindow().setNavigationBarColor(Color.parseColor(color));
32-
promise.resolve(true);
33-
} else {
34-
promise.reject(new Exception("Current android version(" + Build.VERSION.SDK_INT + ") does not support changing the navbar color."));
30+
try {
31+
UiThreadUtil.runOnUiThread(new Runnable() {
32+
@Override
33+
public void run() {
34+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
35+
getCurrentActivity().getWindow().setNavigationBarColor(Color.parseColor(color));
36+
promise.resolve(true);
37+
} else {
38+
promise.reject(new Exception("Current android version(" + Build.VERSION.SDK_INT + ") does not support changing the navbar color."));
39+
}
40+
}
41+
});
42+
} catch(Exception e) {
43+
promise.reject(e);
3544
}
3645
}
3746

0 commit comments

Comments
 (0)