Skip to content

feat: option to add nitro views #805

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

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

Juozas-Petkelis
Copy link

Summary

  • Introduces the option to add a Nitro View Component when scaffolding a new library with create-react-native-library.

    Nitro View selection during setup Nitro view selection
  • Updates the example app generation for nitro modules to set the minimum iOS deployment target to 16.0 for both the project and its native dependencies. This change addresses an Xcode 12.2 compatibility issue where Nitro modules failed to build with the previous default target of iOS 15.1.

  • Updated the fallback Nitro Modules version to 0.25.2

Test plan

  1. clone branch
  2. create new library with bin/create-react-native-library
  3. generate nitrogen yarn nitro-codegen and build example app for both platforms
Example App
iOS Screenshot Android Screenshot
iOS Screenshot Android Screenshot

@Juozas-Petkelis Juozas-Petkelis requested a review from atlj March 28, 2025 14:49
@satya164
Copy link
Member

Hey @Juozas-Petkelis , remember to add the template to the CI matrix

@satya164 satya164 force-pushed the main branch 6 times, most recently from 0b45375 to 7799977 Compare April 7, 2025 20:23
@mrousavy
Copy link
Contributor

mrousavy commented Jun 5, 2025

Super nice!

Copy link
Member

@satya164 satya164 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Juozas-Petkelis

Sorry for the delay in the review. Would you be able to fix the conflicts with main?

Comment on lines +302 to +370
// nitro modules on xcode 16.2 requires ios 16 version because of the bug https://github.com/swiftlang/swift/issues/77909
// full thread in https://github.com/mrousavy/nitro/issues/422
if (
config.project.viewConfig === 'nitro-view' ||
config.project.moduleConfig === 'nitro-modules'
) {
const newTargetVersion = 16.0;

const podfile = await fs.readFile(
path.join(directory, 'ios', 'Podfile'),
'utf8'
);

const postInstallLine = 'post_install do |installer|';
// set pods deployement min version
const podVersionOverride = `
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '${newTargetVersion}'
end
end
`;

const insertionIndex = podfile.indexOf(postInstallLine);

if (insertionIndex !== -1) {
const endOfMarkerLineIndex = podfile.indexOf('\n', insertionIndex);

if (endOfMarkerLineIndex !== -1) {
const updatedPodfileContent =
podfile.slice(0, endOfMarkerLineIndex) +
podVersionOverride +
podfile.slice(endOfMarkerLineIndex);

await fs.writeFile(
path.join(directory, 'ios', 'Podfile'),
updatedPodfileContent
);
}
}

// set project deployement min version
const project = await fs.readFile(
path.join(
directory,
`ios/${config.project.name}Example.xcodeproj`,
'project.pbxproj'
),
'utf8'
);

// match whole IPHONEOS_DEPLOYMENT_TARGET line
const deployementLineRegex =
/^(\s*)IPHONEOS_DEPLOYMENT_TARGET\s*=\s*[^;]+;$/gm;
const replacementPattern = `$1IPHONEOS_DEPLOYMENT_TARGET = ${newTargetVersion};`;
const updatedContent = project.replace(
deployementLineRegex,
replacementPattern
);

await fs.writeFile(
path.join(
directory,
`ios/${config.project.name}Example.xcodeproj`,
'project.pbxproj'
),
updatedContent
);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather not have a workaround for old code. we're testing on newer xcode version so this won't be tested properly. Lets remove this.

@@ -18,13 +18,14 @@ yarn
```

> Since the project relies on Yarn workspaces, you cannot use [`npm`](https://github.com/npm/cli) for development.
<% if (project.moduleConfig === 'nitro-modules') { -%>
> <% if (project.moduleConfig === 'nitro-modules' || project.viewConfig === 'nitro-view') { -%>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the > intentional?

Comment on lines +37 to 39

<% } -%>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will add 2 new lines after processing so we should remove this new line - or add a new line above this block and remove the one after.

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.

3 participants