Skip to content
Permalink
Browse files

Open sourced <ImageEditor>, <ImageStore> for Android

Reviewed By: mkonicek

Differential Revision: D2869751

fb-gh-sync-id: 862c266601dd83ca3bf9c9bcbf107f7b17b8bdfd
  • Loading branch information...
bestander authored and facebook-github-bot-5 committed Jan 27, 2016
1 parent b84f5fb commit 1d819e9503e69737733c3a0890ae272597527083
@@ -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,
@@ -25,12 +25,12 @@ var UIExplorerListBase = require('./UIExplorerListBase');
var COMPONENTS = [
require('./ImageExample'),
require('./ListViewExample'),
require('./PickerAndroidExample'),
require('./ProgressBarAndroidExample'),
require('./PullToRefreshViewAndroidExample.android'),
require('./RefreshControlExample'),
require('./ScrollViewSimpleExample'),
require('./SwitchExample'),
require('./RefreshControlExample'),
require('./PickerAndroidExample'),
require('./PullToRefreshViewAndroidExample.android'),
require('./TextExample.android'),
require('./TextInputExample.android'),
require('./ToolbarAndroidExample'),
@@ -49,6 +49,7 @@ var APIS = [
require('./ClipboardExample'),
require('./DatePickerAndroidExample'),
require('./GeolocationExample'),
require('./ImageEditingExample'),
require('./IntentAndroidExample.android'),
require('./LayoutEventsExample'),
require('./LayoutExample'),
@@ -71,6 +71,7 @@ var APIS = [
require('./CameraRollExample'),
require('./ClipboardExample'),
require('./GeolocationExample'),
require('./ImageEditingExample'),
require('./LayoutExample'),
require('./NetInfoExample'),
require('./PanResponderExample'),
@@ -82,7 +83,6 @@ var APIS = [
require('./TransformExample'),
require('./VibrationIOSExample'),
require('./XHRExample.ios'),
require('./ImageEditingExample'),
];

type Props = {
@@ -51,6 +51,7 @@ class ImageStore {
* Note that it is very inefficient to transfer large quantities of binary
* data between JS and native code, so you should avoid calling this more
* than necessary.
* @platform ios
*/
static addImageFromBase64(
base64ImageData: string,
@@ -80,4 +81,4 @@ class ImageStore {
}
}

module.exports = ImageStore;
module.exports = ImageStore;

0 comments on commit 1d819e9

Please sign in to comment.
You can’t perform that action at this time.