Skip to content
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

Space Switching Back Navigation #6877

Merged
merged 31 commits into from
Aug 26, 2022

Conversation

ericdecanini
Copy link
Contributor

@ericdecanini ericdecanini commented Aug 18, 2022

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

Adds a space backstack that gets used when navigating back with the android back button.

Motivation and context

Closes #6751

Screenshots / GIFs

goingback.mp4

Tests

  • Navigate through spaces and go back using the device back button. See that you can go back and forward seamlessly
  • See that going back when in All Chats minimises the app

Tested devices

  • Physical
  • Emulator
  • OS version(s): Android 12

Checklist

@ericdecanini ericdecanini requested review from a team, ganfra, fedrunov and amshakal and removed request for a team August 18, 2022 15:33
@ericdecanini ericdecanini marked this pull request as ready for review August 18, 2022 15:34
@ericdecanini ericdecanini changed the title Space Switching Back Navigation and Space History Header Space Switching Back Navigation Aug 19, 2022
@ericdecanini ericdecanini requested review from ouchadam and removed request for ganfra and amshakal August 19, 2022 12:29
…ew-layout-debug

# Conflicts:
#	vector/src/test/java/im/vector/app/features/navigation/DefaultNavigatorTest.kt
@ouchadam
Copy link
Contributor

to double check the behaviour, if I go into a inner space, leave the app and return, do I return to the inner space selected and if so, does pressing back exit the app or move up a space level?

vectorPreferences.getSpaceBackstack().toMutableList().apply {
val poppedSpaceId = removeLast()
vectorPreferences.setSpaceBackstack(this)
return poppedSpaceId
Copy link
Contributor

Choose a reason for hiding this comment

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

nit - having the return within the apply feels a little odd to me, I would expect apply usages to augment the receiver but here we have a side effect and exit point

this might be a case where avoiding the scope could be simpler?

val backstack = vectorPreferences.getSpaceBackstack().toMutableList()
val poppedSpaceId = backstack.removeLast()
vectorPreferences.setSpaceBackstack(backstack)
return poppedSpaceId

or with the side effect declared with an also

val backstack = vectorPreferences.getSpaceBackstack().toMutableList()
return backstack.removeLast().also { vectorPreferences.setSpaceBackstack(backstack) }

super minor opinion for me, will leave up to you!

Copy link
Contributor

@fedrunov fedrunov left a comment

Choose a reason for hiding this comment

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

LGTM

true
} else {
} catch (e: NoSuchElementException) {
Copy link
Contributor

Choose a reason for hiding this comment

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

which part of the api throws NoSuchElementException? if we're using exceptions for control flow we'll probably want to document it in the SpaceStateHandler api and add a unit test case

ideally we wouldn't rely on exceptions by catching and modelling the state within our own domain, unless this is an exceptional case out of our control 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It happens in SpaceStateHandlerImpl:144 (val poppedSpaceId = (spaceBackstack).removeLast)

The reason I wanted to use exception here instead of null is because the space backstack can include a valid null which signifies the "All Chats" space, thus we can't use null as a fail option

Copy link
Contributor

@ouchadam ouchadam Aug 22, 2022

Choose a reason for hiding this comment

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

my concern with using the exception is that it reads as if an error has occurred when in reality the user is at the top of the backstack (an empty stack), there's the risk that a NoSuchElementException could be thrown somewhere else and we unexpectedly catch it, causing swallowed errors 🤔

a named guard function provides extra context in relation to the navigation and allows the use of valid nulls

fun onBackPressed() = when {
  spaceStateHandler.isRoot() -> false
  else -> {
        val lastSpace = spaceStateHandler.popSpaceBackstack()
        spaceStateHandler.setCurrentSpace(lastSpace, isForwardNavigation = false)
        true
  }
}

private fun SpaceStateHandler.isRoot() = getBackstack().isEmpty()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion. Changes made

Debug Icon UX Improvements & Addition in New Layout
@ericdecanini ericdecanini requested a review from ouchadam August 22, 2022 12:53
…ayout-navigation

# Conflicts:
#	vector/src/main/java/im/vector/app/features/home/HomeActivity.kt
#	vector/src/main/java/im/vector/app/features/home/NewHomeDetailFragment.kt
…ayout-navigation

# Conflicts:
#	vector/src/main/java/im/vector/app/features/home/NewHomeDetailFragment.kt
…ayout-navigation

# Conflicts:
#	vector/src/main/java/im/vector/app/features/home/NewHomeDetailFragment.kt
…ayout-navigation

# Conflicts:
#	vector/src/main/java/im/vector/app/features/spaces/NewSpaceSummaryController.kt
@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

38.1% 38.1% Coverage
0.0% 0.0% Duplication

@ericdecanini ericdecanini merged commit b5debe9 into develop Aug 26, 2022
@ericdecanini ericdecanini deleted the feature/eric/new-layout-navigation branch August 26, 2022 15:40
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.

Space Switching: Back Navigation
3 participants