Bladeren bron

Add adaptive navigation bar buttons color (#5860)

Co-authored-by: Guy Carmeli <guyca@users.noreply.github.com>
rverbytskyi 4 jaren geleden
bovenliggende
commit
65211775f6
1 gewijzigde bestanden met toevoegingen van 21 en 1 verwijderingen
  1. 21
    1
      lib/android/app/src/main/java/com/reactnativenavigation/presentation/Presenter.java

+ 21
- 1
lib/android/app/src/main/java/com/reactnativenavigation/presentation/Presenter.java Bestand weergeven

@@ -202,7 +202,27 @@ public class Presenter {
202 202
     private void setNavigationBarBackgroundColor(NavigationBarOptions navigationBar) {
203 203
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && navigationBar.backgroundColor.canApplyValue()) {
204 204
             int defaultColor = activity.getWindow().getNavigationBarColor();
205
-            activity.getWindow().setNavigationBarColor(navigationBar.backgroundColor.get(defaultColor));
205
+            int color = navigationBar.backgroundColor.get(defaultColor);
206
+            activity.getWindow().setNavigationBarColor(color);
207
+            setNavigationBarButtonsColor(color);
206 208
         }
207 209
     }
210
+
211
+    private void setNavigationBarButtonsColor(int color) {
212
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
213
+            View decorView = activity.getWindow().getDecorView();
214
+            int flags = decorView.getSystemUiVisibility();
215
+            if (isColorLight(color)) {
216
+                flags |= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
217
+            } else {
218
+                flags &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
219
+            }
220
+            decorView.setSystemUiVisibility(flags);
221
+        }
222
+    }
223
+
224
+    private boolean isColorLight(int color) {
225
+        double darkness = 1 - (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255;
226
+        return darkness < 0.5;
227
+    }
208 228
 }