瀏覽代碼

Merge pull request #171 from tkskto/fix/viewshot-01

add null check
Gaëtan Renaudeau 6 年之前
父節點
當前提交
6953261450
No account linked to committer's email address
共有 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 查看文件

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