Skip to content

Commit 31d8a93

Browse files
piaskowykfacebook-github-bot
authored andcommitted
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. <img width="400" alt="Screenshot 2023-11-27 at 13 55 44" src="https://github.com/facebook/react-native/assets/36106620/04418291-8ce8-4bae-b16c-29a5c9f2ee52"> 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: #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
1 parent 05ed007 commit 31d8a93

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

packages/react-native/ReactAndroid/src/main/jni/react/fabric/Binding.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ class ReactNativeConfig;
3434
class Scheduler;
3535
class SurfaceHandlerBinding;
3636

37-
class Binding : public jni::HybridClass<Binding>,
37+
struct JBinding : public jni::JavaClass<JBinding> {
38+
constexpr static auto kJavaDescriptor = "Lcom/facebook/react/fabric/Binding;";
39+
};
40+
41+
class Binding : public jni::HybridClass<Binding, JBinding>,
3842
public SchedulerDelegate,
3943
public LayoutAnimationStatusDelegate {
4044
public:

packages/react-native/ReactAndroid/src/main/jni/react/fabric/JFabricUIManager.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ namespace facebook::react {
1313

1414
Binding* JFabricUIManager::getBinding() {
1515
static const auto bindingField =
16-
javaClassStatic()->getField<Binding::javaobject>("mBinding");
16+
javaClassStatic()->getField<JBinding::javaobject>("mBinding");
1717

18-
return getFieldValue(bindingField)->cthis();
18+
return jni::static_ref_cast<Binding::javaobject>(getFieldValue(bindingField))
19+
->cthis();
1920
}
2021
} // namespace facebook::react

0 commit comments

Comments
 (0)