88import android .graphics .Canvas ;
99import android .net .Uri ;
1010import android .util .Base64 ;
11+ import android .view .TextureView ;
1112import android .view .View ;
13+ import android .view .ViewGroup ;
1214import android .widget .ScrollView ;
1315
1416import com .facebook .react .bridge .Promise ;
2123import java .io .FileOutputStream ;
2224import java .io .IOException ;
2325import java .io .OutputStream ;
26+ import java .util .ArrayList ;
27+ import java .util .List ;
2428
2529/**
2630 * Snapshot utility class allow to screenshot a view.
@@ -116,6 +120,27 @@ else if ("data-uri".equals(result)) {
116120 }
117121 }
118122
123+ private List <View > getAllChildren (View v ) {
124+
125+ if (!(v instanceof ViewGroup )) {
126+ ArrayList <View > viewArrayList = new ArrayList <View >();
127+ viewArrayList .add (v );
128+ return viewArrayList ;
129+ }
130+
131+ ArrayList <View > result = new ArrayList <View >();
132+
133+ ViewGroup viewGroup = (ViewGroup ) v ;
134+ for (int i = 0 ; i < viewGroup .getChildCount (); i ++) {
135+
136+ View child = viewGroup .getChildAt (i );
137+
138+ //Do not add any parents, just add child elements
139+ result .addAll (getAllChildren (child ));
140+ }
141+ return result ;
142+ }
143+
119144 /**
120145 * Screenshot a view and return the captured bitmap.
121146 * @param view the view to capture
@@ -138,9 +163,21 @@ private void captureView (View view, OutputStream os) {
138163 }
139164 }
140165 Bitmap bitmap = Bitmap .createBitmap (w , h , Bitmap .Config .ARGB_8888 );
166+ Bitmap childBitmapBuffer ;
141167 Canvas c = new Canvas (bitmap );
142168 view .draw (c );
143169
170+ //after view is drawn, go through children
171+ List <View > childrenList = getAllChildren (view );
172+
173+ for (View child : childrenList ) {
174+ if (child instanceof TextureView ) {
175+ ((TextureView ) child ).setOpaque (false );
176+ childBitmapBuffer = ((TextureView ) child ).getBitmap (child .getWidth (), child .getHeight ());
177+ c .drawBitmap (childBitmapBuffer , child .getLeft () + ((ViewGroup )child .getParent ()).getLeft () + child .getPaddingLeft (), child .getTop () + ((ViewGroup )child .getParent ()).getTop () + child .getPaddingTop (), null );
178+ }
179+ }
180+
144181 if (width != null && height != null && (width != w || height != h )) {
145182 bitmap = Bitmap .createScaledBitmap (bitmap , width , height , true );
146183 }
0 commit comments