Merging cxxbridge and bridge packages

Reviewed By: javache

Differential Revision: D5027875

fbshipit-source-id: 47e081069d4219bdb29f63ce8a78c1f31a590da7
This commit is contained in:
Kathy Gray 2017-05-11 03:39:38 -07:00 committed by Facebook Github Bot
parent 31a0b8788f
commit 8b53a2b29b
44 changed files with 218 additions and 398 deletions

View File

@ -26,7 +26,6 @@ android_library(
react_native_target("java/com/facebook/react:react"),
react_native_target("java/com/facebook/react/bridge:bridge"),
react_native_target("java/com/facebook/react/common:common"),
react_native_target("java/com/facebook/react/cxxbridge:bridge"),
react_native_target("java/com/facebook/react/devsupport:interfaces"),
react_native_target("java/com/facebook/react/module/annotations:annotations"),
react_native_target("java/com/facebook/react/module/model:model"),

View File

@ -27,10 +27,10 @@ import com.facebook.react.bridge.NativeModuleCallExceptionHandler;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.WritableNativeMap;
import com.facebook.react.bridge.queue.ReactQueueConfigurationSpec;
import com.facebook.react.cxxbridge.CatalystInstanceImpl;
import com.facebook.react.cxxbridge.JSBundleLoader;
import com.facebook.react.cxxbridge.JSCJavaScriptExecutor;
import com.facebook.react.cxxbridge.JavaScriptExecutor;
import com.facebook.react.bridge.CatalystInstanceImpl;
import com.facebook.react.bridge.JSBundleLoader;
import com.facebook.react.bridge.JSCJavaScriptExecutor;
import com.facebook.react.bridge.JavaScriptExecutor;
import com.facebook.react.modules.core.ReactChoreographer;
import com.android.internal.util.Predicate;

View File

@ -9,7 +9,6 @@ DEPS = [
react_native_dep("third-party/java/jsr-305:jsr-305"),
react_native_target("java/com/facebook/react/bridge:bridge"),
react_native_target("java/com/facebook/react/common:common"),
react_native_target("java/com/facebook/react/cxxbridge:bridge"),
react_native_target("java/com/facebook/react/devsupport:devsupport"),
react_native_target("java/com/facebook/react/devsupport:interfaces"),
react_native_target("java/com/facebook/react/jstasks:jstasks"),

View File

@ -10,14 +10,14 @@ import java.util.Map;
import com.facebook.common.logging.FLog;
import com.facebook.react.bridge.BaseJavaModule;
import com.facebook.react.bridge.ModuleSpec;
import com.facebook.react.bridge.ModuleHolder;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.NativeModuleRegistry;
import com.facebook.react.bridge.OnBatchCompleteListener;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactMarker;
import com.facebook.react.bridge.ReactMarkerConstants;
import com.facebook.react.common.ReactConstants;
import com.facebook.react.cxxbridge.ModuleHolder;
import com.facebook.react.cxxbridge.NativeModuleRegistry;
import com.facebook.react.module.model.ReactModuleInfo;
/**

View File

@ -39,16 +39,16 @@ import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactMarker;
import com.facebook.react.bridge.ReactMarkerConstants;
import com.facebook.react.bridge.queue.ReactQueueConfigurationSpec;
import com.facebook.react.bridge.CatalystInstanceImpl;
import com.facebook.react.bridge.JSBundleLoader;
import com.facebook.react.bridge.JSCJavaScriptExecutor;
import com.facebook.react.bridge.JavaScriptExecutor;
import com.facebook.react.bridge.NativeModuleRegistry;
import com.facebook.react.bridge.ProxyJavaScriptExecutor;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.common.LifecycleState;
import com.facebook.react.common.ReactConstants;
import com.facebook.react.common.annotations.VisibleForTesting;
import com.facebook.react.cxxbridge.CatalystInstanceImpl;
import com.facebook.react.cxxbridge.JSBundleLoader;
import com.facebook.react.cxxbridge.JSCJavaScriptExecutor;
import com.facebook.react.cxxbridge.JavaScriptExecutor;
import com.facebook.react.cxxbridge.NativeModuleRegistry;
import com.facebook.react.cxxbridge.ProxyJavaScriptExecutor;
import com.facebook.react.cxxbridge.UiThreadUtil;
import com.facebook.react.devsupport.DevSupportManagerFactory;
import com.facebook.react.devsupport.ReactInstanceDevCommandsHandler;
import com.facebook.react.devsupport.RedBoxHandler;

View File

@ -13,8 +13,8 @@ import android.app.Application;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.NativeModuleCallExceptionHandler;
import com.facebook.react.bridge.NotThreadSafeBridgeIdleDebugListener;
import com.facebook.react.bridge.JSBundleLoader;
import com.facebook.react.common.LifecycleState;
import com.facebook.react.cxxbridge.JSBundleLoader;
import com.facebook.react.devsupport.interfaces.DevSupportManager;
import com.facebook.react.devsupport.RedBoxHandler;
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;

View File

@ -6,14 +6,155 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.react.bridge;
import java.lang.reflect.Array;
import java.util.AbstractList;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import android.os.Bundle;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableMapKeySetIterator;
import com.facebook.react.bridge.ReadableType;
import com.facebook.react.bridge.WritableNativeArray;
import com.facebook.react.bridge.WritableNativeMap;
public class Arguments {
private static Object makeNativeObject(Object object) {
if (object == null) {
return null;
} else if (object instanceof Float ||
object instanceof Long ||
object instanceof Byte ||
object instanceof Short) {
return new Double(((Number) object).doubleValue());
} else if (object.getClass().isArray()) {
return makeNativeArray(object);
} else if (object instanceof List) {
return makeNativeArray((List) object);
} else if (object instanceof Map) {
return makeNativeMap((Map<String, Object>) object);
} else if (object instanceof Bundle) {
return makeNativeMap((Bundle) object);
} else {
// Boolean, Integer, Double, String, WritableNativeArray, WritableNativeMap
return object;
}
}
/**
* This method converts a List into a NativeArray. The data types supported
* are boolean, int, float, double, and String. List, Map, and Bundle
* objects, as well as arrays, containing values of the above types and/or
* null, or any recursive arrangement of these, are also supported. The best
* way to think of this is a way to generate a Java representation of a json
* list, from Java types which have a natural representation in json.
*/
public static WritableNativeArray makeNativeArray(List objects) {
WritableNativeArray nativeArray = new WritableNativeArray();
if (objects == null) {
return nativeArray;
}
for (Object elem : objects) {
elem = makeNativeObject(elem);
if (elem == null) {
nativeArray.pushNull();
} else if (elem instanceof Boolean) {
nativeArray.pushBoolean((Boolean) elem);
} else if (elem instanceof Integer) {
nativeArray.pushInt((Integer) elem);
} else if (elem instanceof Double) {
nativeArray.pushDouble((Double) elem);
} else if (elem instanceof String) {
nativeArray.pushString((String) elem);
} else if (elem instanceof WritableNativeArray) {
nativeArray.pushArray((WritableNativeArray) elem);
} else if (elem instanceof WritableNativeMap) {
nativeArray.pushMap((WritableNativeMap) elem);
} else {
throw new IllegalArgumentException("Could not convert " + elem.getClass());
}
}
return nativeArray;
}
/**
* This overload is like the above, but uses reflection to operate on any
* primitive or object type.
*/
public static <T> WritableNativeArray makeNativeArray(final Object objects) {
if (objects == null) {
return new WritableNativeArray();
}
// No explicit check for objects's type here. If it's not an array, the
// Array methods will throw IllegalArgumentException.
return makeNativeArray(new AbstractList() {
public int size() {
return Array.getLength(objects);
}
public Object get(int index) {
return Array.get(objects, index);
}
});
}
private static void addEntry(WritableNativeMap nativeMap, String key, Object value) {
value = makeNativeObject(value);
if (value == null) {
nativeMap.putNull(key);
} else if (value instanceof Boolean) {
nativeMap.putBoolean(key, (Boolean) value);
} else if (value instanceof Integer) {
nativeMap.putInt(key, (Integer) value);
} else if (value instanceof Number) {
nativeMap.putDouble(key, ((Number) value).doubleValue());
} else if (value instanceof String) {
nativeMap.putString(key, (String) value);
} else if (value instanceof WritableNativeArray) {
nativeMap.putArray(key, (WritableNativeArray) value);
} else if (value instanceof WritableNativeMap) {
nativeMap.putMap(key, (WritableNativeMap) value);
} else {
throw new IllegalArgumentException("Could not convert " + value.getClass());
}
}
/**
* This method converts a Map into a NativeMap. Value types are supported as
* with makeNativeArray. The best way to think of this is a way to generate
* a Java representation of a json object, from Java types which have a
* natural representation in json.
*/
public static WritableNativeMap makeNativeMap(Map<String, Object> objects) {
WritableNativeMap nativeMap = new WritableNativeMap();
if (objects == null) {
return nativeMap;
}
for (Map.Entry<String, Object> entry : objects.entrySet()) {
addEntry(nativeMap, entry.getKey(), entry.getValue());
}
return nativeMap;
}
/**
* Like the above, but takes a Bundle instead of a Map.
*/
public static WritableNativeMap makeNativeMap(Bundle bundle) {
WritableNativeMap nativeMap = new WritableNativeMap();
if (bundle == null) {
return nativeMap;
}
for (String key : bundle.keySet()) {
addEntry(nativeMap, key, bundle.get(key));
}
return nativeMap;
}
/**
* This method should be used when you need to stub out creating NativeArrays in unit tests.
@ -64,35 +205,34 @@ public class Arguments {
* Convert an array to a {@link WritableArray}.
*
* @param array the array to convert. Supported types are: {@code String[]}, {@code Bundle[]},
* {@code int[]}, {@code float[]}, {@code double[]}, {@code boolean[]}.
*
* {@code int[]}, {@code float[]}, {@code double[]}, {@code boolean[]}.
* @return the converted {@link WritableArray}
* @throws IllegalArgumentException if the passed object is none of the above types
*/
public static WritableArray fromArray(Object array) {
WritableArray catalystArray = createArray();
if (array instanceof String[]) {
for (String v: (String[]) array) {
for (String v : (String[]) array) {
catalystArray.pushString(v);
}
} else if (array instanceof Bundle[]) {
for (Bundle v: (Bundle[]) array) {
for (Bundle v : (Bundle[]) array) {
catalystArray.pushMap(fromBundle(v));
}
} else if (array instanceof int[]) {
for (int v: (int[]) array) {
for (int v : (int[]) array) {
catalystArray.pushInt(v);
}
} else if (array instanceof float[]) {
for (float v: (float[]) array) {
for (float v : (float[]) array) {
catalystArray.pushDouble(v);
}
} else if (array instanceof double[]) {
for (double v: (double[]) array) {
for (double v : (double[]) array) {
catalystArray.pushDouble(v);
}
} else if (array instanceof boolean[]) {
for (boolean v: (boolean[]) array) {
for (boolean v : (boolean[]) array) {
catalystArray.pushBoolean(v);
}
} else {
@ -104,11 +244,11 @@ public class Arguments {
/**
* Convert a {@link Bundle} to a {@link WritableMap}. Supported key types in the bundle
* are:
*
* <p>
* <ul>
* <li>primitive types: int, float, double, boolean</li>
* <li>arrays supported by {@link #fromArray(Object)}</li>
* <li>{@link Bundle} objects that are recursively converted to maps</li>
* <li>primitive types: int, float, double, boolean</li>
* <li>arrays supported by {@link #fromArray(Object)}</li>
* <li>{@link Bundle} objects that are recursively converted to maps</li>
* </ul>
*
* @param bundle the {@link Bundle} to convert
@ -117,7 +257,7 @@ public class Arguments {
*/
public static WritableMap fromBundle(Bundle bundle) {
WritableMap map = createMap();
for (String key: bundle.keySet()) {
for (String key : bundle.keySet()) {
Object value = bundle.get(key);
if (value == null) {
map.putNull(key);
@ -144,6 +284,7 @@ public class Arguments {
/**
* Convert a {@link WritableMap} to a {@link Bundle}.
*
* @param readableMap the {@link WritableMap} to convert.
* @return the converted {@link Bundle}.
*/

View File

@ -33,5 +33,6 @@ android_library(
react_native_dep("third-party/java/infer-annotations:infer-annotations"),
react_native_dep("third-party/java/jsr-305:jsr-305"),
react_native_target("java/com/facebook/react/common:common"),
react_native_target("java/com/facebook/react/module/model:model"),
],
)

View File

@ -7,7 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.react.cxxbridge;
package com.facebook.react.bridge;
import javax.annotation.Nullable;

View File

@ -1,6 +1,6 @@
// Copyright 2004-present Facebook. All Rights Reserved.
package com.facebook.react.cxxbridge;
package com.facebook.react.bridge;
import com.facebook.jni.HybridData;
import com.facebook.proguard.annotations.DoNotStrip;
@ -10,15 +10,15 @@ import com.facebook.react.bridge.NativeArray;
import static com.facebook.react.bridge.Arguments.*;
/**
* Callback impl that calls directly into the cxxbridge. Created from C++.
* Callback impl that calls directly into the cxx bridge. Created from C++.
*/
@DoNotStrip
public class CallbackImpl implements Callback {
public class CxxCallbackImpl implements Callback {
@DoNotStrip
private final HybridData mHybridData;
@DoNotStrip
private CallbackImpl(HybridData hybridData) {
private CxxCallbackImpl(HybridData hybridData) {
mHybridData = hybridData;
}

View File

@ -1,6 +1,6 @@
// Copyright 2004-present Facebook. All Rights Reserved.
package com.facebook.react.cxxbridge;
package com.facebook.react.bridge;
import com.facebook.jni.HybridData;
import com.facebook.proguard.annotations.DoNotStrip;

View File

@ -1,6 +1,6 @@
// Copyright 2004-present Facebook. All Rights Reserved.
package com.facebook.react.cxxbridge;
package com.facebook.react.bridge;
import com.facebook.jni.HybridData;
import com.facebook.proguard.annotations.DoNotStrip;

View File

@ -7,7 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.react.cxxbridge;
package com.facebook.react.bridge;
import java.util.ArrayList;
import java.util.List;

View File

@ -7,7 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.react.cxxbridge;
package com.facebook.react.bridge;
import android.content.Context;

View File

@ -7,7 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.react.cxxbridge;
package com.facebook.react.bridge;
import com.facebook.jni.HybridData;
import com.facebook.proguard.annotations.DoNotStrip;

View File

@ -7,7 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.react.cxxbridge;
package com.facebook.react.bridge;
import javax.annotation.Nullable;

View File

@ -7,7 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.react.cxxbridge;
package com.facebook.react.bridge;
import javax.annotation.Nullable;

View File

@ -7,7 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.react.cxxbridge;
package com.facebook.react.bridge;
import com.facebook.jni.HybridData;
import com.facebook.proguard.annotations.DoNotStrip;

View File

@ -1,6 +1,6 @@
// Copyright 2004-present Facebook. All Rights Reserved.
package com.facebook.react.cxxbridge;
package com.facebook.react.bridge;
import javax.annotation.Nullable;
import javax.inject.Provider;

View File

@ -7,7 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.react.cxxbridge;
package com.facebook.react.bridge;
import java.util.ArrayList;
import java.util.Collection;

View File

@ -7,7 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.react.cxxbridge;
package com.facebook.react.bridge;
import javax.annotation.Nullable;

View File

@ -7,7 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.react.cxxbridge;
package com.facebook.react.bridge;
import com.facebook.proguard.annotations.DoNotStrip;

View File

@ -1,5 +1,5 @@
-keepnames class * extends com.facebook.react.bridge.JavaScriptModule { *; }
-keepnames class * extends com.facebook.react.cxxbridge.CxxModuleWrapper {*; }
-keepnames class * extends com.facebook.react.bridge.CxxModuleWrapper {*; }
-keepclassmembers class * extends com.facebook.react.bridge.NativeModule {
@com.facebook.react.bridge.ReactMethod *;
public <init>(...);
@ -17,3 +17,11 @@
void markerAnnotate(int,int,java.lang.String,java.lang.String);
void markerTag(int,int,java.lang.String);
}
## Putting this here is kind of a hack. I don't want to modify the OSS bridge.
## TODO mhorowitz: add @DoNotStrip to the interface directly.
-keepclassmembers class com.facebook.react.bridge.queue.MessageQueueThread {
public boolean isOnThread();
public void assertIsOnThread();
}

View File

@ -18,6 +18,7 @@ android_library(
],
deps = [
":build_config",
react_native_dep("libraries/fbcore/src/main/java/com/facebook/common/logging:logging"),
react_native_dep("third-party/android/support/v4:lib-support-v4"),
react_native_dep("third-party/java/infer-annotations:infer-annotations"),
react_native_dep("third-party/java/jsr-305:jsr-305"),

View File

@ -1,159 +0,0 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.react.cxxbridge;
import java.lang.reflect.Array;
import java.util.AbstractList;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import android.os.Bundle;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableMapKeySetIterator;
import com.facebook.react.bridge.ReadableType;
import com.facebook.react.bridge.WritableNativeArray;
import com.facebook.react.bridge.WritableNativeMap;
public class Arguments {
private static Object makeNativeObject(Object object) {
if (object == null) {
return null;
} else if (object instanceof Float ||
object instanceof Long ||
object instanceof Byte ||
object instanceof Short) {
return new Double(((Number) object).doubleValue());
} else if (object.getClass().isArray()) {
return makeNativeArray(object);
} else if (object instanceof List) {
return makeNativeArray((List) object);
} else if (object instanceof Map) {
return makeNativeMap((Map<String, Object>) object);
} else if (object instanceof Bundle) {
return makeNativeMap((Bundle) object);
} else {
// Boolean, Integer, Double, String, WritableNativeArray, WritableNativeMap
return object;
}
}
/**
* This method converts a List into a NativeArray. The data types supported
* are boolean, int, float, double, and String. List, Map, and Bundle
* objects, as well as arrays, containing values of the above types and/or
* null, or any recursive arrangement of these, are also supported. The best
* way to think of this is a way to generate a Java representation of a json
* list, from Java types which have a natural representation in json.
*/
public static WritableNativeArray makeNativeArray(List objects) {
WritableNativeArray nativeArray = new WritableNativeArray();
if (objects == null) {
return nativeArray;
}
for (Object elem : objects) {
elem = makeNativeObject(elem);
if (elem == null) {
nativeArray.pushNull();
} else if (elem instanceof Boolean) {
nativeArray.pushBoolean((Boolean) elem);
} else if (elem instanceof Integer) {
nativeArray.pushInt((Integer) elem);
} else if (elem instanceof Double) {
nativeArray.pushDouble((Double) elem);
} else if (elem instanceof String) {
nativeArray.pushString((String) elem);
} else if (elem instanceof WritableNativeArray) {
nativeArray.pushArray((WritableNativeArray) elem);
} else if (elem instanceof WritableNativeMap) {
nativeArray.pushMap((WritableNativeMap) elem);
} else {
throw new IllegalArgumentException("Could not convert " + elem.getClass());
}
}
return nativeArray;
}
/**
* This overload is like the above, but uses reflection to operate on any
* primitive or object type.
*/
public static <T> WritableNativeArray makeNativeArray(final Object objects) {
if (objects == null) {
return new WritableNativeArray();
}
// No explicit check for objects's type here. If it's not an array, the
// Array methods will throw IllegalArgumentException.
return makeNativeArray(new AbstractList() {
public int size() {
return Array.getLength(objects);
}
public Object get(int index) {
return Array.get(objects, index);
}
});
}
private static void addEntry(WritableNativeMap nativeMap, String key, Object value) {
value = makeNativeObject(value);
if (value == null) {
nativeMap.putNull(key);
} else if (value instanceof Boolean) {
nativeMap.putBoolean(key, (Boolean) value);
} else if (value instanceof Integer) {
nativeMap.putInt(key, (Integer) value);
} else if (value instanceof Number) {
nativeMap.putDouble(key, ((Number) value).doubleValue());
} else if (value instanceof String) {
nativeMap.putString(key, (String) value);
} else if (value instanceof WritableNativeArray) {
nativeMap.putArray(key, (WritableNativeArray) value);
} else if (value instanceof WritableNativeMap) {
nativeMap.putMap(key, (WritableNativeMap) value);
} else {
throw new IllegalArgumentException("Could not convert " + value.getClass());
}
}
/**
* This method converts a Map into a NativeMap. Value types are supported as
* with makeNativeArray. The best way to think of this is a way to generate
* a Java representation of a json object, from Java types which have a
* natural representation in json.
*/
public static WritableNativeMap makeNativeMap(Map<String, Object> objects) {
WritableNativeMap nativeMap = new WritableNativeMap();
if (objects == null) {
return nativeMap;
}
for (Map.Entry<String, Object> entry : objects.entrySet()) {
addEntry(nativeMap, entry.getKey(), entry.getValue());
}
return nativeMap;
}
/**
* Like the above, but takes a Bundle instead of a Map.
*/
public static WritableNativeMap makeNativeMap(Bundle bundle) {
WritableNativeMap nativeMap = new WritableNativeMap();
if (bundle == null) {
return nativeMap;
}
for (String key: bundle.keySet()) {
addEntry(nativeMap, key, bundle.get(key));
}
return nativeMap;
}
}

View File

@ -1,34 +0,0 @@
include_defs("//ReactAndroid/DEFS")
android_library(
name = "bridge",
srcs = glob(["**/*.java"]),
exported_deps = [
react_native_dep("java/com/facebook/jni:jni"),
react_native_dep("java/com/facebook/proguard/annotations:annotations"),
react_native_target("java/com/facebook/react/bridge:bridge"),
],
proguard_config = "bridge.pro",
visibility = [
"PUBLIC",
],
deps = [
react_native_dep("java/com/facebook/systrace:systrace"),
react_native_dep("libraries/fbcore/src/main/java/com/facebook/common/logging:logging"),
react_native_dep("libraries/soloader/java/com/facebook/soloader:soloader"),
# TODO mhorowitz:
# java/com/facebook/catalyst/js/react-native-github/ReactAndroid/src/main/java/com/facebook/react/bridge/
# lacks a similar dependency to this. This means that the
# loadLibrary calls in it are not guaranteed to succeed. This is
# kind of a mess for the jni/jni-internal stuff. In theory, we
# should be creating -internal android_library rules, too. In
# practice, since these are resolved at runtime, putting the
# dependency in the app works, too. gross.
# '//native/react/jni:jni-internal',
react_native_dep("third-party/java/infer-annotations:infer-annotations"),
react_native_dep("third-party/java/jsr-305:jsr-305"),
react_native_target("java/com/facebook/react/common:common"),
react_native_target("java/com/facebook/react/devsupport:devsupport"),
react_native_target("java/com/facebook/react/module/model:model"),
],
)

View File

@ -1,52 +0,0 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.react.cxxbridge;
import javax.annotation.Nullable;
import com.facebook.react.bridge.AssertionException;
/**
* Utility class to make assertions that should not hard-crash the app but instead be handled by the
* Catalyst app {@link NativeModuleCallExceptionHandler}. See the javadoc on that class for
* more information about our opinion on when these assertions should be used as opposed to
* assertions that might throw AssertionError Throwables that will cause the app to hard crash.
*/
public class SoftAssertions {
/**
* Throw {@link AssertionException} with a given message. Use this method surrounded with
* {@code if} block with assert condition in case you plan to do string concatenation to produce
* the message.
*/
public static void assertUnreachable(String message) {
throw new AssertionException(message);
}
/**
* Asserts the given condition, throwing an {@link AssertionException} if the condition doesn't
* hold.
*/
public static void assertCondition(boolean condition, String message) {
if (!condition) {
throw new AssertionException(message);
}
}
/**
* Asserts that the given Object isn't null, throwing an {@link AssertionException} if it was.
*/
public static <T> T assertNotNull(@Nullable T instance) {
if (instance == null) {
throw new AssertionException("Expected object to not be null!");
}
return instance;
}
}

View File

@ -1,56 +0,0 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.react.cxxbridge;
import javax.annotation.Nullable;
import android.os.Handler;
import android.os.Looper;
/**
* Utility for interacting with the UI thread.
*/
public class UiThreadUtil {
@Nullable private static Handler sMainHandler;
/**
* @return {@code true} if the current thread is the UI thread.
*/
public static boolean isOnUiThread() {
return Looper.getMainLooper().getThread() == Thread.currentThread();
}
/**
* Throws an {@link AssertionException} if the current thread is not the UI thread.
*/
public static void assertOnUiThread() {
SoftAssertions.assertCondition(isOnUiThread(), "Expected to run on UI thread!");
}
/**
* Throws an {@link AssertionException} if the current thread is the UI thread.
*/
public static void assertNotOnUiThread() {
SoftAssertions.assertCondition(!isOnUiThread(), "Expected not to run on UI thread!");
}
/**
* Runs the given {@code Runnable} on the UI thread.
*/
public static void runOnUiThread(Runnable runnable) {
synchronized (UiThreadUtil.class) {
if (sMainHandler == null) {
sMainHandler = new Handler(Looper.getMainLooper());
}
}
sMainHandler.post(runnable);
}
}

View File

@ -8,6 +8,5 @@ android_library(
],
deps = [
react_native_dep("third-party/java/jsr-305:jsr-305"),
react_native_target("java/com/facebook/react/bridge:bridge"),
],
)

View File

@ -19,12 +19,12 @@ class JavaScriptExecutorHolder;
class NativeArray;
struct ReactCallback : public jni::JavaClass<ReactCallback> {
static constexpr auto kJavaDescriptor = "Lcom/facebook/react/cxxbridge/ReactCallback;";
static constexpr auto kJavaDescriptor = "Lcom/facebook/react/bridge/ReactCallback;";
};
class CatalystInstanceImpl : public jni::HybridClass<CatalystInstanceImpl> {
public:
static constexpr auto kJavaDescriptor = "Lcom/facebook/react/cxxbridge/CatalystInstanceImpl;";
static constexpr auto kJavaDescriptor = "Lcom/facebook/react/bridge/CatalystInstanceImpl;";
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jclass>);
~CatalystInstanceImpl() override;

View File

@ -10,7 +10,7 @@ namespace react {
class CxxModuleWrapper : public jni::HybridClass<CxxModuleWrapper, CxxModuleWrapperBase> {
public:
constexpr static const char *const kJavaDescriptor =
"Lcom/facebook/react/cxxbridge/CxxModuleWrapper;";
"Lcom/facebook/react/bridge/CxxModuleWrapper;";
static void registerNatives() {
registerHybrid({

View File

@ -24,7 +24,7 @@ class CxxModuleWrapperBase
: public jni::HybridClass<CxxModuleWrapperBase, JNativeModule> {
public:
constexpr static const char *const kJavaDescriptor =
"Lcom/facebook/react/cxxbridge/CxxModuleWrapperBase;";
"Lcom/facebook/react/bridge/CxxModuleWrapperBase;";
static void registerNatives() {
registerHybrid({

View File

@ -18,20 +18,20 @@ struct JCallback : public jni::JavaClass<JCallback> {
constexpr static auto kJavaDescriptor = "Lcom/facebook/react/bridge/Callback;";
};
class JCallbackImpl : public jni::HybridClass<JCallbackImpl, JCallback> {
class JCxxCallbackImpl : public jni::HybridClass<JCxxCallbackImpl, JCallback> {
public:
constexpr static auto kJavaDescriptor = "Lcom/facebook/react/cxxbridge/CallbackImpl;";
constexpr static auto kJavaDescriptor = "Lcom/facebook/react/bridge/CxxCallbackImpl;";
static void registerNatives() {
javaClassStatic()->registerNatives({
makeNativeMethod("nativeInvoke", JCallbackImpl::invoke),
makeNativeMethod("nativeInvoke", JCxxCallbackImpl::invoke),
});
}
private:
friend HybridBase;
using Callback = std::function<void(folly::dynamic)>;
JCallbackImpl(Callback callback) : callback_(std::move(callback)) {}
JCxxCallbackImpl(Callback callback) : callback_(std::move(callback)) {}
void invoke(NativeArray* arguments) {
callback_(arguments->consume());

View File

@ -16,7 +16,7 @@ class MessageQueueThread;
struct JMethodDescriptor : public jni::JavaClass<JMethodDescriptor> {
static constexpr auto kJavaDescriptor =
"Lcom/facebook/react/cxxbridge/JavaModuleWrapper$MethodDescriptor;";
"Lcom/facebook/react/bridge/JavaModuleWrapper$MethodDescriptor;";
jni::local_ref<JReflectMethod::javaobject> getMethod() const;
std::string getSignature() const;
@ -25,7 +25,7 @@ struct JMethodDescriptor : public jni::JavaClass<JMethodDescriptor> {
};
struct JavaModuleWrapper : jni::JavaClass<JavaModuleWrapper> {
static constexpr auto kJavaDescriptor = "Lcom/facebook/react/cxxbridge/JavaModuleWrapper;";
static constexpr auto kJavaDescriptor = "Lcom/facebook/react/bridge/JavaModuleWrapper;";
jni::local_ref<JBaseJavaModule::javaobject> getModule() {
// This is the call which causes a lazy Java module to actually be

View File

@ -12,7 +12,7 @@ namespace react {
class JavaScriptExecutorHolder : public jni::HybridClass<JavaScriptExecutorHolder> {
public:
static constexpr auto kJavaDescriptor =
"Lcom/facebook/react/cxxbridge/JavaScriptExecutor;";
"Lcom/facebook/react/bridge/JavaScriptExecutor;";
std::shared_ptr<JSExecutorFactory> getExecutorFactory() {
return mExecutorFactory;

View File

@ -46,11 +46,11 @@ jdouble extractDouble(const folly::dynamic& value) {
}
}
local_ref<JCallbackImpl::jhybridobject> extractCallback(std::weak_ptr<Instance>& instance, const folly::dynamic& value) {
local_ref<JCxxCallbackImpl::jhybridobject> extractCallback(std::weak_ptr<Instance>& instance, const folly::dynamic& value) {
if (value.isNull()) {
return local_ref<JCallbackImpl::jhybridobject>(nullptr);
return local_ref<JCxxCallbackImpl::jhybridobject>(nullptr);
} else {
return JCallbackImpl::newObjectCxxArgs(makeCallback(instance, value));
return JCxxCallbackImpl::newObjectCxxArgs(makeCallback(instance, value));
}
}

View File

@ -17,7 +17,7 @@ class MessageQueueThread;
class ModuleHolder : public jni::JavaClass<ModuleHolder> {
public:
static auto constexpr kJavaDescriptor =
"Lcom/facebook/react/cxxbridge/ModuleHolder;";
"Lcom/facebook/react/bridge/ModuleHolder;";
std::string getName() const;
xplat::module::CxxModule::Provider getProvider() const;

View File

@ -35,7 +35,7 @@ namespace {
class JSCJavaScriptExecutorHolder : public HybridClass<JSCJavaScriptExecutorHolder,
JavaScriptExecutorHolder> {
public:
static constexpr auto kJavaDescriptor = "Lcom/facebook/react/cxxbridge/JSCJavaScriptExecutor;";
static constexpr auto kJavaDescriptor = "Lcom/facebook/react/bridge/JSCJavaScriptExecutor;";
static local_ref<jhybriddata> initHybrid(alias_ref<jclass>, ReadableNativeArray* jscConfigArray) {
// See JSCJavaScriptExecutor.Factory() for the other side of this hack.
@ -61,7 +61,7 @@ struct JavaJSExecutor : public JavaClass<JavaJSExecutor> {
class ProxyJavaScriptExecutorHolder : public HybridClass<ProxyJavaScriptExecutorHolder,
JavaScriptExecutorHolder> {
public:
static constexpr auto kJavaDescriptor = "Lcom/facebook/react/cxxbridge/ProxyJavaScriptExecutor;";
static constexpr auto kJavaDescriptor = "Lcom/facebook/react/bridge/ProxyJavaScriptExecutor;";
static local_ref<jhybriddata> initHybrid(
alias_ref<jclass>, alias_ref<JavaJSExecutor::javaobject> executorInstance) {
@ -159,7 +159,7 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
CatalystInstanceImpl::registerNatives();
CxxModuleWrapperBase::registerNatives();
CxxModuleWrapper::registerNatives();
JCallbackImpl::registerNatives();
JCxxCallbackImpl::registerNatives();
#ifdef WITH_INSPECTOR
JInspector::registerNatives();
#endif

View File

@ -42,5 +42,6 @@ rn_robolectric_test(
react_native_target("java/com/facebook/react/bridge:bridge"),
react_native_target("java/com/facebook/react/common:common"),
react_native_target("java/com/facebook/react/uimanager:uimanager"),
react_native_tests_target("java/com/facebook/common/logging:logging"),
],
)

View File

@ -7,17 +7,11 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.react.cxxbridge;
package com.facebook.react.bridge;
import javax.inject.Provider;
import java.util.List;
import com.facebook.react.bridge.BaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableNativeArray;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.NativeArgumentsParseException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.runner.RunWith;

View File

@ -7,7 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.react.cxxbridge;
package com.facebook.react.bridge;
import java.util.ArrayList;
import java.util.Arrays;

View File

@ -1,22 +0,0 @@
include_defs("//ReactAndroid/DEFS")
rn_robolectric_test(
name = "cxxbridge",
srcs = glob(["*Test.java"]),
# Please change the contact to the oncall of your team
contacts = ["oncall+fbandroid_sheriff@xmail.facebook.com"],
visibility = [
"PUBLIC",
],
deps = [
react_native_dep("libraries/fbcore/src/test/java/com/facebook/powermock:powermock"),
react_native_dep("libraries/soloader/java/com/facebook/soloader:soloader"),
react_native_dep("third-party/java/fest:fest"),
react_native_dep("third-party/java/junit:junit"),
react_native_dep("third-party/java/mockito:mockito"),
react_native_dep("third-party/java/robolectric3/robolectric:robolectric"),
react_native_target("java/com/facebook/react/bridge:bridge"),
react_native_target("java/com/facebook/react/cxxbridge:bridge"),
react_native_tests_target("java/com/facebook/common/logging:logging"),
],
)