From 209d74e91f64850a437df0fa5fde8c39bdc52dd6 Mon Sep 17 00:00:00 2001 From: Jiri Vanek Date: Mon, 16 Dec 2024 11:02:56 +0100 Subject: [PATCH] rn 76.5 fix error while updating width/height ViroNode --- android/viro_bridge/build.gradle | 2 +- .../bridge/component/node/VRTNodeManager.java | 2 +- .../bridge/module/DynamicFromMap.java | 116 ++++++++++++++++++ 3 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 android/viro_bridge/src/main/java/com/viromedia/bridge/module/DynamicFromMap.java diff --git a/android/viro_bridge/build.gradle b/android/viro_bridge/build.gradle index 72de7e7..576e7c8 100644 --- a/android/viro_bridge/build.gradle +++ b/android/viro_bridge/build.gradle @@ -29,7 +29,7 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.0.0' testImplementation 'junit:junit:4.12' - implementation 'com.facebook.react:react-native:+' + implementation 'com.facebook.react:react-android' implementation 'com.google.ar:core:1.41.0' implementation project(':gvr_common') implementation project(':viro_renderer') diff --git a/android/viro_bridge/src/main/java/com/viromedia/bridge/component/node/VRTNodeManager.java b/android/viro_bridge/src/main/java/com/viromedia/bridge/component/node/VRTNodeManager.java index 053e778..b0eeb84 100644 --- a/android/viro_bridge/src/main/java/com/viromedia/bridge/component/node/VRTNodeManager.java +++ b/android/viro_bridge/src/main/java/com/viromedia/bridge/component/node/VRTNodeManager.java @@ -24,7 +24,6 @@ import android.provider.MediaStore; import com.facebook.react.bridge.Dynamic; -import com.facebook.react.bridge.DynamicFromMap; import com.facebook.react.bridge.JavaOnlyMap; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReadableArray; @@ -39,6 +38,7 @@ import com.viro.core.Material; import com.viro.core.VideoTexture; import com.viromedia.bridge.component.VRTViroViewGroupManager; +import com.viromedia.bridge.module.DynamicFromMap; import com.viromedia.bridge.module.MaterialManager; import com.viromedia.bridge.module.MaterialManager.MaterialWrapper; import com.viromedia.bridge.utility.Helper; diff --git a/android/viro_bridge/src/main/java/com/viromedia/bridge/module/DynamicFromMap.java b/android/viro_bridge/src/main/java/com/viromedia/bridge/module/DynamicFromMap.java new file mode 100644 index 0000000..716f124 --- /dev/null +++ b/android/viro_bridge/src/main/java/com/viromedia/bridge/module/DynamicFromMap.java @@ -0,0 +1,116 @@ +package com.viromedia.bridge.module; + +/* + * 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. + */ + +import androidx.annotation.Nullable; +import androidx.core.util.Pools.SimplePool; + +import com.facebook.react.bridge.Dynamic; +import com.facebook.react.bridge.ReadableArray; +import com.facebook.react.bridge.ReadableMap; +import com.facebook.react.bridge.ReadableType; + +import java.util.Objects; + +/** Implementation of Dynamic wrapping a ReadableMap. */ +public class DynamicFromMap implements Dynamic { + private static final ThreadLocal> sPool = + new ThreadLocal>() { + @Override + protected SimplePool initialValue() { + return new SimplePool<>(10); + } + }; + + private @Nullable ReadableMap mMap; + private @Nullable String mName; + + // This is a pools object. Hide the constructor. + private DynamicFromMap() {} + + public static DynamicFromMap create(ReadableMap map, String name) { + DynamicFromMap dynamic = sPool.get().acquire(); + if (dynamic == null) { + dynamic = new DynamicFromMap(); + } + dynamic.mMap = map; + dynamic.mName = name; + return dynamic; + } + + @Override + public void recycle() { + mMap = null; + mName = null; + sPool.get().release(this); + } + + @Override + public boolean isNull() { + if (mMap == null || mName == null) { + throw new IllegalStateException("This dynamic value has been recycled"); + } + return mMap.isNull(mName); + } + + @Override + public boolean asBoolean() { + if (mMap == null || mName == null) { + throw new IllegalStateException("This dynamic value has been recycled"); + } + return mMap.getBoolean(mName); + } + + @Override + public double asDouble() { + if (mMap == null || mName == null) { + throw new IllegalStateException("This dynamic value has been recycled"); + } + return mMap.getDouble(mName); + } + + @Override + public int asInt() { + if (mMap == null || mName == null) { + throw new IllegalStateException("This dynamic value has been recycled"); + } + return mMap.getInt(mName); + } + + @Override + public String asString() { + if (mMap == null || mName == null) { + throw new IllegalStateException("This dynamic value has been recycled"); + } + return mMap.getString(mName); + } + + @Override + public ReadableArray asArray() { + if (mMap == null || mName == null) { + throw new IllegalStateException("This dynamic value has been recycled"); + } + return mMap.getArray(mName); + } + + @Override + public ReadableMap asMap() { + if (mMap == null || mName == null) { + throw new IllegalStateException("This dynamic value has been recycled"); + } + return Objects.requireNonNull(mMap.getMap(mName)); + } + + @Override + public ReadableType getType() { + if (mMap == null || mName == null) { + throw new IllegalStateException("This dynamic value has been recycled"); + } + return mMap.getType(mName); + } +} \ No newline at end of file