Skip to content

feat: Add StateWrapper to fbjni typings#55288

Closed
mrousavy wants to merge 1 commit intofacebook:mainfrom
mrousavy:feat/jstatewrapper-inheritance
Closed

feat: Add StateWrapper to fbjni typings#55288
mrousavy wants to merge 1 commit intofacebook:mainfrom
mrousavy:feat/jstatewrapper-inheritance

Conversation

@mrousavy
Copy link
Contributor

@mrousavy mrousavy commented Jan 23, 2026

Summary:

In Nitro, 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)

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

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.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 23, 2026
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Jan 23, 2026
@meta-codesync
Copy link

meta-codesync bot commented Jan 26, 2026

@javache has imported this pull request. If you are a Meta employee, you can view this in D91468294.

@meta-codesync meta-codesync bot closed this in 99b328b Jan 26, 2026
@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Jan 26, 2026
@meta-codesync
Copy link

meta-codesync bot commented Jan 26, 2026

@javache merged this pull request in 99b328b.

@mrousavy
Copy link
Contributor Author

Thanks!

chrfalch added a commit that referenced this pull request Mar 25, 2026
build.gradle.kts exports src/main/jni/react/fabric → react/fabric/ in the prefab headers, which includes StateWrapperImpl.h. That header does #include <react/uimanager/StateWrapper.h>, but src/main/jni/react/uimanager is not in the prefab export list — so the header is simply missing from the AAR.

This was introduced in #55288 where they modified StateWrapperImpl.h to inherit from StateWrapper and added the #include on StateWrapper.h.

This has caused Expo's nightlies to break due to the missing header file in the prefabs:

- Internally (when RN builds itself): Works fine because all JNI source dirs are on the include path
- Externally (when consumers use the published AAR): StateWrapperImpl.h is included in the prefab, it references <react/uimanager/StateWrapper.h>, but that header doesn't exist in the prefab package

This commit fixes the above problem by including `src/main/jni/react/uimanager` in the prefab.

I have tested and verified this by running this in the root of the repo:

```
./gradlew :packages:react-native:ReactAndroid:preparePrefab
ls packages/react-native/ReactAndroid/build/prefab-headers/reactnative/react/uimanager/
```

Before the fix the uimanager folder was not found, with the fix it exists and contains the following files: ComponentNameResolverBinding.h  StateWrapper.h  UIConstantsProviderBinding.h

There might be an issue with exporting these files in addition to the missing StateWrapper.h - but it seems like this is an issue with other folders in the jni / prefab - everything in a folder is exported when included for prefab.
meta-codesync bot pushed a commit that referenced this pull request Mar 25, 2026
…56215)

Summary:
When testing React Native nightlies, we got the following error from `react-android-0.86.0-nightly-20260325-d1809f0aa-SNAPSHOT-release`:

```
StateWrapperImpl.h:14:10: fatal error: 'react/uimanager/StateWrapper.h' file not found
```

The reason is that build.gradle.kts exports src/main/jni/react/fabric → react/fabric/ in the prefab headers, which includes StateWrapperImpl.h. That header does #include <react/uimanager/StateWrapper.h>, but src/main/jni/react/uimanager is not in the prefab export list — so the header is missing from the AAR.

This was introduced in #55288 where they modified StateWrapperImpl.h to inherit from StateWrapper and added the #include on StateWrapper.h.

This has caused Expo's nightlies to break due to the missing header file in the prefabs:

- Internally (when RN builds itself): Works fine because all JNI source dirs are on the include path
- Externally (when consumers use the published AAR): StateWrapperImpl.h is included in the prefab, it references <react/uimanager/StateWrapper.h>, but that header doesn't exist in the prefab package

## Fix

This commit fixes the above problem by including `src/main/jni/react/uimanager` in the prefab.

## Changelog
[Internal] -

Pull Request resolved: #56215

Test Plan:
I have tested and verified this by running this in the root of the repo:

```
./gradlew :packages:react-native:ReactAndroid:preparePrefab
ls packages/react-native/ReactAndroid/build/prefab-headers/reactnative/react/uimanager/
```

Before the fix the uimanager folder was not found, with the fix it exists and contains the following files: ComponentNameResolverBinding.h  StateWrapper.h  UIConstantsProviderBinding.h

## Changelog:

[ANDROID] [FIXED] - Fixed missing StateWrapper.h header in prefabs

## Potential Issues

There might be an issue with exporting these files in addition to the missing StateWrapper.h - but it seems like this is an issue with other folders in the jni / prefab - everything in a folder is exported when included for prefab.

Reviewed By: alanleedev

Differential Revision: D98124025

Pulled By: cipolleschi

fbshipit-source-id: c8ae35e77652b90477d17ea8cab48ce3ee84d067
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants