Skip to content

Commit 9274a8b

Browse files
authored
Merge pull request #231 from catnuxer/rn.0.60.3
fixed Testable RN 0.60.3
2 parents ec23260 + 1fe5b4c commit 9274a8b

File tree

6 files changed

+131
-12
lines changed

6 files changed

+131
-12
lines changed

android/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ buildscript {
1111
jcenter()
1212
}
1313
dependencies {
14-
classpath 'com.android.tools.build:gradle:2.3.0'
14+
classpath 'com.android.tools.build:gradle:3.4.1'
1515
}
1616
}
1717
}
1818

1919
apply plugin: 'com.android.library'
2020

2121
android {
22-
compileSdkVersion safeExtGet('compileSdkVersion', 27)
22+
compileSdkVersion safeExtGet('compileSdkVersion', 28)
2323
buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3')
2424

2525
defaultConfig {
2626
minSdkVersion safeExtGet('minSdkVersion', 16)
27-
targetSdkVersion safeExtGet('targetSdkVersion', 27)
27+
targetSdkVersion safeExtGet('targetSdkVersion', 28)
2828

2929
versionCode 1
3030
versionName "1.0"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import android.content.res.Resources;
66
import android.graphics.Matrix;
77
import android.os.Build;
8-
import android.support.annotation.NonNull;
9-
import android.support.v4.util.Pair;
8+
import androidx.annotation.NonNull;
9+
import androidx.core.util.Pair;
1010
import android.util.Log;
1111
import android.view.View;
1212
import android.view.ViewGroup;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import android.content.Context;
66
import android.net.Uri;
77
import android.os.AsyncTask;
8-
import android.support.annotation.NonNull;
8+
import androidx.annotation.NonNull;
99
import android.util.DisplayMetrics;
1010
import android.util.Log;
1111

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import android.graphics.Paint;
99
import android.graphics.Point;
1010
import android.net.Uri;
11-
import android.support.annotation.IntDef;
12-
import android.support.annotation.NonNull;
13-
import android.support.annotation.StringDef;
11+
import androidx.annotation.IntDef;
12+
import androidx.annotation.NonNull;
13+
import androidx.annotation.StringDef;
1414
import android.util.Base64;
1515
import android.util.Log;
1616
import android.view.TextureView;

example/Viewshoot.js

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/**
2+
* Sample How To Screenshot Screen inside of ScrollView
3+
* The original github from
4+
* https://github.com/gre/react-native-view-shot
5+
*/
6+
import React, {Component} from 'react';
7+
import {ScrollView, StyleSheet, Text, View, Button, Image, } from 'react-native';
8+
9+
import ViewShot from "react-native-view-shot";
10+
11+
export default class App extends Component {
12+
constructor(props) {
13+
super(props)
14+
this.state={
15+
error: null,
16+
res: null,
17+
options: {
18+
format: "jpg",
19+
quality: 0.9
20+
}
21+
}
22+
}
23+
24+
renderContent()
25+
{
26+
const data = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23];
27+
return data.map((item,index) => {
28+
return (
29+
<View style={styles.item} key={index}>
30+
<Text>{item}</Text>
31+
</View>
32+
);
33+
})
34+
}
35+
36+
renderResultSnapshot()
37+
{
38+
if(this.state.res!==null)
39+
{
40+
console.log('Result on return snapshot: ', this.state.res);
41+
return(
42+
<Image
43+
fadeDuration={0}
44+
resizeMode="contain"
45+
style={styles.previewImage}
46+
source={this.state.res}
47+
/>
48+
);
49+
}
50+
51+
return;
52+
}
53+
54+
55+
56+
renderShootButton(){
57+
return(
58+
<Button
59+
onPress={ async () => await this.captureViewShoot()}
60+
title="Shoot Me"
61+
color="#841584"
62+
/>
63+
)
64+
}
65+
66+
captureViewShoot()
67+
{
68+
this.refs.full.capture().then(uri => {
69+
console.log("do something with ", uri);
70+
this.setState({res: {uri: uri}})
71+
});
72+
}
73+
74+
renderViewShot()
75+
{
76+
return(
77+
<ScrollView style={styles.container}>
78+
<ViewShot
79+
ref="full"
80+
options={{ format: this.state.options.format, quality: this.state.options.quality }}
81+
style={styles.container}
82+
>
83+
{this.renderResultSnapshot()}
84+
{this.renderContent()}
85+
{this.renderShootButton()}
86+
</ViewShot>
87+
</ScrollView>
88+
)
89+
}
90+
91+
render() {
92+
return this.renderViewShot();
93+
}
94+
}
95+
96+
const styles = StyleSheet.create({
97+
container: {
98+
flex: 1,
99+
backgroundColor: '#fff'
100+
},
101+
content: {
102+
padding: 10,
103+
backgroundColor: '#fff'
104+
},
105+
item: {
106+
height: 50,
107+
},
108+
previewImage: {
109+
width: 375,
110+
height: 300
111+
},
112+
});

src/index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ function checkCompatibleProps(props: Props) {
171171
export default class ViewShot extends Component<Props> {
172172
static captureRef = captureRef;
173173
static releaseCapture = releaseCapture;
174+
constructor(props) {
175+
super(props)
176+
this.state={}
177+
}
174178
root: ?View;
175179

176180
_raf: *;
@@ -249,10 +253,13 @@ export default class ViewShot extends Component<Props> {
249253
}
250254
}
251255

252-
componentWillReceiveProps(nextProps: Props) {
253-
if (nextProps.captureMode !== this.props.captureMode) {
254-
this.syncCaptureLoop(nextProps.captureMode);
256+
static getDerivedStateFromProps(props, state) {
257+
if(props.captureMode !== undefined) {
258+
if (nextProps.captureMode !== this.props.captureMode) {
259+
this.syncCaptureLoop(nextProps.captureMode);
260+
}
255261
}
262+
return null;
256263
}
257264

258265
componentDidUpdate() {

0 commit comments

Comments
 (0)