66import android .content .Intent ;
77import android .graphics .Bitmap ;
88import android .graphics .Canvas ;
9+ import android .graphics .Color ;
10+ import android .graphics .Matrix ;
11+ import android .graphics .Rect ;
912import android .net .Uri ;
1013import android .util .Base64 ;
14+ import android .util .Log ;
15+ import android .view .TextureView ;
1116import android .view .View ;
17+ import android .view .ViewGroup ;
18+ import android .widget .LinearLayout ;
1219import android .widget .ScrollView ;
1320
1421import com .facebook .react .bridge .Promise ;
2128import java .io .FileOutputStream ;
2229import java .io .IOException ;
2330import java .io .OutputStream ;
31+ import java .util .ArrayList ;
32+ import java .util .List ;
2433
2534/**
2635 * Snapshot utility class allow to screenshot a view.
@@ -116,6 +125,27 @@ else if ("data-uri".equals(result)) {
116125 }
117126 }
118127
128+ private List <View > getAllChildren (View v ) {
129+
130+ if (!(v instanceof ViewGroup )) {
131+ ArrayList <View > viewArrayList = new ArrayList <View >();
132+ viewArrayList .add (v );
133+ return viewArrayList ;
134+ }
135+
136+ ArrayList <View > result = new ArrayList <View >();
137+
138+ ViewGroup viewGroup = (ViewGroup ) v ;
139+ for (int i = 0 ; i < viewGroup .getChildCount (); i ++) {
140+
141+ View child = viewGroup .getChildAt (i );
142+
143+ //Do not add any parents, just add child elements
144+ result .addAll (getAllChildren (child ));
145+ }
146+ return result ;
147+ }
148+
119149 /**
120150 * Screenshot a view and return the captured bitmap.
121151 * @param view the view to capture
@@ -138,9 +168,21 @@ private void captureView (View view, OutputStream os) {
138168 }
139169 }
140170 Bitmap bitmap = Bitmap .createBitmap (w , h , Bitmap .Config .ARGB_8888 );
171+ Bitmap childBitmapBuffer ;
141172 Canvas c = new Canvas (bitmap );
142173 view .draw (c );
143174
175+ //after view is drawn, go through children
176+ List <View > childrenList = getAllChildren (view );
177+
178+ for (View child : childrenList ) {
179+ if (child instanceof TextureView ) {
180+ ((TextureView ) child ).setOpaque (false );
181+ childBitmapBuffer = ((TextureView ) child ).getBitmap (child .getWidth (), child .getHeight ());
182+ c .drawBitmap (childBitmapBuffer , child .getLeft () + ((ViewGroup )child .getParent ()).getLeft () + child .getPaddingLeft (), child .getTop () + ((ViewGroup )child .getParent ()).getTop () + child .getPaddingTop (), null );
183+ }
184+ }
185+
144186 if (width != null && height != null && (width != w || height != h )) {
145187 bitmap = Bitmap .createScaledBitmap (bitmap , width , height , true );
146188 }
0 commit comments