Open sourced <ImageEditor>, <ImageStore> for Android

Reviewed By: mkonicek

Differential Revision: D2869751

fb-gh-sync-id: 862c266601dd83ca3bf9c9bcbf107f7b17b8bdfd
This commit is contained in:
Konstantin Raev
2016-01-27 10:49:31 -08:00
committed by facebook-github-bot-5
parent b84f5fb6c9
commit 1d819e9503
7 changed files with 575 additions and 21 deletions

View File

@@ -67,22 +67,21 @@ class SquareImageCropper extends React.Component {
this._fetchRandomPhoto();
}
_fetchRandomPhoto() {
CameraRoll.getPhotos(
{first: PAGE_SIZE},
(data) => {
if (!this._isMounted) {
return;
}
var edges = data.edges;
var edge = edges[Math.floor(Math.random() * edges.length)];
var randomPhoto = edge && edge.node && edge.node.image;
if (randomPhoto) {
this.setState({randomPhoto});
}
},
(error) => undefined
);
async _fetchRandomPhoto() {
try {
const data = await CameraRoll.getPhotos({first: PAGE_SIZE});
if (!this._isMounted) {
return;
}
var edges = data.edges;
var edge = edges[Math.floor(Math.random() * edges.length)];
var randomPhoto = edge && edge.node && edge.node.image;
if (randomPhoto) {
this.setState({randomPhoto});
}
} catch (error) {
console.warn("Can't get a photo from camera roll", error);
}
}
componentWillUnmount() {
@@ -209,6 +208,8 @@ class ImageCropper extends React.Component {
height: this.props.size.height,
};
}
// a quick hack for android because Android ScrollView does not have zoom feature
this._scaledImageSize.width = 2 * this._scaledImageSize.width;
this._contentOffset = {
x: (this._scaledImageSize.width - this.props.size.width) / 2,
y: (this._scaledImageSize.height - this.props.size.height) / 2,