This file contains hidden or 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
sealed class RootRouting { | |
object LoggedOut: RootRouting() | |
data class LoggedIn(val user: User): RootRouting() | |
} | |
sealed class LoggedInRouting { | |
object News : LoggedInRouting() | |
object Gallery : LoggedInRouting() | |
object Profile : LoggedInRouting() | |
} |
This file contains hidden or 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
interface Gallery { | |
sealed class Routing { | |
object AlbumList : Routing() | |
data class PhotosOfAlbum(val album: Album) : Routing() | |
data class FullScreenPhoto(val photo: Photo) : Routing() | |
} | |
companion object { | |
@Composable |
This file contains hidden or 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
routing = Routing.PhotosOfAlbum(someAlbum) |
This file contains hidden or 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
@Model | |
class BackStack<T>( | |
defaultElement: T | |
) { | |
private var elements: List<T> = listOf(defaultElement) | |
fun last(): T = | |
elements.last() | |
fun push(element: T) { |
This file contains hidden or 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
@Composable | |
fun Content() { | |
- var routing by +state<Routing> { Routing.AlbumList } | |
+ var backStack by +state<BackStack<Routing>> { BackStack(Routing.AlbumList) } |
This file contains hidden or 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
- when (routing) { | |
+ when (currentRouting = backStack.last()) { | |
// all Content() on the right hand side are @Composable | |
is Routing.AlbumList -> AlbumList.Content() | |
is Routing.PhotosOfAlbum -> PhotosOfAlbum.Content(currentRouting.album) | |
is Routing.FullScreenPhoto -> FullScreenPhoto.Content(currentRouting..photo) | |
} |
This file contains hidden or 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
// “going forward” | |
backStack.push(Routing.PhotosOfAlbum(album)) | |
// “going backwards” -- we’ll want to trigger this from actual back press | |
backStack.pop() |
This file contains hidden or 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
class MainActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContent { | |
MaterialTheme { | |
Root.Content() | |
} | |
} | |
} |
This file contains hidden or 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
@Model | |
object BackPress { | |
var triggered = false | |
} |
This file contains hidden or 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
class MainActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContent { | |
MaterialTheme { | |
Root.Content(Backpress) | |
} | |
} | |
} |