Skip to content

fix: allow Object params to correctly reflect the native code gen#335

Open
hurali97 wants to merge 4 commits into
mainfrom
fix/issue-312
Open

fix: allow Object params to correctly reflect the native code gen#335
hurali97 wants to merge 4 commits into
mainfrom
fix/issue-312

Conversation

@hurali97
Copy link
Copy Markdown
Member

@hurali97 hurali97 commented May 14, 2026

Summary

Fixes #312

Test plan

Object types now correctly reflect in the BrownfieldNavigationDelegate:

Schema:

type UserType = {
  id: string;
  name: string;
  email: string;
};

export interface BrownfieldNavigationSpec {
  /**
   * Navigate to the native settings screen
   */
  navigateToSettings(user: UserType): void;

  /**
   * Navigate to the native referrals screen
   * @param userId - The user's unique identifier
   */
  navigateToReferrals(userId: string): void;
}

Kotlin:

interface BrownfieldNavigationDelegate {
  fun navigateToSettings(user: UserType)
  fun navigateToReferrals(userId: String)
}

Swift:

@objc public protocol BrownfieldNavigationDelegate: AnyObject {
    @objc func navigateToSettings(_ user: UserType)
    @objc func navigateToReferrals(_ userId: String)
}

@hurali97 hurali97 marked this pull request as ready for review May 14, 2026 09:18
Copilot AI review requested due to automatic review settings May 14, 2026 09:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 modelTypeNames from generateNavigationModels() 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.

Comment thread packages/cli/src/navigation/generators/ios.ts
@hurali97 hurali97 marked this pull request as draft May 15, 2026 04:17
@hurali97 hurali97 marked this pull request as ready for review May 15, 2026 08:28
@hurali97 hurali97 requested a review from Copilot May 15, 2026 08:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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

  • mapReadableMapFieldExpression force-unwraps values (!!) and doesn't account for ModelFieldDefinition.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 to Any).
  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')}`
}`;
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.

Brownfield navigation: Object params are generated as Any in native code

2 participants