mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-12 22:39:06 +08:00
Extract all NativeArray/NativeMap from OnLoad.cpp
Summary: These will, eventually, need to be moved to the new bridge and so must become standalone things. For *NativeArray, this is almost just moving them out into their own .h/.cpp files. The *NativeMaps are updated to be hybrids instead of countables (in addition to getting their own .h/.cpp). Reviewed By: mhorowitz Differential Revision: D3325169 fbshipit-source-id: 40cfcab92b3fb2310bcd4de8f39e82f85d404abd
This commit is contained in:
committed by
Facebook Github Bot 2
parent
0d1d7ba2b7
commit
886a558f75
@@ -9,7 +9,7 @@
|
||||
|
||||
package com.facebook.react.bridge;
|
||||
|
||||
import com.facebook.jni.Countable;
|
||||
import com.facebook.jni.HybridData;
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
|
||||
@@ -17,18 +17,18 @@ import com.facebook.soloader.SoLoader;
|
||||
* Base class for a Map whose keys and values are stored in native code (C++).
|
||||
*/
|
||||
@DoNotStrip
|
||||
public abstract class NativeMap extends Countable {
|
||||
|
||||
public abstract class NativeMap {
|
||||
static {
|
||||
SoLoader.loadLibrary(ReactBridge.REACT_NATIVE_LIB);
|
||||
}
|
||||
|
||||
public NativeMap() {
|
||||
initialize();
|
||||
public NativeMap(HybridData hybridData) {
|
||||
mHybridData = hybridData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public native String toString();
|
||||
|
||||
private native void initialize();
|
||||
@DoNotStrip
|
||||
private HybridData mHybridData;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
package com.facebook.react.bridge;
|
||||
|
||||
import com.facebook.jni.Countable;
|
||||
import com.facebook.jni.HybridData;
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
|
||||
@@ -27,6 +27,10 @@ public class ReadableNativeMap extends NativeMap implements ReadableMap {
|
||||
SoLoader.loadLibrary(ReactBridge.REACT_NATIVE_LIB);
|
||||
}
|
||||
|
||||
protected ReadableNativeMap(HybridData hybridData) {
|
||||
super(hybridData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public native boolean hasKey(String name);
|
||||
@Override
|
||||
@@ -51,7 +55,7 @@ public class ReadableNativeMap extends NativeMap implements ReadableMap {
|
||||
return new ReadableNativeMapKeySetIterator(this);
|
||||
}
|
||||
|
||||
public HashMap<String, Object>toHashMap() {
|
||||
public HashMap<String, Object> toHashMap() {
|
||||
ReadableMapKeySetIterator iterator = keySetIterator();
|
||||
HashMap<String, Object> hashMap = new HashMap<>();
|
||||
|
||||
@@ -87,14 +91,17 @@ public class ReadableNativeMap extends NativeMap implements ReadableMap {
|
||||
* Implementation of a {@link ReadableNativeMap} iterator in native memory.
|
||||
*/
|
||||
@DoNotStrip
|
||||
private static class ReadableNativeMapKeySetIterator extends Countable
|
||||
implements ReadableMapKeySetIterator {
|
||||
private static class ReadableNativeMapKeySetIterator implements ReadableMapKeySetIterator {
|
||||
@DoNotStrip
|
||||
private final HybridData mHybridData;
|
||||
|
||||
private final ReadableNativeMap mReadableNativeMap;
|
||||
// Need to hold a strong ref to the map so that our native references remain valid.
|
||||
@DoNotStrip
|
||||
private final ReadableNativeMap mMap;
|
||||
|
||||
public ReadableNativeMapKeySetIterator(ReadableNativeMap readableNativeMap) {
|
||||
mReadableNativeMap = readableNativeMap;
|
||||
initialize(mReadableNativeMap);
|
||||
mMap = readableNativeMap;
|
||||
mHybridData = initHybrid(readableNativeMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -102,6 +109,6 @@ public class ReadableNativeMap extends NativeMap implements ReadableMap {
|
||||
@Override
|
||||
public native String nextKey();
|
||||
|
||||
private native void initialize(ReadableNativeMap readableNativeMap);
|
||||
private static native HybridData initHybrid(ReadableNativeMap readableNativeMap);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class WritableNativeArray extends ReadableNativeArray implements Writable
|
||||
pushNativeMap((WritableNativeMap) map);
|
||||
}
|
||||
|
||||
private native static HybridData initHybrid();
|
||||
private static native HybridData initHybrid();
|
||||
private native void pushNativeArray(WritableNativeArray array);
|
||||
private native void pushNativeMap(WritableNativeMap map);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
package com.facebook.react.bridge;
|
||||
|
||||
import com.facebook.jni.HybridData;
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
@@ -20,7 +21,6 @@ import com.facebook.soloader.SoLoader;
|
||||
*/
|
||||
@DoNotStrip
|
||||
public class WritableNativeMap extends ReadableNativeMap implements WritableMap {
|
||||
|
||||
static {
|
||||
SoLoader.loadLibrary(ReactBridge.REACT_NATIVE_LIB);
|
||||
}
|
||||
@@ -59,6 +59,12 @@ public class WritableNativeMap extends ReadableNativeMap implements WritableMap
|
||||
mergeNativeMap((ReadableNativeMap) source);
|
||||
}
|
||||
|
||||
public WritableNativeMap() {
|
||||
super(initHybrid());
|
||||
}
|
||||
|
||||
private static native HybridData initHybrid();
|
||||
|
||||
private native void putNativeMap(String key, WritableNativeMap value);
|
||||
private native void putNativeArray(String key, WritableNativeArray value);
|
||||
private native void mergeNativeMap(ReadableNativeMap source);
|
||||
|
||||
Reference in New Issue
Block a user