Skip to content

Commit 1d819e9

Browse files
bestanderfacebook-github-bot-5
authored andcommitted
Open sourced <ImageEditor>, <ImageStore> for Android
Reviewed By: mkonicek Differential Revision: D2869751 fb-gh-sync-id: 862c266601dd83ca3bf9c9bcbf107f7b17b8bdfd
1 parent b84f5fb commit 1d819e9

7 files changed

Lines changed: 575 additions & 21 deletions

File tree

Examples/UIExplorer/ImageEditingExample.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,21 @@ class SquareImageCropper extends React.Component {
6767
this._fetchRandomPhoto();
6868
}
6969

70-
_fetchRandomPhoto() {
71-
CameraRoll.getPhotos(
72-
{first: PAGE_SIZE},
73-
(data) => {
74-
if (!this._isMounted) {
75-
return;
76-
}
77-
var edges = data.edges;
78-
var edge = edges[Math.floor(Math.random() * edges.length)];
79-
var randomPhoto = edge && edge.node && edge.node.image;
80-
if (randomPhoto) {
81-
this.setState({randomPhoto});
82-
}
83-
},
84-
(error) => undefined
85-
);
70+
async _fetchRandomPhoto() {
71+
try {
72+
const data = await CameraRoll.getPhotos({first: PAGE_SIZE});
73+
if (!this._isMounted) {
74+
return;
75+
}
76+
var edges = data.edges;
77+
var edge = edges[Math.floor(Math.random() * edges.length)];
78+
var randomPhoto = edge && edge.node && edge.node.image;
79+
if (randomPhoto) {
80+
this.setState({randomPhoto});
81+
}
82+
} catch (error) {
83+
console.warn("Can't get a photo from camera roll", error);
84+
}
8685
}
8786

8887
componentWillUnmount() {
@@ -209,6 +208,8 @@ class ImageCropper extends React.Component {
209208
height: this.props.size.height,
210209
};
211210
}
211+
// a quick hack for android because Android ScrollView does not have zoom feature
212+
this._scaledImageSize.width = 2 * this._scaledImageSize.width;
212213
this._contentOffset = {
213214
x: (this._scaledImageSize.width - this.props.size.width) / 2,
214215
y: (this._scaledImageSize.height - this.props.size.height) / 2,

Examples/UIExplorer/UIExplorerList.android.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ var UIExplorerListBase = require('./UIExplorerListBase');
2525
var COMPONENTS = [
2626
require('./ImageExample'),
2727
require('./ListViewExample'),
28+
require('./PickerAndroidExample'),
2829
require('./ProgressBarAndroidExample'),
30+
require('./PullToRefreshViewAndroidExample.android'),
31+
require('./RefreshControlExample'),
2932
require('./ScrollViewSimpleExample'),
3033
require('./SwitchExample'),
31-
require('./RefreshControlExample'),
32-
require('./PickerAndroidExample'),
33-
require('./PullToRefreshViewAndroidExample.android'),
3434
require('./TextExample.android'),
3535
require('./TextInputExample.android'),
3636
require('./ToolbarAndroidExample'),
@@ -49,6 +49,7 @@ var APIS = [
4949
require('./ClipboardExample'),
5050
require('./DatePickerAndroidExample'),
5151
require('./GeolocationExample'),
52+
require('./ImageEditingExample'),
5253
require('./IntentAndroidExample.android'),
5354
require('./LayoutEventsExample'),
5455
require('./LayoutExample'),

Examples/UIExplorer/UIExplorerList.ios.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ var APIS = [
7171
require('./CameraRollExample'),
7272
require('./ClipboardExample'),
7373
require('./GeolocationExample'),
74+
require('./ImageEditingExample'),
7475
require('./LayoutExample'),
7576
require('./NetInfoExample'),
7677
require('./PanResponderExample'),
@@ -82,7 +83,6 @@ var APIS = [
8283
require('./TransformExample'),
8384
require('./VibrationIOSExample'),
8485
require('./XHRExample.ios'),
85-
require('./ImageEditingExample'),
8686
];
8787

8888
type Props = {

Libraries/Image/ImageStore.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class ImageStore {
5151
* Note that it is very inefficient to transfer large quantities of binary
5252
* data between JS and native code, so you should avoid calling this more
5353
* than necessary.
54+
* @platform ios
5455
*/
5556
static addImageFromBase64(
5657
base64ImageData: string,
@@ -80,4 +81,4 @@ class ImageStore {
8081
}
8182
}
8283

83-
module.exports = ImageStore;
84+
module.exports = ImageStore;

0 commit comments

Comments
 (0)