mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-02-11 22:32:38 +08:00
Open sourced <ImageEditor>, <ImageStore> for Android
Reviewed By: mkonicek Differential Revision: D2869751 fb-gh-sync-id: 862c266601dd83ca3bf9c9bcbf107f7b17b8bdfd
This commit is contained in:
committed by
facebook-github-bot-5
parent
b84f5fb6c9
commit
1d819e9503
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user