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
Draft: Packaging guide for iOS #3861
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for react-native ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Hi @michalchudziak, thanks for this guide, but I have a few questions:
|
Begin by generating a fresh React Native project: | ||
|
||
```bash | ||
npx react-native init HighScores2048 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
npx react-native init HighScores2048 | |
npx react-native@latest init HighScores2048 |
Hey @cipolleschi! The PR isn't finished, which is why it's in a draft state. I haven't yet focused on fixing the linting issues and testing the actual preview (it's certainly not ready for merging yet). Regarding point 3, I see significant value in the
I believe it aligns well with specific code organization patterns and organizational structures. We're definitely keeping the new architecture in mind, and we want to ensure we consider it before finalizing this guide. Unless I'm mistaken, I believe that moving the generated files can be managed with a post-install script. I'm considering adding this information to the guide, alongside the Swift guide. Do you think that if we address this, there would be room for such a guide in the docs? Maybe in the advanced section? |
|
||
## Creating a 2048 High Scores Package | ||
|
||
In this guide, you'll craft a High Scores screen, similar to the one made in the [guide to integrate with native apps](https://reactnative.dev/docs/integration-with-existing-apps?language=objc). You'll package it as a standalone `.xcframework` file. Afterward, you can use it directly in a native app like any native library, eliminating the need for installing any JavaScript dependencies. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if I like to use only a certain component not a whole "screen"? I understand the doc "how can I integrate a component" so a single view not exactly whole screen. I would like to see guidance for this case + the whole screen if the implementation paths are different for them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The guide covers that case, but perhaps we should make it more explicit. Simply register the component in AppDelegate, and you should be good to go. The guide how to export a UIView instance, not a ViewController or anything that would make it work only as a screen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The guide how to export a UIView instance, not a ViewController
- perhaps I misunderstood sth but I believe we want to export RN code to work in XCode project not UIView into RN project.
|
||
### Starting a New React Native App | ||
|
||
Begin by generating a fresh React Native project: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do I need to create a whole project if it is said we can integrate components? I would like to see explanation if this is the only way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. In that case we can register multiple root views and duplicate the binding files. I think it would be good to explain that explicitly in the docs tho.
AppRegistry.registerComponent('HighScores', () => HighScores); | ||
``` | ||
|
||
Finally, modify the code in `AppDelegate.mm` so it references the correct component. Also, feed mocked data to the view for development testing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not noticed when you created an iOS project. Besides, you assume there is AppDelegate
. Not sure about ObjC but using Swift there is more likely you see SceneDelegate
and no AppDelegate
. The description seems to be incomplete.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm reusing the project generated by the RN template, I haven't accounted for creating a fresh project form the scratch. Also it only serves as a playground, so I don't consider it crucial for the whole integration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But wait, we would like to use RN components inside MY OWN XCODE PROJECT. I understand we need to create a framework using RN project to finally use it inside XCode project. I miss more explicit explanation what is the goal and steps to achieve this.
@michalchudziak I agree that XCFrameworks can bring benefit, but we can have this page in the official documentation, unfortunately. This can make for an amazing post in your company blogpost, but for the official documentation we want to have something that is battle-tested and work in all the scenarios, including the New Architecture, and that integrates well with the current tooling (e.g. autolinking).
Also considering that now we can build dependencies with |
|
||
### Setting Up a New Package Target | ||
|
||
Now, create a separate Xcode target to build our `.xcframework` package. Open the `ios/HighScores2048.workspace` file. In Xcode, navigate to the targets section and select **Add new target (+)**. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You create in in Xcode (your XCode project) or this is a RN project's iOS part? Why do you create a framework? It is said we will integrate RN code in to XCode project. The vast majority of cases user will have an XCode app project not a framework. There is no explanation why you do so.
MY goal and understanding:
Integrate some RN components into my own standalone XCode app project. I do not see this here.
@cipolleschi I completely understand your point. Just to be clear, it does work with auto-linking without any issues. The change to the app delegate is not essential for the packaging process; it's solely about changing the name to demonstrate the ability to have multiple root views. In fact, AppDelegate is not used in this process at all. I also think that achieving support for new architecture is possible with minimal overhead (at least in a simple setup), as described in the comment above. Also, I can't fully agree with the |
|
||
![Screenshot](/docs/assets/PackagingCreateNewTarget.png) | ||
|
||
If done correctly, you'll see a `HighScore2048Module` folder on the left sidebar and a new yellow suitcase icon in the targets section. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typeo in name of the module (missing s
). Should be: HighScores2048Module
|
||
![Screenshot](/docs/assets/PackagingAddNewTarget.png) | ||
|
||
From the options, pick `Framework` and name it **HighScore2048Module**. Ensure the **Embed in Application** option remains off. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typeo in name of the module (missing s
). Should be: HighScores2048Module
This PR introduces a comprehensive guide on packaging React Native modules as
.framework
for iOS:The goal of this new documentation is to equip developers with the knowledge needed for seamless integration of React Native modules into native iOS projects.