mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
Make CameraRoll work with Promises
Summary: public This is the first module moving to the new model of working with Promises. We now warn on uses of callback version. At some point we will remove that. Reviewed By: davidaurelio Differential Revision: D2849811 fb-gh-sync-id: 8a31924cc2b438efc58f3ad22d5f27c273563472
This commit is contained in:
committed by
facebook-github-bot-2
parent
34d5fa2695
commit
9baff8f437
@@ -16,6 +16,7 @@
|
||||
let Systrace = require('Systrace');
|
||||
let ErrorUtils = require('ErrorUtils');
|
||||
let JSTimersExecution = require('JSTimersExecution');
|
||||
let Platform = require('Platform');
|
||||
|
||||
let invariant = require('invariant');
|
||||
let keyMirror = require('keyMirror');
|
||||
@@ -318,10 +319,21 @@ class MessageQueue {
|
||||
if (type === MethodTypes.remoteAsync) {
|
||||
fn = function(...args) {
|
||||
return new Promise((resolve, reject) => {
|
||||
self.__nativeCall(module, method, args, resolve, (errorData) => {
|
||||
var error = createErrorFromErrorData(errorData);
|
||||
reject(error);
|
||||
});
|
||||
self.__nativeCall(
|
||||
module,
|
||||
method,
|
||||
args,
|
||||
(data) => {
|
||||
// iOS always wraps the data in an Array regardless of what the
|
||||
// shape of the data so we strip it out
|
||||
// Android sends the data back properly
|
||||
// TODO: Remove this once iOS has support for Promises natively (t9774697)
|
||||
resolve(Platform.OS == 'ios' ? data[0] : data);
|
||||
},
|
||||
(errorData) => {
|
||||
var error = createErrorFromErrorData(errorData);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
} else {
|
||||
|
||||
@@ -12,11 +12,9 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var AndroidConstants = require('NativeModules').AndroidConstants;
|
||||
|
||||
var Platform = {
|
||||
OS: 'android',
|
||||
Version: AndroidConstants.Version,
|
||||
get Version() { return require('NativeModules').AndroidConstants.Version; },
|
||||
};
|
||||
|
||||
module.exports = Platform;
|
||||
|
||||
Reference in New Issue
Block a user