-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Sample] Hook up back button on Android (#459)
- Loading branch information
1 parent
9158e35
commit c3633e9
Showing
4 changed files
with
43 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
sample/shared/src/commonMain/kotlin/dev/chrisbanes/haze/sample/Navigator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2024, Christopher Banes and the Haze project contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package dev.chrisbanes.haze.sample | ||
|
||
import androidx.compose.runtime.mutableStateListOf | ||
|
||
class Navigator { | ||
|
||
private val backStack = mutableStateListOf<Sample>() | ||
|
||
val currentSample: Sample? | ||
get() = backStack.lastOrNull() | ||
|
||
fun navigateTo(sample: Sample) { | ||
backStack.add(sample) | ||
} | ||
|
||
fun navigateUp() { | ||
if (backStack.isNotEmpty()) { | ||
backStack.removeLast() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters