Skip to content

feat(ios): Better handling for emitting navigation events #10757

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

Merged

Conversation

CatchABus
Copy link
Contributor

@CatchABus CatchABus commented Jul 2, 2025

PR Checklist

What is the current behavior?

Right now, we have Page navigation events handling inside iOS page ViewController to handle cases like back button navigation or swipe back navigation.
Unfortunately, the handling is quite messy with a couple of hackish solutions resulting in events being emitted when they shouldn't (e.g. @NathanWalker iOS 18 TabView navigation between frame that were already loaded once).

What is the new behavior?

This PR focuses on improving how these events are emitted and decouple TabView from nested Page logic. Navigation events are now safely emitted from page ViewController when needed.

Few things to note:

  • Added missing Frame navigatingTo event trigger for back button/swipe back navigations
  • Assign Frame's executing context during those navigations since the property is essential for blocking unexpected calls during the transition
  • Upon reusing a Frame, add it back to the Frame stack if it has a current entry
  • Use a common navigation controller delegate for all Frames and unset it when the app has no Frames left in the stack

Copy link

coderabbitai bot commented Jul 2, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes update the event-handling logic for tab navigation in iOS and its corresponding automated test. On the iOS side, the emission of the navigatingFrom event is deferred in specific tab bar scenarios to improve accuracy. The test is updated to explicitly listen for and synchronize with this event, ensuring correct sequencing.

Changes

File(s) Change Summary
apps/automated/src/ui/tab-view/tab-view-root-tests.ts Updated test to explicitly listen for and await the navigatingFrom event on the third tab's page; revised expected event arrays.
packages/core/ui/page/index.ios.ts Modified UIViewControllerImpl to defer navigatingFrom event emission in tab bar scenarios; unified variable naming.

Poem

In the warren of tabs, events hop with care,
A rabbit ensures each leap’s truly fair.
With iOS paws, we now wait and see—
NavigatingFrom fires, as synced as can be.
Tests now listen, tails held high,
For every event that hops right by! 🐇✨

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

nx-cloud bot commented Jul 2, 2025

View your CI Pipeline Execution ↗ for commit 378e39b

Command Status Duration Result
nx test apps-automated -c=ios ✅ Succeeded 2m 10s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded 1s View ↗

☁️ Nx Cloud last updated this comment at 2025-07-09 20:54:24 UTC

Copy link

nx-cloud bot commented Jul 2, 2025

View your CI Pipeline Execution ↗ for commit 9d16c0d.

Command Status Duration Result
nx run-many --target=test --configuration=ci --... ✅ Succeeded 1s View ↗

☁️ Nx Cloud last updated this comment at 2025-07-02 02:11:30 UTC

@CatchABus CatchABus marked this pull request as ready for review July 2, 2025 02:15
@CatchABus CatchABus changed the title fix(ios): TabView does not emit navigatingFrom in iOS 17 fix(ios): TabView does not emit page navigatingFrom in iOS 17 Jul 2, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/core/ui/page/index.ios.ts (1)

284-290: Correct implementation of deferred event emission.

The logic properly checks for the pending flag, cleans it up, and emits the navigatingFrom event with the correct isBack parameter. This addresses the iOS 17 tab lifecycle timing issue.

Consider using an undefined assignment instead of the delete operator for better performance:

-			delete this['_isPendingNavigatingFrom'];
+			this['_isPendingNavigatingFrom'] = undefined;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 32f2dd1 and 9d16c0d.

📒 Files selected for processing (2)
  • apps/automated/src/ui/tab-view/tab-view-root-tests.ts (2 hunks)
  • packages/core/ui/page/index.ios.ts (2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/core/ui/page/index.ios.ts

[error] 286-286: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test-android
🔇 Additional comments (6)
apps/automated/src/ui/tab-view/tab-view-root-tests.ts (4)

2-2: LGTM! Import addition is necessary for event handling.

The addition of EventData import is required for the new event handler functionality.


143-148: Good synchronization mechanism for deferred events.

The test correctly implements synchronization for the navigatingFrom event that is now deferred in the iOS implementation. The boolean flag and event handler pattern ensures the test waits for the event to fire.


154-156: Proper event listener setup and synchronization.

The test correctly attaches the event listener before the tab switch and waits for the event to occur, which aligns with the deferred event emission behavior implemented in the iOS core.


158-158: Expected events updated to reflect deferred behavior.

The expected events array correctly includes the navigatingFrom event for the third tab's page, matching the new deferred emission behavior.

packages/core/ui/page/index.ios.ts (2)

257-263: Well-implemented deferral logic for iOS 17 tab issue.

The logic correctly identifies tab bar controller scenarios where the navigatingFrom event needs to be deferred. The condition checks ensure the deferral only happens when necessary (tab switching scenarios).


272-272: Good variable naming consistency.

Unifying the variable name from page to owner improves consistency with the rest of the method.

@CatchABus CatchABus marked this pull request as draft July 2, 2025 02:23
@CatchABus CatchABus changed the title fix(ios): TabView does not emit page navigatingFrom in iOS 17 feat(ios): Better handling for emitting navigation events Jul 9, 2025
@CatchABus CatchABus marked this pull request as ready for review July 11, 2025 20:53
@NathanWalker NathanWalker merged commit bca3452 into NativeScript:main Jul 11, 2025
4 checks passed
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