Android Compose currently doesn't support any Navigation Container.
So in this tutorial we will show how to implement simple Stack Navigation
● when Stack is empty list of Show View Buttons is shown
● when Stack is not empty last View on the Stack is shown
● when Show View Button is pressed View is placed on the Stack
● when Back Button is pressed last View is taken from the Stack
MainActivity.kt
package com.example.myapplication
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.Text
import androidx.compose.foundation.layout.*
import androidx.compose.material.Button
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.setContent
import androidx.compose.ui.unit.dp
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Column {
val myList = remember { mutableStateListOf<@Composable () -> Unit>() }
if (myList.size == 0) { MainList (myList) }
else { DetailsView(myList) }
}
}
}
}
@Composable
fun MainList(myList: MutableList<@Composable () -> Unit>) {
Button({ myList.add { View1() } }) { Text("Show View 1") }
Button({ myList.add { View2() } }) { Text("Show View 2") }
Button({ myList.add { View3() } }) { Text("Show View 3") }
}
@Composable
fun DetailsView(myList: MutableList<@Composable () -> Unit>) {
myList.last()()
Button({ myList.removeLast() }) { Text("Back") }
}
@Composable fun View1() { Text("Details of View 1") }
@Composable fun View2() { Text("Details of View 2") }
@Composable fun View2() { Text("Details of View 3") }