Skip to content

Commit 794b4bc

Browse files
authored
Merge pull request #153 from HenleyKuang/master
Fix psitioning of TextureView elements relative to target element
2 parents 6d3d09c + e9ad6aa commit 794b4bc

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

android/src/main/java/fr/greweb/reactnativeviewshot/ViewShot.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,18 @@ private void captureView (View view, OutputStream os) {
180180
if(child instanceof TextureView) {
181181
((TextureView) child).setOpaque(false);
182182
childBitmapBuffer = ((TextureView) child).getBitmap(child.getWidth(), child.getHeight());
183-
c.drawBitmap(childBitmapBuffer, child.getLeft() + ((ViewGroup)child.getParent()).getLeft() + child.getPaddingLeft(), child.getTop() + ((ViewGroup)child.getParent()).getTop() + child.getPaddingTop(), null);
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;
189+
}
190+
left += parentElem.getLeft();
191+
top += parentElem.getTop();
192+
parentElem = (View)parentElem.getParent();
193+
}
194+
c.drawBitmap(childBitmapBuffer, left + child.getPaddingLeft(), top + child.getPaddingTop(), null);
184195
}
185196
}
186197

0 commit comments

Comments
 (0)