[tests][android] add RNPromiseTest native module
This commit is contained in:
parent
e1162b7f30
commit
e41d90a5a8
117
tests/android/app/src/main/java/com/testing/RNPromiseTest.java
Normal file
117
tests/android/app/src/main/java/com/testing/RNPromiseTest.java
Normal file
@ -0,0 +1,117 @@
|
||||
package com.testing;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.facebook.react.bridge.Arguments;
|
||||
import com.facebook.react.bridge.Promise;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
|
||||
public class RNPromiseTest extends ReactContextBaseJavaModule {
|
||||
private static final String TAG = "RNPromiseTest";
|
||||
|
||||
RNPromiseTest(ReactApplicationContext reactContext) {
|
||||
super(reactContext);
|
||||
Log.d(TAG, "New instance");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
// void resolve(@Nullable Object value);
|
||||
@ReactMethod
|
||||
public void resolveWithValue(String value, Promise promise) {
|
||||
promise.resolve(value);
|
||||
}
|
||||
|
||||
// void reject(String code, String message);
|
||||
@ReactMethod
|
||||
public void rejectWithCodeAndMessage(String code, String message, Promise promise) {
|
||||
promise.reject(code, message);
|
||||
}
|
||||
|
||||
// void reject(String code, Throwable throwable);
|
||||
@ReactMethod
|
||||
public void rejectWithCodeAndThrowable(String code, String errorMessage, Promise promise) {
|
||||
promise.reject(code, new Exception(errorMessage));
|
||||
}
|
||||
|
||||
// void reject(String code, String message, Throwable throwable);
|
||||
@ReactMethod
|
||||
public void rejectWithCodeMessageAndThrowable(
|
||||
String code,
|
||||
String message,
|
||||
String errorMessage,
|
||||
Promise promise
|
||||
) {
|
||||
promise.reject(code, message, new Exception(errorMessage));
|
||||
}
|
||||
|
||||
// void reject(Throwable throwable);
|
||||
@ReactMethod
|
||||
public void rejectWithThrowable(String errorMessage, Promise promise) {
|
||||
promise.reject(new Exception(errorMessage));
|
||||
}
|
||||
|
||||
/* ---------------------------
|
||||
* With userInfo WritableMap
|
||||
* --------------------------- */
|
||||
|
||||
// void reject(Throwable throwable, WritableMap userInfo);
|
||||
@ReactMethod
|
||||
public void rejectWithThrowableAndMap(String errorMessage, ReadableMap map, Promise promise) {
|
||||
promise.reject(new Exception(errorMessage), Arguments.makeNativeMap(map.toHashMap()));
|
||||
}
|
||||
|
||||
// void reject(String code, @Nonnull WritableMap userInfo);
|
||||
@ReactMethod
|
||||
public void rejectWithCodeAndMap(String code, ReadableMap map, Promise promise) {
|
||||
promise.reject(code, Arguments.makeNativeMap(map.toHashMap()));
|
||||
}
|
||||
|
||||
// void reject(String code, Throwable throwable, WritableMap userInfo);
|
||||
@ReactMethod
|
||||
public void rejectWithCodeThrowableAndMap(
|
||||
String code,
|
||||
String errorMessage,
|
||||
ReadableMap map,
|
||||
Promise promise
|
||||
) {
|
||||
promise.reject(code, new Exception(errorMessage), Arguments.makeNativeMap(map.toHashMap()));
|
||||
}
|
||||
|
||||
// void reject(String code, String message, @Nonnull WritableMap userInfo);
|
||||
@ReactMethod
|
||||
public void rejectWithCodeMessageAndMap(
|
||||
String code,
|
||||
String message,
|
||||
ReadableMap map,
|
||||
Promise promise
|
||||
) {
|
||||
promise.reject(code, message, Arguments.makeNativeMap(map.toHashMap()));
|
||||
}
|
||||
|
||||
// void reject(String code, String message, Throwable throwable, WritableMap userInfo);
|
||||
@ReactMethod
|
||||
public void rejectWithCodeMessageThrowableAndMap(
|
||||
String code,
|
||||
String message,
|
||||
String errorMessage,
|
||||
ReadableMap map,
|
||||
Promise promise
|
||||
) {
|
||||
promise.reject(
|
||||
code,
|
||||
message,
|
||||
new Exception(errorMessage),
|
||||
Arguments.makeNativeMap(map.toHashMap())
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.testing;
|
||||
|
||||
import com.facebook.react.ReactPackage;
|
||||
import com.facebook.react.bridge.NativeModule;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.uimanager.UIManagerModule;
|
||||
import com.facebook.react.uimanager.ViewManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class RNPromiseTestPackage implements ReactPackage {
|
||||
public RNPromiseTestPackage() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param reactContext react application context that can be used to create modules
|
||||
* @return list of native modules to register with the newly created catalyst instance
|
||||
*/
|
||||
@Override
|
||||
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
|
||||
List<NativeModule> modules = new ArrayList<>();
|
||||
modules.add(new RNPromiseTest(reactContext));
|
||||
return modules;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param reactContext
|
||||
* @return a list of view managers that should be registered with {@link UIManagerModule}
|
||||
*/
|
||||
@Override
|
||||
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user