Skip to content

Commit 99b328b

Browse files
mrousavymeta-codesync[bot]
authored andcommitted
feat: Add StateWrapper to fbjni typings (#55288)
Summary: In [Nitro](https://nitro.margelo.com), we support creating views using Fabric's view system. We use `StateWrapper` (and `StateWrapperImpl`) from C++. While we can use `react::StateWrapperImpl` from C++, we had to define `StateWrapper` ourselves ([see `JStateWrapper.hpp`](https://github.com/mrousavy/nitro/blob/main/packages/react-native-nitro-modules/android/src/main/cpp/views/JStateWrapper.hpp)) `StateWrapperImpl` inherits from `StateWrapper` in Kotlin, but the same inheritance is not reflected in C++ via fbjni. To fix this, we did some dirty static downcasting, which is not safe to do but worked. ## Changelog: [ANDROID] [ADDED] - Add `StateWrapper` to C++ fbjni types <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests Pull Request resolved: #55288 Test Plan: When you have a `StateWrapperImpl` in Kotlin, pass that to C++ via fbjni using the `jni::alias_ref<react::StateWrapper>` type. (Example; `SimpleViewManager.updateState(...)` gives you a `StateWrapper`) Then try downcasting via `jni::dynamic_ref_cast<react::StateWrapperImpl>(...)`. If both works, this PR works. Reviewed By: cipolleschi Differential Revision: D91468294 Pulled By: javache fbshipit-source-id: 7d5a04ad486c4f6f776020855468f87d0fd0fff0
1 parent 680bd5a commit 99b328b

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
#include <react/common/mapbuffer/JReadableMapBuffer.h>
1212
#include <react/jni/ReadableNativeMap.h>
1313
#include <react/renderer/core/State.h>
14+
#include <react/uimanager/StateWrapper.h>
1415

1516
namespace facebook::react {
1617

1718
class Instance;
1819

19-
class StateWrapperImpl : public jni::HybridClass<StateWrapperImpl> {
20+
class StateWrapperImpl : public jni::HybridClass<StateWrapperImpl, StateWrapper> {
2021
public:
2122
constexpr static const char *const kJavaDescriptor = "Lcom/facebook/react/fabric/StateWrapperImpl;";
2223
constexpr static auto StateWrapperImplJavaDescriptor = "com/facebook/react/fabric/StateWrapperImpl";
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
#include <fbjni/fbjni.h>
11+
12+
namespace facebook::react {
13+
14+
class StateWrapper : public jni::HybridClass<StateWrapper> {
15+
public:
16+
constexpr static const char *const kJavaDescriptor = "Lcom/facebook/react/uimanager/StateWrapper;";
17+
};
18+
19+
} // namespace facebook::react

0 commit comments

Comments
 (0)