From 92254f93803f8e03cb5dfed803f4bacd76082d1a Mon Sep 17 00:00:00 2001 From: Krzysztof Piaskowy Date: Thu, 30 Nov 2023 04:32:16 -0800 Subject: [PATCH] Fix Binding JNI type (#41657) Summary: New implementation: This PR adds cast from interface Binding to BindingImpl class. Previous implementation: The changes made in this PR make the `mBinding` field of `FabricUIManager` visible for JNI. Without these changes, calling the method `JFabricUIManager::getBinding()` would result in an error. Screenshot 2023-11-27 at 13 55 44 In the `react-native-reanimated` library, we utilize `JFabricUIManager::getBinding()`, and we have noticed this issue since version 0.73. This isn't perfect solution, but I'm not certain which change in RN or FBJNI is the source of the problem. If there are any alternative solutions worth considering, I am open to discussing them. Usage of `getBinding()` in Reanimated: https://github.com/software-mansion/react-native-reanimated/blob/main/android/src/main/cpp/NativeProxy.cpp#L57 ## Changelog: [ANDROID] [FIXED] - Fix type for unrecognisable field mBinding Pull Request resolved: https://github.com/facebook/react-native/pull/41657 Test Plan: Just call `JFabricUIManager::getBinding` method (https://github.com/facebook/react-native/blob/v0.73.0-rc.5/packages/react-native/ReactAndroid/src/main/jni/react/fabric/JFabricUIManager.cpp#L14) or run app with repro: https://github.com/piaskowyk/missing-mBinding-repro after the app lunch you will receive error from above screenshot. Co-author: tomekzaw Reviewed By: NickGerleman Differential Revision: D51661873 Pulled By: javache fbshipit-source-id: 1891c36bf25c503ebc9b0501211df03be6f74115 --- .../ReactAndroid/src/main/jni/react/fabric/Binding.h | 6 +++++- .../src/main/jni/react/fabric/JFabricUIManager.cpp | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/Binding.h b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/Binding.h index d4266bcab6f..9eaa1ee7670 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/Binding.h +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/Binding.h @@ -34,7 +34,11 @@ class ReactNativeConfig; class Scheduler; class SurfaceHandlerBinding; -class Binding : public jni::HybridClass, +struct JBinding : public jni::JavaClass { + constexpr static auto kJavaDescriptor = "Lcom/facebook/react/fabric/Binding;"; +}; + +class Binding : public jni::HybridClass, public SchedulerDelegate, public LayoutAnimationStatusDelegate { public: diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/JFabricUIManager.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/JFabricUIManager.cpp index a2ccdbf5d57..48326b97c26 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/JFabricUIManager.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/JFabricUIManager.cpp @@ -13,8 +13,9 @@ namespace facebook::react { Binding* JFabricUIManager::getBinding() { static const auto bindingField = - javaClassStatic()->getField("mBinding"); + javaClassStatic()->getField("mBinding"); - return getFieldValue(bindingField)->cthis(); + return jni::static_ref_cast(getFieldValue(bindingField)) + ->cthis(); } } // namespace facebook::react