Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
fix: simplify logic for determining forward/backward transition in ma…
Browse files Browse the repository at this point in the history
…in activity
  • Loading branch information
itsaky committed Jul 16, 2023
1 parent acf6973 commit 3c8c4f7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,7 @@ class MainActivity : LimitlessIDEActivity() {
MaterialSharedAxis.Y
}

val isForward = when {
previous == SCREEN_MAIN && screen == SCREEN_TEMPLATE_LIST -> true
previous == SCREEN_TEMPLATE_LIST && screen == SCREEN_TEMPLATE_DETAILS -> true
previous == SCREEN_TEMPLATE_DETAILS && screen == SCREEN_TEMPLATE_LIST -> false
previous == SCREEN_TEMPLATE_DETAILS && screen == SCREEN_MAIN -> false
previous == SCREEN_TEMPLATE_LIST && screen == SCREEN_MAIN -> false
else -> throw IllegalStateException(
"Invalid screen states. Previous: $previous Current: $screen"
)
}
val isForward = (screen ?: 0) - previous == 1

val transition = MaterialSharedAxis(axis, isForward)
transition.doOnEnd {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ class MainViewModel : ViewModel() {

companion object {

// main screens
// The values assigned to these variables reflect the order in which the screens are presented
// to the user. A screen with a lower value is displayed before a screen with a higher value.
// For example, SCREEN_MAIN is the first screen visible to the user, followed by SCREEN_TEMPLATE_LIST,
// and then SCREEN_TEMPLATE_DETAILS.
//
// These values are used as unique identifiers for the screens as well as for determining whether
// the screen change transition should be forward or backward.
const val SCREEN_MAIN = 0
const val SCREEN_TEMPLATE_LIST = 1
const val SCREEN_TEMPLATE_DETAILS = 2
Expand Down

0 comments on commit 3c8c4f7

Please sign in to comment.