Skip to content

fix: makes example image specific #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 10 additions & 22 deletions example/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import {
} from 'react-native';
import ImageEditor from '@react-native-community/image-editor';

const DEFAULT_IMAGE_HEIGHT = 600;
const DEFAULT_IMAGE_WIDTH = 1000;
const DEFAULT_IMAGE_HEIGHT = 720;
const DEFAULT_IMAGE_WIDTH = 1080;

type ImageOffset = {|
x: number,
Expand Down Expand Up @@ -55,27 +55,17 @@ export default class SquareImageCropper extends React.Component<
super(props);
this._isMounted = true;
this.state = {
randomPhoto: null,
photo: {
uri: `https://source.unsplash.com/2Ts5HnA67k8/${DEFAULT_IMAGE_WIDTH}x${DEFAULT_IMAGE_HEIGHT}`,
height: DEFAULT_IMAGE_HEIGHT,
width: DEFAULT_IMAGE_WIDTH,
},
measuredSize: null,
croppedImageURI: null,
cropError: null,
};
}

async _fetchRandomPhoto() {
this.setState({
randomPhoto: {
uri: `http://placeimg.com/${DEFAULT_IMAGE_WIDTH}/${DEFAULT_IMAGE_HEIGHT}/tech?${new Date().getTime()}`,
height: DEFAULT_IMAGE_HEIGHT,
width: DEFAULT_IMAGE_WIDTH,
},
});
}

componentDidMount() {
this._fetchRandomPhoto();
}

render() {
if (!this.state.measuredSize) {
return (
Expand All @@ -101,7 +91,7 @@ export default class SquareImageCropper extends React.Component<
}

_renderImageCropper() {
if (!this.state.randomPhoto) {
if (!this.state.photo) {
return <View style={styles.container} />;
}
let error = null;
Expand All @@ -114,7 +104,7 @@ export default class SquareImageCropper extends React.Component<
Drag the image within the square to crop:
</Text>
<ImageCropper
image={this.state.randomPhoto}
image={this.state.photo}
size={this.state.measuredSize}
style={[styles.imageCropper, this.state.measuredSize]}
onTransformDataChange={data => (this._transformData = data)}
Expand Down Expand Up @@ -153,7 +143,7 @@ export default class SquareImageCropper extends React.Component<
async _crop() {
try {
const croppedImageURI = await ImageEditor.cropImage(
this.state.randomPhoto.uri,
this.state.photo.uri,
this._transformData,
);

Expand All @@ -167,11 +157,9 @@ export default class SquareImageCropper extends React.Component<

_reset() {
this.setState({
randomPhoto: null,
croppedImageURI: null,
cropError: null,
});
this._fetchRandomPhoto();
}
}

Expand Down