浏览代码

add null check

takeshi kato 6 年前
父节点
当前提交
cf16f2389e
共有 1 个文件被更改,包括 12 次插入10 次删除
  1. 12
    10
      android/src/main/java/fr/greweb/reactnativeviewshot/ViewShot.java

+ 12
- 10
android/src/main/java/fr/greweb/reactnativeviewshot/ViewShot.java 查看文件

@@ -180,18 +180,20 @@ public class ViewShot implements UIBlock {
180 180
             if(child instanceof TextureView) {
181 181
                 ((TextureView) child).setOpaque(false);
182 182
                 childBitmapBuffer = ((TextureView) child).getBitmap(child.getWidth(), child.getHeight());
183
-                int left = child.getLeft();
184
-                int top = child.getTop();
185
-                View parentElem = (View)child.getParent();
186
-                while (parentElem != null) {
187
-                    if (parentElem == view) {
188
-                        break;
183
+                if (childBitmapBuffer != null) {
184
+                    int left = child.getLeft();
185
+                    int top = child.getTop();
186
+                    View parentElem = (View)child.getParent();
187
+                    while (parentElem != null) {
188
+                        if (parentElem == view) {
189
+                            break;
190
+                        }
191
+                        left += parentElem.getLeft();
192
+                        top += parentElem.getTop();
193
+                        parentElem = (View)parentElem.getParent();
189 194
                     }
190
-                    left += parentElem.getLeft();
191
-                    top += parentElem.getTop();
192
-                    parentElem = (View)parentElem.getParent();
195
+                    c.drawBitmap(childBitmapBuffer, left + child.getPaddingLeft(), top + child.getPaddingTop(), null);
193 196
                 }
194
-                c.drawBitmap(childBitmapBuffer, left + child.getPaddingLeft(),  top + child.getPaddingTop(), null);
195 197
             }
196 198
         }
197 199