Skip to content

Commit

Permalink
Allow 'userInfo' for native promise.reject + add native error stack s…
Browse files Browse the repository at this point in the history
…upport (facebook#20940)

Summary:
As mentioned [here](react-native-community/releases#34 (comment)), Android is missing native Promise reject with a `userInfo` `WritableMap` support and also `nativeStack` support (which addresses `TODO(8850038)`). This PR adds Android support for both of these.

React Native on iOS ([here](https://github.com/facebook/react-native/blob/master/React/Base/RCTUtils.m#L433)) and Windows ([here](microsoft/react-native-windows#732)) already support this so this is a relatively minor addition to bring Android in line with the other platforms. (JS support is also [here](https://github.com/facebook/react-native/blob/master/Libraries/BatchedBridge/NativeModules.js#L145-L148))

Existing methods remain unchanged other than general cleanup of variable names (`e -> throwable`) and adding code comments/docs.

Additionally, the `ShareTestModule` implementation of Promise (SimplePromise) was updated to reflect these changes - other line changes in this file are from formatting in Android Studio - if this is an issue let me know.

 - Currently inconsistent with other platforms.
 - Blocking a couple of issues over at [invertase/react-native-firebase](https://github.com/invertase/react-native-firebase) - save for re-writing everything to Promise resolve only - which is no small change and isn't a great solution either.
Pull Request resolved: facebook#20940

Differential Revision: D13412527

Pulled By: cpojer

fbshipit-source-id: 2ca6c5f3db9ff2c2986b02edda80bc73432f66d3
  • Loading branch information
Salakar authored and facebook-github-bot committed Dec 11, 2018
1 parent 36c74b6 commit 2ef7bfc
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions NetInfoModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public String getName() {
@ReactMethod
public void getCurrentConnectivity(Promise promise) {
if (mNoNetworkPermission) {
promise.reject(ERROR_MISSING_PERMISSION, MISSING_PERMISSION_MESSAGE, null);
promise.reject(ERROR_MISSING_PERMISSION, MISSING_PERMISSION_MESSAGE);
return;
}
promise.resolve(createConnectivityEventMap());
Expand All @@ -112,7 +112,7 @@ public void getCurrentConnectivity(Promise promise) {
@ReactMethod
public void isConnectionMetered(Promise promise) {
if (mNoNetworkPermission) {
promise.reject(ERROR_MISSING_PERMISSION, MISSING_PERMISSION_MESSAGE, null);
promise.reject(ERROR_MISSING_PERMISSION, MISSING_PERMISSION_MESSAGE);
return;
}
promise.resolve(ConnectivityManagerCompat.isActiveNetworkMetered(mConnectivityManager));
Expand Down

0 comments on commit 2ef7bfc

Please sign in to comment.