Skip to content

Commit

Permalink
Open sourced <ImageEditor>, <ImageStore> for Android
Browse files Browse the repository at this point in the history
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 1d819e9
Show file tree
Hide file tree
Showing 7 changed files with 575 additions and 21 deletions.
33 changes: 17 additions & 16 deletions Examples/UIExplorer/ImageEditingExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions Examples/UIExplorer/UIExplorerList.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -49,6 +49,7 @@ var APIS = [
require('./ClipboardExample'),
require('./DatePickerAndroidExample'),
require('./GeolocationExample'),
require('./ImageEditingExample'),
require('./IntentAndroidExample.android'),
require('./LayoutEventsExample'),
require('./LayoutExample'),
Expand Down
2 changes: 1 addition & 1 deletion Examples/UIExplorer/UIExplorerList.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ var APIS = [
require('./CameraRollExample'),
require('./ClipboardExample'),
require('./GeolocationExample'),
require('./ImageEditingExample'),
require('./LayoutExample'),
require('./NetInfoExample'),
require('./PanResponderExample'),
Expand All @@ -82,7 +83,6 @@ var APIS = [
require('./TransformExample'),
require('./VibrationIOSExample'),
require('./XHRExample.ios'),
require('./ImageEditingExample'),
];

type Props = {
Expand Down
3 changes: 2 additions & 1 deletion Libraries/Image/ImageStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -80,4 +81,4 @@ class ImageStore {
}
}

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

0 comments on commit 1d819e9

Please sign in to comment.