-
Notifications
You must be signed in to change notification settings - Fork 24.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Pull Request resolved: #45884 Pull Request resolved: #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
- Loading branch information
1 parent
8d4fd07
commit a4cd599
Showing
12 changed files
with
278 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/NativeArray.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.facebook.react.bridge; | ||
|
||
import com.facebook.jni.HybridData; | ||
import com.facebook.proguard.annotations.DoNotStrip; | ||
|
||
/** Base class for an array whose members are stored in native code (C++). */ | ||
@DoNotStrip | ||
public abstract class NativeArray implements NativeArrayInterface { | ||
static { | ||
ReactBridge.staticInit(); | ||
} | ||
|
||
protected NativeArray(HybridData hybridData) { | ||
mHybridData = hybridData; | ||
} | ||
|
||
@Override | ||
public native String toString(); | ||
|
||
@DoNotStrip private HybridData mHybridData; | ||
} |
25 changes: 0 additions & 25 deletions
25
packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/NativeArray.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
174 changes: 174 additions & 0 deletions
174
...eact-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReadableNativeArray.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.facebook.react.bridge; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import com.facebook.infer.annotation.Assertions; | ||
import com.facebook.jni.HybridData; | ||
import com.facebook.proguard.annotations.DoNotStrip; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
|
||
/** | ||
* Implementation of a NativeArray that allows read-only access to its members. This will generally | ||
* be constructed and filled in native code so you shouldn't construct one yourself. | ||
*/ | ||
@DoNotStrip | ||
public class ReadableNativeArray extends NativeArray implements ReadableArray { | ||
static { | ||
ReactBridge.staticInit(); | ||
} | ||
|
||
protected ReadableNativeArray(HybridData hybridData) { | ||
super(hybridData); | ||
} | ||
|
||
// WriteOnce but not in the constructor fields | ||
private @Nullable Object[] mLocalArray; | ||
private @Nullable ReadableType[] mLocalTypeArray; | ||
|
||
private static int jniPassCounter = 0; | ||
|
||
public static int getJNIPassCounter() { | ||
return jniPassCounter; | ||
} | ||
|
||
private Object[] getLocalArray() { | ||
if (mLocalArray != null) { | ||
return mLocalArray; | ||
} | ||
synchronized (this) { | ||
// Make sure no concurrent call already updated | ||
if (mLocalArray == null) { | ||
jniPassCounter++; | ||
mLocalArray = Assertions.assertNotNull(importArray()); | ||
} | ||
} | ||
return mLocalArray; | ||
} | ||
|
||
private native Object[] importArray(); | ||
|
||
private ReadableType[] getLocalTypeArray() { | ||
if (mLocalTypeArray != null) { | ||
return mLocalTypeArray; | ||
} | ||
synchronized (this) { | ||
// Make sure no concurrent call already updated | ||
if (mLocalTypeArray == null) { | ||
jniPassCounter++; | ||
Object[] tempArray = Assertions.assertNotNull(importTypeArray()); | ||
mLocalTypeArray = Arrays.copyOf(tempArray, tempArray.length, ReadableType[].class); | ||
} | ||
} | ||
return mLocalTypeArray; | ||
} | ||
|
||
private native Object[] importTypeArray(); | ||
|
||
@Override | ||
public int size() { | ||
return getLocalArray().length; | ||
} | ||
|
||
@Override | ||
public boolean isNull(int index) { | ||
return getLocalArray()[index] == null; | ||
} | ||
|
||
@Override | ||
public boolean getBoolean(int index) { | ||
return ((Boolean) getLocalArray()[index]).booleanValue(); | ||
} | ||
|
||
@Override | ||
public double getDouble(int index) { | ||
return ((Double) getLocalArray()[index]).doubleValue(); | ||
} | ||
|
||
@Override | ||
public int getInt(int index) { | ||
return ((Double) getLocalArray()[index]).intValue(); | ||
} | ||
|
||
@Override | ||
public long getLong(int index) { | ||
return ((Long) getLocalArray()[index]).longValue(); | ||
} | ||
|
||
@Override | ||
public @NonNull String getString(int index) { | ||
return (String) getLocalArray()[index]; | ||
} | ||
|
||
@Override | ||
public @NonNull ReadableNativeArray getArray(int index) { | ||
return (ReadableNativeArray) getLocalArray()[index]; | ||
} | ||
|
||
@Override | ||
public @NonNull ReadableNativeMap getMap(int index) { | ||
return (ReadableNativeMap) getLocalArray()[index]; | ||
} | ||
|
||
@Override | ||
public @NonNull ReadableType getType(int index) { | ||
return getLocalTypeArray()[index]; | ||
} | ||
|
||
@Override | ||
public @NonNull Dynamic getDynamic(int index) { | ||
return DynamicFromArray.create(this, index); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return getLocalArray().hashCode(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (!(obj instanceof ReadableNativeArray)) { | ||
return false; | ||
} | ||
ReadableNativeArray other = (ReadableNativeArray) obj; | ||
return Arrays.deepEquals(getLocalArray(), other.getLocalArray()); | ||
} | ||
|
||
@Override | ||
public @NonNull ArrayList<Object> toArrayList() { | ||
ArrayList<Object> arrayList = new ArrayList<>(); | ||
|
||
for (int i = 0; i < this.size(); i++) { | ||
switch (getType(i)) { | ||
case Null: | ||
arrayList.add(null); | ||
break; | ||
case Boolean: | ||
arrayList.add(getBoolean(i)); | ||
break; | ||
case Number: | ||
arrayList.add(getDouble(i)); | ||
break; | ||
case String: | ||
arrayList.add(getString(i)); | ||
break; | ||
case Map: | ||
arrayList.add(getMap(i).toHashMap()); | ||
break; | ||
case Array: | ||
arrayList.add(getArray(i).toArrayList()); | ||
break; | ||
default: | ||
throw new IllegalArgumentException("Could not convert object at index: " + i + "."); | ||
} | ||
} | ||
return arrayList; | ||
} | ||
} |
90 changes: 0 additions & 90 deletions
90
.../react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReadableNativeArray.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.