Convert com.facebook.react.bridge.WritableNativeArray to Kotlin (#47486)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/47486

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D65596952

fbshipit-source-id: 462432af819ed9a7fba515cee54055d737d2584e
This commit is contained in:
Pieter De Baets
2024-11-22 01:53:48 -08:00
committed by Facebook GitHub Bot
parent 145c72f816
commit eb5fbdf134
4 changed files with 53 additions and 74 deletions
@@ -1622,7 +1622,7 @@ public abstract interface class com/facebook/react/bridge/WritableMap : com/face
public abstract fun putString (Ljava/lang/String;Ljava/lang/String;)V
}
public class com/facebook/react/bridge/WritableNativeArray : com/facebook/react/bridge/ReadableNativeArray, com/facebook/react/bridge/WritableArray {
public final class com/facebook/react/bridge/WritableNativeArray : com/facebook/react/bridge/ReadableNativeArray, com/facebook/react/bridge/WritableArray {
public fun <init> ()V
public fun pushArray (Lcom/facebook/react/bridge/ReadableArray;)V
public fun pushBoolean (Z)V
@@ -1,67 +0,0 @@
/*
* 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.Nullable;
import com.facebook.infer.annotation.Assertions;
import com.facebook.proguard.annotations.DoNotStrip;
/**
* Implementation of a write-only array stored in native memory. Use {@link Arguments#createArray()}
* if you need to stub out creating this class in a test. TODO(5815532): Check if consumed on read
*/
@DoNotStrip
public class WritableNativeArray extends ReadableNativeArray implements WritableArray {
static {
ReactBridge.staticInit();
}
public WritableNativeArray() {
initHybrid();
}
@Override
public native void pushNull();
@Override
public native void pushBoolean(boolean value);
@Override
public native void pushDouble(double value);
@Override
public native void pushInt(int value);
@Override
public native void pushLong(long value);
@Override
public native void pushString(@Nullable String value);
// Note: this consumes the map so do not reuse it.
@Override
public void pushArray(@Nullable ReadableArray array) {
Assertions.assertCondition(
array == null || array instanceof ReadableNativeArray, "Illegal type provided");
pushNativeArray((ReadableNativeArray) array);
}
// Note: this consumes the map so do not reuse it.
@Override
public void pushMap(@Nullable ReadableMap map) {
Assertions.assertCondition(
map == null || map instanceof ReadableNativeMap, "Illegal type provided");
pushNativeMap((ReadableNativeMap) map);
}
private native void initHybrid();
private native void pushNativeArray(ReadableNativeArray array);
private native void pushNativeMap(ReadableNativeMap map);
}
@@ -0,0 +1,52 @@
/*
* 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.proguard.annotations.DoNotStrip
/**
* Implementation of a write-only array stored in native memory. Use [Arguments#createArray()] if
* you need to stub out creating this class in a test.
*/
@DoNotStrip
public class WritableNativeArray : ReadableNativeArray(), WritableArray {
init {
initHybrid()
}
external override fun pushNull()
external override fun pushBoolean(value: Boolean)
external override fun pushDouble(value: Double)
external override fun pushInt(value: Int)
external override fun pushLong(value: Long)
external override fun pushString(value: String?)
// Note: this consumes the map so do not reuse it.
override fun pushArray(array: ReadableArray?) {
check(array == null || array is ReadableNativeArray) { "Illegal type provided" }
pushNativeArray(array as ReadableNativeArray?)
}
// Note: this consumes the map so do not reuse it.
override fun pushMap(map: ReadableMap?) {
check(map == null || map is ReadableNativeMap) { "Illegal type provided" }
pushNativeMap(map as ReadableNativeMap?)
}
private external fun initHybrid()
private external fun pushNativeArray(array: ReadableNativeArray?)
private external fun pushNativeMap(map: ReadableNativeMap?)
}
@@ -63,10 +63,4 @@ public class WritableNativeMap : ReadableNativeMap(), WritableMap {
private external fun mergeNativeMap(source: ReadableNativeMap)
private external fun initHybrid()
private companion object {
init {
ReactBridge.staticInit()
}
}
}