Skip to content

Commit a4cd599

Browse files
generatedunixname89002005232357facebook-github-bot
authored andcommitted
Revert D57327835 (facebook#45884)
Summary: Pull Request resolved: facebook#45884 Pull Request resolved: facebook#44569 Changelog: [Internal] - Reverting this diff due to internal build crashes: This converts the vertical of NativeArray/ReadableNativeArray/WritableNativeArray classes to Kotlin. Reviewed By: bvanderhoof Differential Revision: D60707170 fbshipit-source-id: 95e66ebe725d0ff625b50f4711872b9f70ec2f7c
1 parent 8d4fd07 commit a4cd599

File tree

12 files changed

+278
-184
lines changed

12 files changed

+278
-184
lines changed

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,7 @@ public class com/facebook/react/bridge/ReadableNativeArray : com/facebook/react/
14891489
public fun getDouble (I)D
14901490
public fun getDynamic (I)Lcom/facebook/react/bridge/Dynamic;
14911491
public fun getInt (I)I
1492-
public static final fun getJNIPassCounter ()I
1492+
public static fun getJNIPassCounter ()I
14931493
public fun getLong (I)J
14941494
public synthetic fun getMap (I)Lcom/facebook/react/bridge/ReadableMap;
14951495
public fun getMap (I)Lcom/facebook/react/bridge/ReadableNativeMap;

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/JavaMethodWrapper.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ public String extractArgument(
7979
@Override
8080
public ReadableArray extractArgument(
8181
JSInstance jsInstance, ReadableArray jsArguments, int atIndex) {
82-
if (jsArguments.isNull(atIndex) || jsArguments.getType(atIndex) != ReadableType.Array) {
83-
return null;
84-
}
8582
return jsArguments.getArray(atIndex);
8683
}
8784
};
@@ -100,9 +97,6 @@ public Dynamic extractArgument(
10097
@Override
10198
public ReadableMap extractArgument(
10299
JSInstance jsInstance, ReadableArray jsArguments, int atIndex) {
103-
if (jsArguments.isNull(atIndex) || jsArguments.getType(atIndex) != ReadableType.Map) {
104-
return null;
105-
}
106100
return jsArguments.getMap(atIndex);
107101
}
108102
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.facebook.react.bridge;
9+
10+
import com.facebook.jni.HybridData;
11+
import com.facebook.proguard.annotations.DoNotStrip;
12+
13+
/** Base class for an array whose members are stored in native code (C++). */
14+
@DoNotStrip
15+
public abstract class NativeArray implements NativeArrayInterface {
16+
static {
17+
ReactBridge.staticInit();
18+
}
19+
20+
protected NativeArray(HybridData hybridData) {
21+
mHybridData = hybridData;
22+
}
23+
24+
@Override
25+
public native String toString();
26+
27+
@DoNotStrip private HybridData mHybridData;
28+
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/NativeArray.kt

Lines changed: 0 additions & 25 deletions
This file was deleted.

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReadableArray.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ public interface ReadableArray {
3636

3737
public fun size(): Int
3838

39-
public fun toArrayList(): ArrayList<Any?>
39+
public fun toArrayList(): ArrayList<Any>
4040
}
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.facebook.react.bridge;
9+
10+
import androidx.annotation.NonNull;
11+
import androidx.annotation.Nullable;
12+
import com.facebook.infer.annotation.Assertions;
13+
import com.facebook.jni.HybridData;
14+
import com.facebook.proguard.annotations.DoNotStrip;
15+
import java.util.ArrayList;
16+
import java.util.Arrays;
17+
18+
/**
19+
* Implementation of a NativeArray that allows read-only access to its members. This will generally
20+
* be constructed and filled in native code so you shouldn't construct one yourself.
21+
*/
22+
@DoNotStrip
23+
public class ReadableNativeArray extends NativeArray implements ReadableArray {
24+
static {
25+
ReactBridge.staticInit();
26+
}
27+
28+
protected ReadableNativeArray(HybridData hybridData) {
29+
super(hybridData);
30+
}
31+
32+
// WriteOnce but not in the constructor fields
33+
private @Nullable Object[] mLocalArray;
34+
private @Nullable ReadableType[] mLocalTypeArray;
35+
36+
private static int jniPassCounter = 0;
37+
38+
public static int getJNIPassCounter() {
39+
return jniPassCounter;
40+
}
41+
42+
private Object[] getLocalArray() {
43+
if (mLocalArray != null) {
44+
return mLocalArray;
45+
}
46+
synchronized (this) {
47+
// Make sure no concurrent call already updated
48+
if (mLocalArray == null) {
49+
jniPassCounter++;
50+
mLocalArray = Assertions.assertNotNull(importArray());
51+
}
52+
}
53+
return mLocalArray;
54+
}
55+
56+
private native Object[] importArray();
57+
58+
private ReadableType[] getLocalTypeArray() {
59+
if (mLocalTypeArray != null) {
60+
return mLocalTypeArray;
61+
}
62+
synchronized (this) {
63+
// Make sure no concurrent call already updated
64+
if (mLocalTypeArray == null) {
65+
jniPassCounter++;
66+
Object[] tempArray = Assertions.assertNotNull(importTypeArray());
67+
mLocalTypeArray = Arrays.copyOf(tempArray, tempArray.length, ReadableType[].class);
68+
}
69+
}
70+
return mLocalTypeArray;
71+
}
72+
73+
private native Object[] importTypeArray();
74+
75+
@Override
76+
public int size() {
77+
return getLocalArray().length;
78+
}
79+
80+
@Override
81+
public boolean isNull(int index) {
82+
return getLocalArray()[index] == null;
83+
}
84+
85+
@Override
86+
public boolean getBoolean(int index) {
87+
return ((Boolean) getLocalArray()[index]).booleanValue();
88+
}
89+
90+
@Override
91+
public double getDouble(int index) {
92+
return ((Double) getLocalArray()[index]).doubleValue();
93+
}
94+
95+
@Override
96+
public int getInt(int index) {
97+
return ((Double) getLocalArray()[index]).intValue();
98+
}
99+
100+
@Override
101+
public long getLong(int index) {
102+
return ((Long) getLocalArray()[index]).longValue();
103+
}
104+
105+
@Override
106+
public @NonNull String getString(int index) {
107+
return (String) getLocalArray()[index];
108+
}
109+
110+
@Override
111+
public @NonNull ReadableNativeArray getArray(int index) {
112+
return (ReadableNativeArray) getLocalArray()[index];
113+
}
114+
115+
@Override
116+
public @NonNull ReadableNativeMap getMap(int index) {
117+
return (ReadableNativeMap) getLocalArray()[index];
118+
}
119+
120+
@Override
121+
public @NonNull ReadableType getType(int index) {
122+
return getLocalTypeArray()[index];
123+
}
124+
125+
@Override
126+
public @NonNull Dynamic getDynamic(int index) {
127+
return DynamicFromArray.create(this, index);
128+
}
129+
130+
@Override
131+
public int hashCode() {
132+
return getLocalArray().hashCode();
133+
}
134+
135+
@Override
136+
public boolean equals(Object obj) {
137+
if (!(obj instanceof ReadableNativeArray)) {
138+
return false;
139+
}
140+
ReadableNativeArray other = (ReadableNativeArray) obj;
141+
return Arrays.deepEquals(getLocalArray(), other.getLocalArray());
142+
}
143+
144+
@Override
145+
public @NonNull ArrayList<Object> toArrayList() {
146+
ArrayList<Object> arrayList = new ArrayList<>();
147+
148+
for (int i = 0; i < this.size(); i++) {
149+
switch (getType(i)) {
150+
case Null:
151+
arrayList.add(null);
152+
break;
153+
case Boolean:
154+
arrayList.add(getBoolean(i));
155+
break;
156+
case Number:
157+
arrayList.add(getDouble(i));
158+
break;
159+
case String:
160+
arrayList.add(getString(i));
161+
break;
162+
case Map:
163+
arrayList.add(getMap(i).toHashMap());
164+
break;
165+
case Array:
166+
arrayList.add(getArray(i).toArrayList());
167+
break;
168+
default:
169+
throw new IllegalArgumentException("Could not convert object at index: " + i + ".");
170+
}
171+
}
172+
return arrayList;
173+
}
174+
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReadableNativeArray.kt

Lines changed: 0 additions & 90 deletions
This file was deleted.

0 commit comments

Comments
 (0)