浏览代码

ViewUtils.runOnPreDraw

Daniel Zlotin 8 年前
父节点
当前提交
e5786aedac
共有 1 个文件被更改,包括 21 次插入0 次删除
  1. 21
    0
      android/app/src/main/java/com/reactnativenavigation/utils/ViewUtils.java

+ 21
- 0
android/app/src/main/java/com/reactnativenavigation/utils/ViewUtils.java 查看文件

@@ -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
+