fix: allow Object params to correctly reflect the native code gen#335
Open
hurali97 wants to merge 4 commits into
Open
fix: allow Object params to correctly reflect the native code gen#335hurali97 wants to merge 4 commits into
hurali97 wants to merge 4 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the navigation code generators so that TypeScript “model” (object) types referenced by the spec are emitted as concrete types (e.g. UserType) in the generated Swift/Kotlin delegate + Kotlin module signatures, instead of falling back to Any.
Changes:
- Pass discovered
modelTypeNamesfromgenerateNavigationModels()into the iOS/Android generators. - Extend Swift/Kotlin TS-type mapping to treat known model types as first-class types (including optional handling).
- Add unit tests covering model-type mapping for Swift and Kotlin, and ship a changeset.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/cli/src/navigation/runner.ts | Plumbs modelTypeNames into Swift/Kotlin generator entrypoints. |
| packages/cli/src/navigation/generators/ios.ts | Maps known model types to Swift types in generated delegate signatures. |
| packages/cli/src/navigation/generators/android.ts | Maps known model types to Kotlin types in generated delegate + module signatures. |
| packages/cli/src/navigation/tests/generators.test.ts | Adds coverage for Swift/Kotlin model-type mapping (incl. optional). |
| .changeset/bright-insects-pay.md | Patch release note for the CLI change. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 18 out of 19 changed files in this pull request and generated 4 comments.
Comments suppressed due to low confidence (1)
packages/cli/src/navigation/generators/models.ts:310
mapReadableMapFieldExpressionforce-unwraps values (!!) and doesn't account forModelFieldDefinition.optional, so generated conversions can throw when optional fields are absent/null. It also assumes every non-primitive field is another model (getMap(...)!!+to${fieldType}), which will break for arrays/unions. Consider generating nullable accessors for optional fields and explicitly handling unsupported field shapes (or falling back toAny).
if (fieldType === 'string') {
return `${mapName}.getString("${fieldName}")!!`;
}
if (fieldType === 'number') {
return `${mapName}.getDouble("${fieldName}")`;
Comment on lines
+237
to
+241
| return `@objc public extension ${modelName} { | ||
| static func fromDictionary(_ value: NSDictionary) -> ${modelName} { | ||
| return ${modelName}(${args}) | ||
| } | ||
| }`; |
Comment on lines
+251
to
+255
| const valueAccess = `value["${fieldName}"]`; | ||
| if (fieldType === 'string') { | ||
| return `${valueAccess} as! String`; | ||
| } | ||
| if (fieldType === 'number') { |
Comment on lines
149
to
152
| const { name, params, returnType } = method; | ||
|
|
||
| let signature = `- (${mapTsTypeToObjC(returnType)})${name}`; | ||
| let signature = `- (${mapTsTypeToObjC(returnType, false, options)})${name}`; | ||
| if (params.length > 0) { |
Comment on lines
140
to
144
| const signature = ` @ReactMethod\n override fun ${method.name}(${params})${ | ||
| method.returnType === 'void' | ||
| ? '' | ||
| : `: ${mapTsTypeToKotlin(method.returnType, false)}` | ||
| : `: ${mapTsTypeToKotlin(method.returnType, false, options, 'module')}` | ||
| }`; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #312
Test plan
Object types now correctly reflect in the
BrownfieldNavigationDelegate:Schema:
Kotlin:
Swift: