|
@@ -1,11 +1,14 @@
|
1
|
1
|
package fr.greweb.reactnativeviewshot;
|
2
|
2
|
|
3
|
3
|
import javax.annotation.Nullable;
|
|
4
|
+
|
|
5
|
+import android.app.Activity;
|
4
|
6
|
import android.graphics.Bitmap;
|
5
|
7
|
import android.graphics.Canvas;
|
6
|
8
|
import android.net.Uri;
|
7
|
9
|
import android.util.Base64;
|
8
|
10
|
import android.view.View;
|
|
11
|
+import android.widget.ScrollView;
|
9
|
12
|
|
10
|
13
|
import com.facebook.react.bridge.Promise;
|
11
|
14
|
import com.facebook.react.uimanager.NativeViewHierarchyManager;
|
|
@@ -33,6 +36,7 @@ public class ViewShot implements UIBlock {
|
33
|
36
|
private File output;
|
34
|
37
|
private String result;
|
35
|
38
|
private Promise promise;
|
|
39
|
+ private Boolean snapshotContentContainer;
|
36
|
40
|
|
37
|
41
|
public ViewShot(
|
38
|
42
|
int tag,
|
|
@@ -43,6 +47,7 @@ public class ViewShot implements UIBlock {
|
43
|
47
|
@Nullable Integer height,
|
44
|
48
|
File output,
|
45
|
49
|
String result,
|
|
50
|
+ Boolean snapshotContentContainer,
|
46
|
51
|
Promise promise) {
|
47
|
52
|
this.tag = tag;
|
48
|
53
|
this.extension = extension;
|
|
@@ -52,6 +57,7 @@ public class ViewShot implements UIBlock {
|
52
|
57
|
this.height = height;
|
53
|
58
|
this.output = output;
|
54
|
59
|
this.result = result;
|
|
60
|
+ this.snapshotContentContainer = snapshotContentContainer;
|
55
|
61
|
this.promise = promise;
|
56
|
62
|
}
|
57
|
63
|
|
|
@@ -112,10 +118,20 @@ public class ViewShot implements UIBlock {
|
112
|
118
|
private void captureView (View view, OutputStream os) {
|
113
|
119
|
int w = view.getWidth();
|
114
|
120
|
int h = view.getHeight();
|
|
121
|
+
|
115
|
122
|
if (w <= 0 || h <= 0) {
|
116
|
123
|
throw new RuntimeException("Impossible to snapshot the view: view is invalid");
|
117
|
124
|
}
|
118
|
|
- Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
|
|
125
|
+
|
|
126
|
+ //evaluate real height
|
|
127
|
+ if (this.snapshotContentContainer){
|
|
128
|
+ h=0;
|
|
129
|
+ ScrollView scrollView = (ScrollView)view;
|
|
130
|
+ for (int i = 0; i < scrollView.getChildCount(); i++) {
|
|
131
|
+ h += scrollView.getChildAt(i).getHeight();
|
|
132
|
+ }
|
|
133
|
+ }
|
|
134
|
+ Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
|
119
|
135
|
Canvas c = new Canvas(bitmap);
|
120
|
136
|
view.draw(c);
|
121
|
137
|
|