Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: supporting apps that have enabled New Architecture #481

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

rxnveer
Copy link
Contributor

@rxnveer rxnveer commented Oct 28, 2024

Description

This PR is intended to start a discussion about how we could support apps that have enabled React Native's New Architecture (without upgrading maplibre-react-native itself to the New Architecture just yet, which is significantly more work). It includes some quick changes to demonstrate the quirks I found and to render a basic MapView example - definitely not a complete solution! 😄

I was able to render a simple MapView without any additional changes on iOS (the 'Interop Layer' does all of the work and was updated as of RN 0.74 to be enabled by default). The docs say that "it will work with every component that has not migrated yet" (reactwg/react-native-new-architecture#175), but it does not work in all cases unfortunately, and getting a MapView to render on Android required additional changes:

  1. Accessing Native Modules - I'm not clear on the reasons why, but on Android the MapLibreGL module and it's methods could not be accessed in the regular way, I had to use the underlying RCTMLNModule (not an ideal solution but it works for the purposes of this demo)
  2. Replacing UIManagerModule - this discussion about the use of UIManager in the New Architecture explains that "UIManagerModule is deprecated in favour of UIManager in the New Architecture.". UIManagerModule is currently used on Android in the AbstractedEventEmitter component - replacing it with the new UIManager (via UIManagerHelper) was required to render a MapView

To see the example, run the expo-app and from the home screen navigate to Map > Show Map.

Feedback and suggestions for next steps are very welcome!

Checklist

  • I have tested this on a device/simulator for each compatible OS
  • I formatted JS and TS files with running yarn lint:eslint:fix in the root folder
  • I have run tests via yarn test in the root folder
  • I updated the documentation with running yarn generate in the root folder
  • I mentioned this change in CHANGELOG.md
  • I added/updated a sample (/packages/examples)

@KiwiKilian
Copy link
Contributor

KiwiKilian commented Oct 29, 2024

Each of the Modules in android/rctmln/src/main/java/com/maplibre/rctmln/modules has a REACT_CLASS string with RCT prefix (example). Did you try dropping the RCT prefixes? This could fixe the all the module problems.

Can't find much on this @ReactModule annotation, but on iOS RCT prefix is stripped automatically.

@KiwiKilian
Copy link
Contributor

And thank you very much for taking the time to investigate!

@rxnveer
Copy link
Contributor Author

rxnveer commented Oct 29, 2024

I did try that yes (dropping the RCT prefix in the REACT_CLASS) but unfortunately I still couldn't access the module in the regular way after 😞. I thought there was probably some sensitivity around these names that I was not familiar with, good to know about the iOS logic!

No worries at all and thank you very much for taking the time to collaborate! Hopefully together we can find a good solution and unlock New Architecture apps for everyone! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants