Selaa lähdekoodia

ViewUtils.runOnPreDraw

Daniel Zlotin 8 vuotta sitten
vanhempi
commit
e5786aedac

+ 21
- 0
android/app/src/main/java/com/reactnativenavigation/utils/ViewUtils.java Näytä tiedosto

@@ -0,0 +1,21 @@
1
+package com.reactnativenavigation.utils;
2
+
3
+import android.view.View;
4
+import android.view.ViewTreeObserver;
5
+
6
+public class ViewUtils {
7
+    public static void runOnPreDraw(final View view, final Runnable task) {
8
+        view.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
9
+            @Override
10
+            public boolean onPreDraw() {
11
+                if (!view.getViewTreeObserver().isAlive()) {
12
+                    return true;
13
+                }
14
+                view.getViewTreeObserver().removeOnPreDrawListener(this);
15
+                task.run();
16
+                return true;
17
+            }
18
+        });
19
+    }
20
+}
21
+