[FR]: Use navigateUp() Instead of popBackStack() for Toolbar Up Button Click

Open
#1,817 3 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
android, kotlin
Domain
mobile

Research direction

Start in NiaNavHost and trace the onBackClick callbacks passed to the screens, including the topicScreen example. Compare the toolbar Up behavior with the linked Compose navigation principles, then verify that the affected screens use the intended navigation callback consistently and that existing navigation behavior remains intact.

Written by the indexing model from the issue text.

Description

enhancement
Is there an existing issue for this?
  • I have searched the existing issues
Describe the problem

I recently reviewed the principles of navigation in Compose. From what I understand, the top app bar’s “Up” navigation button should call navController.navigateUp() rather than popBackStack(), which is intended for handling the device’s back press.

However, in the NiaNavHost, the onBackClick callbacks in various screens are currently using popBackStack(). My understanding is that onBackClick is hoisted to handle the toolbar’s “Up” button clicks in these screens.

The current implementation using popBackStack() works as expected. However, I would like to understand whether using navigateUp() might be a more appropriate approach.

Describe the solution

Current

topicScreen(
    showBackButton = true,
    onBackClick = navController::popBackStack,
    onTopicClick = navController::navigateToTopic,
)

Proposed

topicScreen(
    showBackButton = true,
    onNavigateUp = navController::navigateUp,
    onTopicClick = navController::navigateToTopic,
)
Additional context

No response

Code of Conduct
  • I agree to follow this project's Code of Conduct
Dominant language
Kotlin
Stars
22.1k
Forks
4.7k
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from android/nowinandroid

All issues in android/nowinandroid

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.