├── router
├── .gitignore
├── consumer-rules.pro
├── src
│ └── main
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── github
│ │ └── zsoltk
│ │ └── compose
│ │ ├── savedinstancestate
│ │ ├── Persistent.kt
│ │ ├── SavedInstanceState.kt
│ │ └── BundleScope.kt
│ │ ├── backpress
│ │ └── BackPressHandler.kt
│ │ └── router
│ │ ├── BackStack.kt
│ │ └── Router.kt
├── proguard-rules.pro
└── build.gradle
├── app-lifelike
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ ├── styles.xml
│ │ │ └── material_colors.xml
│ │ ├── drawable
│ │ │ ├── placeholder.png
│ │ │ └── ic_launcher_background.xml
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ └── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ ├── java
│ │ └── com
│ │ │ └── example
│ │ │ └── lifelike
│ │ │ ├── entity
│ │ │ ├── Photo.kt
│ │ │ ├── User.kt
│ │ │ └── Album.kt
│ │ │ ├── composable
│ │ │ ├── loggedout
│ │ │ │ ├── RegFinal.kt
│ │ │ │ ├── RegUserPhone.kt
│ │ │ │ ├── RegUserName.kt
│ │ │ │ ├── common
│ │ │ │ │ └── RegFlowPanel.kt
│ │ │ │ ├── RegConfirmSmsCode.kt
│ │ │ │ └── Splash.kt
│ │ │ ├── common
│ │ │ │ └── BigButton.kt
│ │ │ ├── loggedin
│ │ │ │ ├── Gallery.kt
│ │ │ │ ├── Profile.kt
│ │ │ │ ├── FullScreenPhoto.kt
│ │ │ │ ├── AlbumList.kt
│ │ │ │ ├── Menu.kt
│ │ │ │ ├── PhotosOfAlbum.kt
│ │ │ │ └── News.kt
│ │ │ ├── Root.kt
│ │ │ ├── LoggedOut.kt
│ │ │ └── LoggedIn.kt
│ │ │ ├── DeepLink.kt
│ │ │ └── MainActivity.kt
│ │ └── AndroidManifest.xml
├── README.md
├── proguard-rules.pro
└── build.gradle
├── jitpack.yml
├── app-nested-containers
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ ├── styles.xml
│ │ │ └── material_colors.xml
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ └── drawable
│ │ │ └── ic_launcher_background.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── nestedcontainers
│ │ ├── DeepLink.kt
│ │ ├── MainActivity.kt
│ │ └── composable
│ │ └── SomeChild.kt
├── README.md
├── proguard-rules.pro
└── build.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── settings.gradle
├── .gitignore
├── gradle.properties
├── .github
└── workflows
│ └── gradle.yml
├── gradlew.bat
├── gradlew
├── README.md
└── LICENSE
/router/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/router/consumer-rules.pro:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app-lifelike/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/jitpack.yml:
--------------------------------------------------------------------------------
1 | jdk:
2 | - openjdk11
3 |
--------------------------------------------------------------------------------
/app-nested-containers/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/compose-router/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/router/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/app-lifelike/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Lifelike example
3 |
4 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app-nested-containers'
2 | include ':app-lifelike'
3 | include ':router'
4 | rootProject.name = "compose-router"
5 |
--------------------------------------------------------------------------------
/app-nested-containers/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Nested containers
3 |
4 |
--------------------------------------------------------------------------------
/app-lifelike/src/main/res/drawable/placeholder.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/compose-router/HEAD/app-lifelike/src/main/res/drawable/placeholder.png
--------------------------------------------------------------------------------
/app-lifelike/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/compose-router/HEAD/app-lifelike/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app-lifelike/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/compose-router/HEAD/app-lifelike/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app-lifelike/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/compose-router/HEAD/app-lifelike/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app-lifelike/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/compose-router/HEAD/app-lifelike/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app-lifelike/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/compose-router/HEAD/app-lifelike/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app-lifelike/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/compose-router/HEAD/app-lifelike/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app-lifelike/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/compose-router/HEAD/app-lifelike/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app-lifelike/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/compose-router/HEAD/app-lifelike/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app-lifelike/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/compose-router/HEAD/app-lifelike/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app-lifelike/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/compose-router/HEAD/app-lifelike/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app-nested-containers/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/compose-router/HEAD/app-nested-containers/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app-nested-containers/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/compose-router/HEAD/app-nested-containers/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app-nested-containers/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/compose-router/HEAD/app-nested-containers/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app-nested-containers/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/compose-router/HEAD/app-nested-containers/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app-nested-containers/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/compose-router/HEAD/app-nested-containers/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app-nested-containers/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/compose-router/HEAD/app-nested-containers/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app-nested-containers/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/compose-router/HEAD/app-nested-containers/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app-nested-containers/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/compose-router/HEAD/app-nested-containers/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app-nested-containers/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/compose-router/HEAD/app-nested-containers/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app-nested-containers/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zsoltk/compose-router/HEAD/app-nested-containers/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app-lifelike/src/main/java/com/example/lifelike/entity/Photo.kt:
--------------------------------------------------------------------------------
1 | package com.example.lifelike.entity
2 |
3 | data class Photo(
4 | val id: Int
5 | ) {
6 | val title: String = "Photo #$id"
7 | }
8 |
--------------------------------------------------------------------------------
/app-lifelike/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #6200EE
4 | #3700B3
5 | #03DAC5
6 |
7 |
--------------------------------------------------------------------------------
/app-nested-containers/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #6200EE
4 | #3700B3
5 | #03DAC5
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Jul 23 10:35:09 AEST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | /.idea/caches
6 | /.idea/libraries
7 | /.idea/modules.xml
8 | /.idea/workspace.xml
9 | /.idea/navEditor.xml
10 | /.idea/assetWizardSettings.xml
11 | .DS_Store
12 | /build
13 | /captures
14 | .externalNativeBuild
15 | .cxx
16 |
--------------------------------------------------------------------------------
/app-lifelike/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app-lifelike/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app-nested-containers/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app-nested-containers/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app-lifelike/src/main/java/com/example/lifelike/entity/User.kt:
--------------------------------------------------------------------------------
1 | package com.example.lifelike.entity
2 |
3 | import androidx.compose.runtime.getValue
4 | import androidx.compose.runtime.mutableStateOf
5 | import androidx.compose.runtime.setValue
6 |
7 |
8 | class User(
9 | name: String,
10 | phone: String
11 | ){
12 | var name by mutableStateOf(name)
13 | var phone by mutableStateOf(phone)
14 | }
15 |
--------------------------------------------------------------------------------
/app-lifelike/src/main/java/com/example/lifelike/composable/loggedout/RegFinal.kt:
--------------------------------------------------------------------------------
1 | package com.example.lifelike.composable.loggedout
2 |
3 | import androidx.compose.runtime.Composable
4 | import com.example.lifelike.composable.loggedout.common.RegFlowPanel
5 |
6 |
7 | interface RegFinal {
8 | companion object {
9 |
10 | @Composable
11 | fun Content(onNext: () -> Unit) {
12 | RegFlowPanel("Welcome on board!", onNext)
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/app-lifelike/src/main/java/com/example/lifelike/composable/common/BigButton.kt:
--------------------------------------------------------------------------------
1 | package com.example.lifelike.composable.common
2 |
3 | import androidx.compose.material.Button
4 | import androidx.compose.material.MaterialTheme
5 | import androidx.compose.material.Text
6 | import androidx.compose.runtime.Composable
7 | import androidx.compose.ui.graphics.Color
8 |
9 | @Composable
10 | fun BigButton(text: String, onClick: () -> Unit) {
11 | Button(onClick = onClick) {
12 | Text(
13 | text = text.toUpperCase(),
14 | style = MaterialTheme.typography.body1.copy(color = Color.White)
15 | )
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/app-lifelike/src/main/java/com/example/lifelike/entity/Album.kt:
--------------------------------------------------------------------------------
1 | package com.example.lifelike.entity
2 |
3 | data class Album(
4 | val name: String,
5 | val photos: List
6 | )
7 |
8 | val albums = listOf(
9 | Album("Trip to Budapest", MutableList(19) { i -> Photo(i) }),
10 | Album("Cats", MutableList(39) { i -> Photo(i) }),
11 | Album("Family", MutableList(162) { i -> Photo(i) }),
12 | Album("Todo", MutableList(15) { i -> Photo(i) }),
13 | Album("California road trip", MutableList(112) { i -> Photo(i) }),
14 | Album("KotlinConf", MutableList(43) { i -> Photo(i) }),
15 | Album("Summer of '19", MutableList(72) { i -> Photo(i) })
16 | )
17 |
--------------------------------------------------------------------------------
/app-nested-containers/README.md:
--------------------------------------------------------------------------------
1 | **What your're seeing here**
2 | - There are nested containers of the same type
3 | - Every level can have its routing to a Red, Green, or Blue subtree
4 | - When you hit `Next`, that level pushes a new Routing to its own back stack, resulting in a new subtree
5 | - The previous state of that level is kept in a back stack
6 | - When you hit back on the device, the lowest level that has any screen history in its back stack will pop, and the previous subtree gets restored
7 |
8 | Not shown in this gif (should capture again), but actual code also has local state on every level (a counter), that is persisted and restored from back stack.
9 |
10 | 
11 |
--------------------------------------------------------------------------------
/app-lifelike/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app-nested-containers/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app-lifelike/README.md:
--------------------------------------------------------------------------------
1 | **What you're seeing here**
2 | - There's a whole app hierarchy represented solely with Compose
3 | - Any level that needs a back stack can have one
4 | - `Root` level switches between `LoggedOut` / `LoggedIn` routing
5 | - Once logged in, `LoggedOut` flow is removed from back stack, you cannot go back by pressing back button
6 | - `LoggedOut` flow has its own routing of registration screens with its own back stack
7 | - `Loggedin` subtree has its own routing of `Menu` + main screens (`Gallery`, `News`, `Profile`), with back stack for demonstration purposes
8 | - `Gallery` subtree has its own routing with `Album list`, `Album view`, `Photo view` with back stack
9 | - Once there's no more back stack to pop on back press, Android default action happens (Activity finishes)
10 |
11 | 
12 |
--------------------------------------------------------------------------------
/router/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/router/src/main/java/com/github/zsoltk/compose/savedinstancestate/Persistent.kt:
--------------------------------------------------------------------------------
1 | package com.github.zsoltk.compose.savedinstancestate
2 |
3 | import androidx.compose.runtime.Composable
4 | import androidx.compose.runtime.MutableState
5 | import androidx.compose.runtime.mutableStateOf
6 | import androidx.compose.runtime.remember
7 |
8 | @Composable
9 | fun persistentInt(key: String, defaultValue: Int = 0): MutableState {
10 | val bundle = AmbientSavedInstanceState.current
11 |
12 | val state: MutableState = remember { mutableStateOf(
13 | bundle.getInt(key, defaultValue)
14 | )}
15 |
16 | saveInt(key, state.value)
17 |
18 | return state
19 | }
20 |
21 | @Composable
22 | private fun saveInt(key: String, value: Int) {
23 | val bundle = AmbientSavedInstanceState.current
24 | bundle.putInt(key, value)
25 | }
26 |
--------------------------------------------------------------------------------
/app-lifelike/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app-nested-containers/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/router/src/main/java/com/github/zsoltk/compose/backpress/BackPressHandler.kt:
--------------------------------------------------------------------------------
1 | package com.github.zsoltk.compose.backpress
2 |
3 | import androidx.compose.runtime.ProvidableCompositionLocal
4 | import androidx.compose.runtime.compositionLocalOf
5 |
6 | val LocalBackPressHandler: ProvidableCompositionLocal =
7 | compositionLocalOf { throw IllegalStateException("backPressHandler is not initialized") }
8 |
9 | @Deprecated(
10 | message = "Replaced with LocalBackPressHandler to reflect Compose API changes",
11 | replaceWith = ReplaceWith("LocalBackPressHandler")
12 | )
13 | val AmbientBackPressHandler = LocalBackPressHandler
14 |
15 |
16 | class BackPressHandler(
17 | val id: String = "Root"
18 | ) {
19 | var children = mutableListOf<() -> Boolean>()
20 |
21 | fun handle(): Boolean =
22 | children.reversed().any { it() }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/app-lifelike/src/main/java/com/example/lifelike/composable/loggedout/RegUserPhone.kt:
--------------------------------------------------------------------------------
1 | package com.example.lifelike.composable.loggedout
2 |
3 | import androidx.compose.foundation.ExperimentalFoundationApi
4 | import androidx.compose.foundation.text.BasicTextField
5 | import androidx.compose.runtime.Composable
6 | import androidx.compose.ui.text.TextRange
7 | import androidx.compose.ui.text.input.TextFieldValue
8 | import com.example.lifelike.composable.loggedout.common.RegFlowPanel
9 | import com.example.lifelike.entity.User
10 |
11 |
12 | interface RegUserPhone {
13 | companion object {
14 | @ExperimentalFoundationApi
15 | @Composable
16 | fun Content(user: User, onNext: () -> Unit) {
17 | RegFlowPanel("Your fake phone number", onNext) {
18 | BasicTextField(
19 | value = TextFieldValue(user.phone, TextRange(user.phone.length,user.phone.length)),
20 | onValueChange = { user.phone = it.text.filter { it.isDigit() } }
21 | )
22 | }
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/router/src/main/java/com/github/zsoltk/compose/savedinstancestate/SavedInstanceState.kt:
--------------------------------------------------------------------------------
1 | package com.github.zsoltk.compose.savedinstancestate
2 |
3 | import android.os.Bundle
4 | import androidx.compose.runtime.ProvidableCompositionLocal
5 | import androidx.compose.runtime.compositionLocalOf
6 |
7 | private val rootSavedInstanceState = Bundle()
8 |
9 | val LocalSavedInstanceState: ProvidableCompositionLocal = compositionLocalOf { rootSavedInstanceState }
10 |
11 | @Deprecated(
12 | message = "Replaced with LocalSavedInstanceState to reflect Compose API changes",
13 | replaceWith = ReplaceWith("LocalSavedInstanceState")
14 | )
15 | val AmbientSavedInstanceState = LocalSavedInstanceState
16 |
17 | internal const val BUNDLE_KEY = "LocalSavedInstanceState"
18 |
19 | fun Bundle.saveLocal() {
20 | putBundle(BUNDLE_KEY, rootSavedInstanceState)
21 | }
22 |
23 | @Deprecated(
24 | message = "Replaced with saveLocal to reflect Compose API changes",
25 | replaceWith = ReplaceWith("saveLocal()")
26 | )
27 | fun Bundle.saveAmbient() {
28 | this.saveLocal()
29 | }
30 |
31 |
32 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx2048m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
19 | # AndroidX package structure to make it clearer which packages are bundled with the
20 | # Android operating system, and which are packaged with your app"s APK
21 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
22 | android.useAndroidX=true
23 | # Automatically convert third-party libraries to use AndroidX
24 | android.enableJetifier=true
25 |
--------------------------------------------------------------------------------
/app-lifelike/src/main/java/com/example/lifelike/composable/loggedout/RegUserName.kt:
--------------------------------------------------------------------------------
1 | package com.example.lifelike.composable.loggedout
2 |
3 | import androidx.compose.foundation.ExperimentalFoundationApi
4 | import androidx.compose.foundation.text.BasicTextField
5 | import androidx.compose.runtime.Composable
6 | import androidx.compose.ui.text.TextRange
7 | import androidx.compose.ui.text.input.TextFieldValue
8 | import androidx.compose.ui.tooling.preview.Preview
9 | import com.example.lifelike.composable.loggedout.common.RegFlowPanel
10 | import com.example.lifelike.entity.User
11 |
12 |
13 | interface RegUserName {
14 | companion object {
15 |
16 | @OptIn(ExperimentalFoundationApi::class)
17 | @Composable
18 | fun Content(user: User, onNext: () -> Unit) {
19 | RegFlowPanel("Your fake name", onNext) {
20 | BasicTextField(
21 | value = TextFieldValue(user.name, TextRange(user.name.length,user.name.length)),
22 | onValueChange = { user.name = it.text }
23 | )
24 | }
25 | }
26 | }
27 | }
28 |
29 | @Preview
30 | @Composable
31 | fun PreviewRegUserName() {
32 | RegUserName.Content(User("Test user", "123456"), {})
33 | }
34 |
--------------------------------------------------------------------------------
/app-lifelike/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/app-nested-containers/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/app-nested-containers/src/main/java/com/example/nestedcontainers/DeepLink.kt:
--------------------------------------------------------------------------------
1 | package com.example.nestedcontainers
2 |
3 | import android.content.Intent
4 | import android.util.Log
5 | import com.example.nestedcontainers.composable.SomeChild
6 |
7 | // TODO: implement your own validation / conversion
8 | fun Intent.deepLinkRoute(): List =
9 | when (data?.host) {
10 | // adb shell 'am start -a "android.intent.action.VIEW" -d "app-nested://default/abcd"'
11 | "default" -> parseDefaultDeepLink(data?.path)
12 | null -> emptyList()
13 | else -> emptyList().also {
14 | Log.e("compose-router", "Unexpected deep link: $data")
15 | }
16 | }
17 |
18 | private fun parseDefaultDeepLink(path: String?): List =
19 | // TODO: implement your own validation / conversion
20 | path
21 | ?.take(4)
22 | ?.toCharArray()
23 | ?.map {
24 | when (it.toUpperCase()) {
25 | 'R' -> SomeChild.Routing.SubtreeRed
26 | 'G' -> SomeChild.Routing.SubtreeGreen
27 | 'B' -> SomeChild.Routing.SubtreeBlue
28 | else -> Unit.also {
29 | Log.e("compose-router", "Unexpected deep link path: $path")
30 | }
31 | }
32 | }
33 | ?.filter { it !is Unit }
34 | ?: emptyList()
35 |
--------------------------------------------------------------------------------
/.github/workflows/gradle.yml:
--------------------------------------------------------------------------------
1 | name: Build
2 | on:
3 | push:
4 | branches:
5 | - "master"
6 | pull_request:
7 | branches:
8 | - "*"
9 |
10 | jobs:
11 | validation:
12 | name: Validate Gradle Wrapper
13 | runs-on: ubuntu-latest
14 | steps:
15 | - name: Checkout latest code
16 | uses: actions/checkout@v2
17 | - name: Validate Gradle Wrapper
18 | uses: gradle/wrapper-validation-action@v1
19 | gradle:
20 | name: Build Gradle Tasks
21 | strategy:
22 | matrix:
23 | os: [ubuntu-latest, macos-latest, windows-latest]
24 | runs-on: ${{ matrix.os }}
25 | if: ${{ !contains(github.event.head_commit.message, 'ci skip') }}
26 | steps:
27 | - name: Set up JDK 11
28 | uses: actions/setup-java@v1
29 | with:
30 | java-version: 11
31 | - name: Checkout Repo
32 | uses: actions/checkout@v2
33 | - name: Cache Gradle Caches
34 | uses: actions/cache@v1
35 | with:
36 | path: ~/.gradle/caches/
37 | key: cache-gradle-cache
38 | - name: Cache Gradle Wrapper
39 | uses: actions/cache@v1
40 | with:
41 | path: ~/.gradle/wrapper/
42 | key: cache-gradle-wrapper
43 | - name: Run Gradle tasks
44 | run: ./gradlew build --continue
45 | - name: Stop Gradle
46 | run: ./gradlew --stop
47 |
--------------------------------------------------------------------------------
/router/src/main/java/com/github/zsoltk/compose/savedinstancestate/BundleScope.kt:
--------------------------------------------------------------------------------
1 | package com.github.zsoltk.compose.savedinstancestate
2 |
3 | import android.os.Bundle
4 | import androidx.compose.runtime.*
5 |
6 | @Composable
7 | fun BundleScope(
8 | savedInstanceState: Bundle?,
9 | children: @Composable (bundle: Bundle) -> Unit
10 | ) {
11 | BundleScope(BUNDLE_KEY, savedInstanceState ?: Bundle(), true, children)
12 | }
13 |
14 | @Composable
15 | fun BundleScope(
16 | key: String,
17 | children: @Composable (bundle: Bundle) -> Unit
18 | ) {
19 | BundleScope(key, Bundle(), true, children)
20 | }
21 |
22 | /**
23 | * Scopes a new Bundle with [key] under ambient [AmbientSavedInstanceState] and provides it
24 | * to [children].
25 | */
26 | @Composable
27 | fun BundleScope(
28 | key: String,
29 | defaultBundle: Bundle = Bundle(),
30 | autoDispose: Boolean = true,
31 | children: @Composable (Bundle) -> Unit
32 | ) {
33 | val upstream = LocalSavedInstanceState.current
34 | val downstream = upstream.getBundle(key) ?: defaultBundle
35 |
36 | SideEffect {
37 | upstream.putBundle(key, downstream)
38 | }
39 | if (autoDispose) {
40 | DisposableEffect(Unit) { onDispose { upstream.remove(key) } }
41 | }
42 |
43 | CompositionLocalProvider(LocalSavedInstanceState provides downstream) {
44 | children(downstream)
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app-lifelike/src/main/java/com/example/lifelike/DeepLink.kt:
--------------------------------------------------------------------------------
1 | package com.example.lifelike
2 |
3 | import android.content.Intent
4 | import android.net.Uri
5 | import android.util.Log
6 | import com.example.lifelike.composable.LoggedIn
7 | import com.example.lifelike.composable.Root
8 | import com.example.lifelike.entity.User
9 |
10 | // TODO: implement your own validation / conversion
11 | fun Intent.deepLinkRoute(): List =
12 | when (data?.host) {
13 | // adb shell 'am start -a "android.intent.action.VIEW" -d "app-lifelike://go-to-profile?name=fake&phone=123123"'
14 | "go-to-profile" -> parseProfileDeepLink(data!!)
15 | null -> emptyList()
16 | else -> emptyList().also {
17 | Log.e("compose-router", "Unexpected deep link: $data")
18 | }
19 | }
20 |
21 | private fun parseProfileDeepLink(data: Uri): List {
22 | // Bear in mind that this is only a proof of concept implementation.
23 | // In real life you definitely don't want to do it like this.
24 | val name = data.getQueryParameter("name") ?: ""
25 | val phone = data.getQueryParameter("phone") ?: ""
26 | val user = User(name, phone)
27 |
28 | return listOf(
29 | // TODO support waiting for a routing to happen (e.g. user to authenticate by themselves)
30 | // before moving on with the rest
31 | Root.Routing.LoggedIn(user),
32 | LoggedIn.Routing.Profile
33 | )
34 | }
35 |
--------------------------------------------------------------------------------
/app-lifelike/src/main/java/com/example/lifelike/composable/loggedout/common/RegFlowPanel.kt:
--------------------------------------------------------------------------------
1 | package com.example.lifelike.composable.loggedout.common
2 |
3 | import androidx.compose.foundation.layout.*
4 | import androidx.compose.material.MaterialTheme
5 | import androidx.compose.material.Text
6 | import androidx.compose.runtime.Composable
7 | import androidx.compose.ui.Alignment
8 | import androidx.compose.ui.Modifier
9 | import androidx.compose.ui.unit.dp
10 | import com.example.lifelike.composable.common.BigButton
11 |
12 | @Composable
13 | fun RegFlowPanel(
14 | title: String,
15 | onNext: () -> Unit,
16 | content: @Composable () -> Unit = {}
17 | ) {
18 | Column(
19 | modifier = Modifier.fillMaxSize().padding(40.dp),
20 | verticalArrangement = Arrangement.SpaceAround
21 | ) {
22 | Box(modifier = Modifier.wrapContentSize()) {
23 | Text(
24 | text = title,
25 | style = MaterialTheme.typography.h5
26 | )
27 | }
28 | Box(modifier = Modifier.fillMaxSize().weight(1f).wrapContentHeight(Alignment.CenterVertically)) {
29 | content()
30 | }
31 | Box(
32 | modifier = Modifier
33 | .sizeIn(maxHeight = 48.dp)
34 | .wrapContentSize(Alignment.CenterEnd)
35 | ) {
36 | BigButton(
37 | text = "Next",
38 | onClick = onNext
39 | )
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/app-lifelike/src/main/java/com/example/lifelike/composable/loggedin/Gallery.kt:
--------------------------------------------------------------------------------
1 | package com.example.lifelike.composable.loggedin
2 |
3 | import androidx.compose.runtime.Composable
4 | import com.example.lifelike.entity.Album
5 | import com.example.lifelike.entity.Photo
6 | import com.github.zsoltk.compose.router.Router
7 |
8 | interface Gallery {
9 |
10 | sealed class Routing {
11 | object AlbumList : Routing()
12 | data class PhotosOfAlbum(val album: Album) : Routing()
13 | data class FullScreenPhoto(val photo: Photo) : Routing()
14 | }
15 |
16 | companion object {
17 | @Composable
18 | fun Content(defaultRouting: Routing) {
19 | Router(defaultRouting) { backStack ->
20 | when (val routing = backStack.last()) {
21 | is Routing.AlbumList -> AlbumList.Content(
22 | onAlbumSelected = {
23 | backStack.push(Routing.PhotosOfAlbum(it))
24 | })
25 |
26 | is Routing.PhotosOfAlbum -> PhotosOfAlbum.Content(
27 | album = routing.album,
28 | onPhotoSelected = {
29 | backStack.push(Routing.FullScreenPhoto(it))
30 | })
31 |
32 | is Routing.FullScreenPhoto -> FullScreenPhoto.Content(
33 | photo = routing.photo
34 | )
35 | }
36 | }
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/app-lifelike/src/main/java/com/example/lifelike/composable/loggedout/RegConfirmSmsCode.kt:
--------------------------------------------------------------------------------
1 | package com.example.lifelike.composable.loggedout
2 |
3 | import androidx.compose.foundation.ExperimentalFoundationApi
4 | import androidx.compose.foundation.text.BasicTextField
5 | import androidx.compose.runtime.Composable
6 | import androidx.compose.runtime.mutableStateOf
7 | import androidx.compose.runtime.remember
8 | import androidx.compose.ui.text.TextRange
9 | import androidx.compose.ui.text.input.TextFieldValue
10 | import com.example.lifelike.composable.loggedout.common.RegFlowPanel
11 |
12 |
13 | interface RegConfirmSmsCode {
14 | companion object {
15 |
16 | @ExperimentalFoundationApi
17 | @Composable
18 | fun Content(onNext: () -> Unit) {
19 |
20 | val code = remember {
21 | val initialValue = "0000"
22 | mutableStateOf(TextFieldValue(initialValue, TextRange(initialValue.length, initialValue.length)))
23 | }
24 |
25 | RegFlowPanel(
26 | "Confirm SMS code that will never arrive",
27 | { if (code.value.text.length == 4) onNext() }) {
28 | BasicTextField(
29 | value = code.value,
30 | onValueChange = {
31 | var digits = it.text.filter { it.isDigit() }
32 | digits = if (digits.length <= 4) digits else digits.substring(0, 4)
33 | code.value = TextFieldValue(digits, TextRange(digits.length, digits.length))
34 | }
35 | )
36 | }
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/router/src/main/java/com/github/zsoltk/compose/router/BackStack.kt:
--------------------------------------------------------------------------------
1 | package com.github.zsoltk.compose.router
2 |
3 | import androidx.compose.runtime.getValue
4 | import androidx.compose.runtime.mutableStateOf
5 | import androidx.compose.runtime.setValue
6 |
7 |
8 | class BackStack internal constructor(
9 | initialElement: T,
10 | private var onElementRemoved: ((Int) -> Unit)
11 | ) {
12 | var elements by mutableStateOf(listOf(initialElement))
13 | private set
14 |
15 | val lastIndex: Int
16 | get() = elements.lastIndex
17 |
18 | val size: Int
19 | get() = elements.size
20 |
21 | fun last(): T =
22 | elements.last()
23 |
24 | fun push(element: T) {
25 | elements = elements.plus(element)
26 | }
27 |
28 | fun pushAndDropNested(element: T) {
29 | onElementRemoved.invoke(lastIndex)
30 | push(element)
31 | }
32 |
33 | fun pop(): Boolean =
34 | // we won’t let the last item to be popped
35 | if (size <= 1) false else {
36 | onElementRemoved.invoke(lastIndex)
37 | elements = ArrayList(
38 | elements.subList(0, lastIndex) // exclusive
39 | )
40 | true
41 | }
42 |
43 | fun replace(element: T) {
44 | onElementRemoved.invoke(lastIndex)
45 | elements = elements
46 | .subList(0, elements.lastIndex) // exclusive
47 | .plus(element)
48 | }
49 |
50 | fun newRoot(element: T) {
51 | elements.indices.reversed().forEach { index ->
52 | onElementRemoved.invoke(index)
53 | }
54 | elements = arrayListOf(element)
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/app-lifelike/src/main/java/com/example/lifelike/composable/loggedout/Splash.kt:
--------------------------------------------------------------------------------
1 | package com.example.lifelike.composable.loggedout
2 |
3 | import androidx.compose.foundation.layout.*
4 | import androidx.compose.material.MaterialTheme
5 | import androidx.compose.material.Text
6 | import androidx.compose.runtime.Composable
7 | import androidx.compose.ui.Alignment
8 | import androidx.compose.ui.Modifier
9 | import androidx.compose.ui.text.AnnotatedString
10 | import androidx.compose.ui.text.ParagraphStyle
11 | import androidx.compose.ui.text.style.TextAlign
12 | import androidx.compose.ui.unit.dp
13 | import com.example.lifelike.composable.common.BigButton
14 |
15 |
16 | interface Splash {
17 | companion object {
18 |
19 | @Composable
20 | fun Content(onNext: () -> Unit) {
21 | Column(modifier = Modifier.padding(40.dp), verticalArrangement = Arrangement.SpaceAround) {
22 | Text(
23 | text = AnnotatedString(
24 | text = "Welcome to amazing fake app",
25 | paragraphStyle = ParagraphStyle(
26 | textAlign = TextAlign.Center
27 | )
28 | ),
29 | style = MaterialTheme.typography.h4
30 | )
31 | Box(
32 | modifier = Modifier.fillMaxWidth()
33 | .sizeIn(maxHeight = 48.dp)
34 | .wrapContentSize(Alignment.Center)
35 | ) {
36 | BigButton(
37 | text = "Create account",
38 | onClick = onNext
39 | )
40 | }
41 | }
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/router/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.library'
3 | id 'kotlin-android'
4 | id 'maven-publish'
5 | }
6 |
7 | android {
8 | compileSdkVersion 31
9 |
10 | defaultConfig {
11 | minSdkVersion 21
12 | targetSdkVersion 30
13 | versionCode 1
14 | versionName "0.27.0"
15 |
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | consumerProguardFiles 'consumer-rules.pro'
18 | }
19 |
20 | buildTypes {
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 | compileOptions {
27 | sourceCompatibility JavaVersion.VERSION_1_8
28 | targetCompatibility JavaVersion.VERSION_1_8
29 | }
30 | buildFeatures {
31 | compose true
32 | }
33 | composeOptions {
34 | kotlinCompilerExtensionVersion compose_version
35 | }
36 | kotlinOptions {
37 | useIR = true
38 | jvmTarget = "1.8"
39 | freeCompilerArgs += ["-Xallow-jvm-ir-dependencies", "-Xskip-prerelease-check"]
40 | }
41 | }
42 |
43 | dependencies {
44 | // kotlin
45 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
46 |
47 | // jetpack compose
48 | implementation "androidx.compose.ui:ui:$compose_version"
49 | implementation "androidx.compose.foundation:foundation-layout:$compose_version"
50 | implementation "androidx.compose.ui:ui-tooling:$compose_version"
51 | implementation "androidx.compose.foundation:foundation:$compose_version"
52 | }
53 |
54 | afterEvaluate {
55 | publishing {
56 | publications {
57 | release(MavenPublication) {
58 | from components.release
59 | }
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/app-lifelike/src/main/java/com/example/lifelike/composable/loggedin/Profile.kt:
--------------------------------------------------------------------------------
1 | package com.example.lifelike.composable.loggedin
2 |
3 | import androidx.compose.foundation.layout.*
4 | import androidx.compose.material.Button
5 | import androidx.compose.material.MaterialTheme
6 | import androidx.compose.material.Text
7 | import androidx.compose.runtime.Composable
8 | import androidx.compose.ui.Modifier
9 | import androidx.compose.ui.tooling.preview.Preview
10 | import androidx.compose.ui.unit.dp
11 | import com.example.lifelike.entity.User
12 |
13 |
14 | interface Profile {
15 |
16 | companion object {
17 | @Composable
18 | fun Content(user: User, onLogout: () -> Unit) {
19 | Column(
20 | modifier = Modifier.fillMaxHeight().padding(40.dp),
21 | verticalArrangement = Arrangement.SpaceAround
22 | ) {
23 | Text(
24 | text = "You are logged in as:",
25 | style = MaterialTheme.typography.h4
26 | )
27 | Column {
28 | Text(
29 | text = user.name,
30 | style = MaterialTheme.typography.h5
31 | )
32 | Spacer(modifier = Modifier.height(16.dp))
33 | Text(
34 | text = user.phone,
35 | style = MaterialTheme.typography.h5
36 | )
37 | }
38 | Column {
39 | Button(onClick = onLogout) {
40 | Text(text = "Log out")
41 | }
42 | }
43 | }
44 | }
45 | }
46 | }
47 |
48 | @Preview
49 | @Composable
50 | fun ProfilePreview() {
51 | Profile.Content(user = User("Demo user", "123456789"), onLogout = {})
52 | }
53 |
--------------------------------------------------------------------------------
/app-lifelike/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
31 |
--------------------------------------------------------------------------------
/app-lifelike/src/main/java/com/example/lifelike/composable/loggedin/FullScreenPhoto.kt:
--------------------------------------------------------------------------------
1 | package com.example.lifelike.composable.loggedin
2 |
3 | import androidx.compose.foundation.Image
4 | import androidx.compose.foundation.layout.*
5 | import androidx.compose.material.MaterialTheme
6 | import androidx.compose.material.Surface
7 | import androidx.compose.material.Text
8 | import androidx.compose.runtime.Composable
9 | import androidx.compose.ui.Alignment
10 | import androidx.compose.ui.Modifier
11 | import androidx.compose.ui.graphics.Color
12 | import androidx.compose.ui.res.painterResource
13 | import androidx.compose.ui.tooling.preview.Preview
14 | import androidx.compose.ui.unit.dp
15 | import com.example.lifelike.R
16 | import com.example.lifelike.entity.Photo
17 |
18 | interface FullScreenPhoto {
19 |
20 | companion object {
21 | @Composable
22 | fun Content(photo: Photo) {
23 | val image = painterResource(R.drawable.placeholder)
24 | val typography = MaterialTheme.typography
25 |
26 | Surface(color = Color.DarkGray) {
27 | Box(modifier = Modifier.padding(32.dp)) {
28 | Column {
29 | Box(modifier = Modifier.weight(0.8f).fillMaxSize().wrapContentSize(Alignment.Center)) {
30 | Image(image, null)
31 | }
32 |
33 | Spacer(modifier = Modifier.height(32.dp))
34 | Text(
35 | text = photo.title,
36 | style = typography.subtitle1.copy(color = Color.White)
37 | )
38 | }
39 | }
40 | }
41 | }
42 | }
43 | }
44 |
45 |
46 | @Preview
47 | @Composable
48 | fun FullScreenPhotoPreview() {
49 | FullScreenPhoto.Content(Photo(167))
50 | }
51 |
--------------------------------------------------------------------------------
/app-nested-containers/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
31 |
--------------------------------------------------------------------------------
/app-lifelike/src/main/java/com/example/lifelike/composable/Root.kt:
--------------------------------------------------------------------------------
1 | package com.example.lifelike.composable
2 |
3 | import androidx.compose.foundation.ExperimentalFoundationApi
4 | import androidx.compose.runtime.Composable
5 | import com.example.lifelike.composable.LoggedIn.Routing.Gallery
6 | import com.example.lifelike.composable.LoggedOut.Routing.Splash
7 | import com.example.lifelike.entity.User
8 | import com.github.zsoltk.compose.router.Router
9 |
10 | interface Root {
11 |
12 | sealed class Routing {
13 | object LoggedOut : Routing()
14 | data class LoggedIn(val user: User) : Routing()
15 | }
16 |
17 | companion object {
18 | @ExperimentalFoundationApi
19 | @Composable
20 | fun Content(defaultRouting: Routing) {
21 | Router(defaultRouting) { backStack ->
22 | when (val currentRouting = backStack.last()) {
23 | is Routing.LoggedOut -> LoggedOut.Content(
24 | defaultRouting = Splash,
25 | onLoggedIn = { user ->
26 | // play around with other back stack operations here:
27 | backStack.newRoot(
28 | Routing.LoggedIn(user)
29 | )
30 | }
31 | )
32 | is Routing.LoggedIn -> LoggedIn.Content(
33 | defaultRouting = Gallery,
34 | user = currentRouting.user,
35 | onLogout = {
36 | // play around with other back stack operations here:
37 | backStack.newRoot(
38 | Routing.LoggedOut
39 | )
40 | }
41 | )
42 | }
43 | }
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app-lifelike/src/main/java/com/example/lifelike/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.example.lifelike
2 |
3 | import android.os.Bundle
4 | import androidx.activity.compose.setContent
5 | import androidx.appcompat.app.AppCompatActivity
6 | import androidx.compose.foundation.ExperimentalFoundationApi
7 | import androidx.compose.material.MaterialTheme
8 | import androidx.compose.runtime.CompositionLocalProvider
9 | import com.example.lifelike.composable.Root
10 | import com.example.lifelike.composable.Root.Routing.LoggedOut
11 | import com.github.zsoltk.compose.backpress.BackPressHandler
12 | import com.github.zsoltk.compose.backpress.LocalBackPressHandler
13 | import com.github.zsoltk.compose.router.LocalRouting
14 | import com.github.zsoltk.compose.savedinstancestate.BundleScope
15 | import com.github.zsoltk.compose.savedinstancestate.saveAmbient
16 | import com.github.zsoltk.compose.savedinstancestate.saveLocal
17 |
18 | class MainActivity : AppCompatActivity() {
19 |
20 | private val backPressHandler = BackPressHandler()
21 |
22 | @ExperimentalFoundationApi
23 | override fun onCreate(savedInstanceState: Bundle?) {
24 | super.onCreate(savedInstanceState)
25 |
26 | setContent {
27 | MaterialTheme {
28 | CompositionLocalProvider(
29 | LocalBackPressHandler provides backPressHandler,
30 | LocalRouting provides intent.deepLinkRoute()
31 | ) {
32 | BundleScope(savedInstanceState) {
33 | Root.Content(LoggedOut)
34 | }
35 | }
36 | }
37 | }
38 | }
39 |
40 | override fun onBackPressed() {
41 | if (!backPressHandler.handle()) {
42 | super.onBackPressed()
43 | }
44 | }
45 |
46 | override fun onSaveInstanceState(outState: Bundle) {
47 | super.onSaveInstanceState(outState)
48 | outState.saveLocal()
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app-nested-containers/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | id 'kotlin-android'
4 | id 'kotlin-kapt'
5 | }
6 |
7 | android {
8 | compileSdkVersion 31
9 |
10 | defaultConfig {
11 | applicationId "com.example.nestedcontainers"
12 | minSdkVersion 24
13 | targetSdkVersion 30
14 | versionCode 1
15 | versionName "1.0"
16 |
17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
18 | }
19 |
20 | buildTypes {
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 | compileOptions {
27 | sourceCompatibility JavaVersion.VERSION_1_8
28 | targetCompatibility JavaVersion.VERSION_1_8
29 | }
30 | buildFeatures {
31 | compose true
32 | }
33 | composeOptions {
34 | kotlinCompilerVersion kotlin_version
35 | kotlinCompilerExtensionVersion compose_version
36 | }
37 | kotlinOptions {
38 | jvmTarget = "1.8"
39 | freeCompilerArgs += ["-Xallow-jvm-ir-dependencies", "-Xskip-prerelease-check"]
40 | }
41 | }
42 |
43 | dependencies {
44 | // kotlin
45 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
46 |
47 | // android
48 | implementation 'androidx.core:core-ktx:1.6.0'
49 | implementation 'androidx.appcompat:appcompat:1.3.1'
50 | implementation 'androidx.activity:activity-compose:1.4.0-alpha02'
51 |
52 | // jetpack compose
53 | implementation "androidx.compose.ui:ui:$compose_version"
54 | implementation "androidx.compose.foundation:foundation-layout:$compose_version"
55 | implementation "androidx.compose.material:material:$compose_version"
56 | implementation "androidx.compose.ui:ui-tooling:$compose_version"
57 | implementation "androidx.compose.foundation:foundation:$compose_version"
58 |
59 | // compose-router module in the local project scope
60 | implementation project(":router")
61 |
62 | // testing
63 | testImplementation 'junit:junit:4.13.2'
64 | androidTestImplementation 'androidx.test.ext:junit:1.1.3'
65 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
66 | }
67 |
--------------------------------------------------------------------------------
/app-lifelike/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | id 'kotlin-android'
4 | id 'kotlin-kapt'
5 | }
6 |
7 | android {
8 | compileSdkVersion 31
9 | buildToolsVersion "30.0.3"
10 |
11 | defaultConfig {
12 | applicationId "com.example.lifelike"
13 | minSdkVersion 24
14 | targetSdkVersion 30
15 | versionCode 1
16 | versionName "1.0"
17 |
18 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
19 | }
20 |
21 | buildTypes {
22 | release {
23 | minifyEnabled false
24 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
25 | }
26 | }
27 | compileOptions {
28 | sourceCompatibility JavaVersion.VERSION_1_8
29 | targetCompatibility JavaVersion.VERSION_1_8
30 | }
31 | buildFeatures {
32 | compose true
33 | }
34 | composeOptions {
35 | kotlinCompilerVersion kotlin_version
36 | kotlinCompilerExtensionVersion compose_version
37 | }
38 | kotlinOptions {
39 | jvmTarget = "1.8"
40 | freeCompilerArgs += ["-Xallow-jvm-ir-dependencies", "-Xskip-prerelease-check"]
41 | }
42 | }
43 |
44 | dependencies {
45 | // kotlin
46 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
47 |
48 | // android
49 | implementation 'androidx.core:core-ktx:1.6.0'
50 | implementation 'androidx.appcompat:appcompat:1.3.1'
51 | implementation 'androidx.activity:activity-compose:1.4.0-alpha02'
52 |
53 | // jetpack compose
54 | implementation "androidx.compose.ui:ui:$compose_version"
55 | implementation "androidx.compose.foundation:foundation-layout:$compose_version"
56 | implementation "androidx.compose.material:material:$compose_version"
57 | implementation "androidx.compose.ui:ui-tooling:$compose_version"
58 | implementation "androidx.compose.foundation:foundation:$compose_version"
59 |
60 | // compose-router module in the local project scope
61 | implementation project(":router")
62 |
63 | // testing
64 | testImplementation 'junit:junit:4.13.2'
65 | androidTestImplementation 'androidx.test.ext:junit:1.1.3'
66 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
67 | }
68 |
--------------------------------------------------------------------------------
/app-nested-containers/src/main/java/com/example/nestedcontainers/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.example.nestedcontainers
2 |
3 | import android.os.Bundle
4 | import androidx.activity.compose.setContent
5 | import androidx.appcompat.app.AppCompatActivity
6 | import androidx.compose.foundation.horizontalScroll
7 | import androidx.compose.foundation.layout.Row
8 | import androidx.compose.foundation.rememberScrollState
9 | import androidx.compose.material.MaterialTheme
10 | import androidx.compose.runtime.Composable
11 | import androidx.compose.runtime.CompositionLocalProvider
12 | import androidx.compose.ui.Modifier
13 | import androidx.compose.ui.tooling.preview.Preview
14 | import com.example.nestedcontainers.composable.SomeChild
15 | import com.github.zsoltk.compose.backpress.BackPressHandler
16 | import com.github.zsoltk.compose.backpress.LocalBackPressHandler
17 | import com.github.zsoltk.compose.router.LocalRouting
18 | import com.github.zsoltk.compose.savedinstancestate.BundleScope
19 | import com.github.zsoltk.compose.savedinstancestate.saveLocal
20 |
21 | class MainActivity : AppCompatActivity() {
22 | private val backPressHandler = BackPressHandler()
23 |
24 | override fun onCreate(savedInstanceState: Bundle?) {
25 | super.onCreate(savedInstanceState)
26 | setContent {
27 | MaterialTheme {
28 | Row(modifier = Modifier.horizontalScroll(rememberScrollState())) {
29 | CompositionLocalProvider(
30 | LocalBackPressHandler provides backPressHandler,
31 | LocalRouting provides intent.deepLinkRoute()
32 | ) {
33 | BundleScope(savedInstanceState) {
34 | SomeChild.Root()
35 | }
36 | }
37 | }
38 | }
39 | }
40 | }
41 |
42 | override fun onBackPressed() {
43 | if (!backPressHandler.handle()) {
44 | super.onBackPressed()
45 | }
46 | }
47 |
48 | override fun onSaveInstanceState(outState: Bundle) {
49 | super.onSaveInstanceState(outState)
50 | outState.saveLocal()
51 | }
52 | }
53 |
54 |
55 | @Preview
56 | @Composable
57 | fun DefaultPreview() {
58 | MaterialTheme {
59 | SomeChild.Root()
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/app-lifelike/src/main/java/com/example/lifelike/composable/loggedin/AlbumList.kt:
--------------------------------------------------------------------------------
1 | package com.example.lifelike.composable.loggedin
2 |
3 | import androidx.compose.foundation.Image
4 | import androidx.compose.foundation.clickable
5 | import androidx.compose.foundation.layout.*
6 | import androidx.compose.foundation.lazy.LazyColumn
7 | import androidx.compose.foundation.lazy.items
8 | import androidx.compose.material.MaterialTheme
9 | import androidx.compose.material.Text
10 | import androidx.compose.runtime.Composable
11 | import androidx.compose.ui.Modifier
12 | import androidx.compose.ui.res.painterResource
13 | import androidx.compose.ui.text.font.FontWeight
14 | import androidx.compose.ui.tooling.preview.Preview
15 | import androidx.compose.ui.unit.dp
16 | import com.example.lifelike.R
17 | import com.example.lifelike.entity.Album
18 | import com.example.lifelike.entity.albums
19 |
20 |
21 | interface AlbumList {
22 |
23 | companion object {
24 | @Composable
25 | fun Content(onAlbumSelected: (Album) -> Unit) {
26 | LazyColumn {
27 | items(albums) {
28 | AlbumRow(it, onAlbumSelected)
29 | }
30 | }
31 | }
32 |
33 | @Composable
34 | private fun AlbumRow(album: Album, onAlbumSelected: (Album) -> Unit) {
35 | val image = painterResource(R.drawable.placeholder)
36 | val typography = MaterialTheme.typography
37 |
38 | Box(
39 | modifier = Modifier.clickable(onClick = { onAlbumSelected(album) })
40 | ) {
41 | Row(modifier = Modifier.padding(all = 16.dp)) {
42 | Box(modifier = Modifier.size(40.dp, 40.dp)) {
43 | Image(image, null)
44 | }
45 | Spacer(modifier = Modifier.width(16.dp))
46 | Column {
47 | Text(
48 | album.name,
49 | style = typography.subtitle1.copy(fontWeight = FontWeight.Bold)
50 | )
51 | Text("${album.photos.size} photos", style = typography.body1)
52 | }
53 | }
54 | }
55 | }
56 | }
57 | }
58 |
59 |
60 | @Preview
61 | @Composable
62 | fun AlbumListPreview() {
63 | AlbumList.Content {}
64 | }
65 |
--------------------------------------------------------------------------------
/app-lifelike/src/main/java/com/example/lifelike/composable/LoggedOut.kt:
--------------------------------------------------------------------------------
1 | package com.example.lifelike.composable
2 |
3 | import androidx.compose.foundation.ExperimentalFoundationApi
4 | import androidx.compose.runtime.Composable
5 | import com.example.lifelike.composable.loggedout.RegConfirmSmsCode
6 | import com.example.lifelike.composable.loggedout.RegFinal
7 | import com.example.lifelike.composable.loggedout.RegUserName
8 | import com.example.lifelike.composable.loggedout.RegUserPhone
9 | import com.example.lifelike.composable.loggedout.Splash
10 | import com.example.lifelike.entity.User
11 | import com.github.zsoltk.compose.router.Router
12 |
13 | interface LoggedOut {
14 |
15 | sealed class Routing {
16 | object Splash : Routing()
17 | object RegUserName : Routing()
18 | object RegUserPhone : Routing()
19 | object RegConfirmSmsCode : Routing()
20 | object RegFinal : Routing()
21 | }
22 |
23 | companion object {
24 | @ExperimentalFoundationApi
25 | @Composable
26 | fun Content(defaultRouting: Routing, onLoggedIn: (User) -> Unit) {
27 | val user = User("Demo user", "123456789")
28 |
29 | Router(defaultRouting) { backStack ->
30 | fun Routing.next(): () -> Unit = {
31 | when (this) {
32 | Routing.Splash -> Routing.RegUserName
33 | Routing.RegUserName -> Routing.RegUserPhone
34 | Routing.RegUserPhone -> Routing.RegConfirmSmsCode
35 | Routing.RegConfirmSmsCode -> Routing.RegFinal
36 | Routing.RegFinal -> null
37 | }?.let {
38 | backStack.push(it)
39 | }
40 | }
41 |
42 | when (val currentRouting = backStack.last()) {
43 | Routing.Splash -> Splash.Content(onNext = currentRouting.next())
44 | Routing.RegUserName -> RegUserName.Content(
45 | user = user,
46 | onNext = currentRouting.next()
47 | )
48 | Routing.RegUserPhone -> RegUserPhone.Content(
49 | user = user,
50 | onNext = currentRouting.next()
51 | )
52 | Routing.RegConfirmSmsCode -> RegConfirmSmsCode.Content(onNext = currentRouting.next())
53 | Routing.RegFinal -> RegFinal.Content(onNext = { onLoggedIn(user) })
54 | }
55 | }
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app-lifelike/src/main/java/com/example/lifelike/composable/LoggedIn.kt:
--------------------------------------------------------------------------------
1 | package com.example.lifelike.composable
2 |
3 | import androidx.compose.foundation.layout.Box
4 | import androidx.compose.foundation.layout.Column
5 | import androidx.compose.foundation.layout.wrapContentSize
6 | import androidx.compose.runtime.Composable
7 | import androidx.compose.ui.Alignment
8 | import androidx.compose.ui.Modifier
9 | import com.example.lifelike.composable.loggedin.Gallery
10 | import com.example.lifelike.composable.loggedin.Gallery.Routing.AlbumList
11 | import com.example.lifelike.composable.loggedin.Menu
12 | import com.example.lifelike.composable.loggedin.News
13 | import com.example.lifelike.composable.loggedin.Profile
14 | import com.example.lifelike.entity.User
15 | import com.github.zsoltk.compose.router.Router
16 |
17 | interface LoggedIn {
18 | sealed class Routing {
19 | object Gallery : Routing()
20 | object News : Routing()
21 | object Profile : Routing()
22 | }
23 |
24 | companion object {
25 | @Composable
26 | fun Content(defaultRouting: Routing, user: User, onLogout: () -> Unit) {
27 | Router(defaultRouting) { backStack ->
28 | val routing = backStack.last()
29 |
30 | Column {
31 | Box(modifier = Modifier.weight(1f).wrapContentSize(Alignment.TopStart)) {
32 | routing.toContent(user, onLogout)
33 | }
34 |
35 | Menu.Content(
36 | state = routing.toMenuState(),
37 | onMenuItemClicked = { menuItem ->
38 | backStack.push(menuItem.toRouting())
39 | }
40 | )
41 | }
42 | }
43 | }
44 |
45 | /**
46 | * Renders Content of another Composable module based on the selected Routing
47 | */
48 | @Composable
49 | private fun Routing.toContent(user: User, onLogout: () -> Unit) = when (this) {
50 | is Routing.Gallery -> Gallery.Content(AlbumList)
51 | is Routing.News -> News.Content()
52 | is Routing.Profile -> Profile.Content(
53 | user,
54 | onLogout
55 | )
56 | }
57 |
58 | /**
59 | * Creates Menu state with menu item selected based on current routing choice
60 | */
61 | private fun Routing.toMenuState() =
62 | Menu.State(
63 | currentSelection = when (this) {
64 | is Routing.Gallery -> Menu.MenuItem.Gallery
65 | is Routing.News -> Menu.MenuItem.News
66 | is Routing.Profile -> Menu.MenuItem.Profile
67 | }
68 | )
69 |
70 | /**
71 | * Maps the MenuItem to the corresponding Routing choice
72 | */
73 | private fun Menu.MenuItem.toRouting(): Routing = when (this) {
74 | is Menu.MenuItem.Gallery -> Routing.Gallery
75 | is Menu.MenuItem.News -> Routing.News
76 | is Menu.MenuItem.Profile -> Routing.Profile
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/app-lifelike/src/main/java/com/example/lifelike/composable/loggedin/Menu.kt:
--------------------------------------------------------------------------------
1 | package com.example.lifelike.composable.loggedin
2 |
3 | import androidx.compose.foundation.clickable
4 | import androidx.compose.foundation.layout.Box
5 | import androidx.compose.foundation.layout.Row
6 | import androidx.compose.foundation.layout.fillMaxWidth
7 | import androidx.compose.foundation.layout.padding
8 | import androidx.compose.foundation.shape.RoundedCornerShape
9 | import androidx.compose.material.MaterialTheme
10 | import androidx.compose.material.Surface
11 | import androidx.compose.material.Text
12 | import androidx.compose.runtime.Composable
13 | import androidx.compose.ui.Modifier
14 | import androidx.compose.ui.text.AnnotatedString
15 | import androidx.compose.ui.text.ParagraphStyle
16 | import androidx.compose.ui.text.style.TextAlign
17 | import androidx.compose.ui.tooling.preview.Preview
18 | import androidx.compose.ui.unit.dp
19 | import com.example.lifelike.composable.loggedin.Menu.MenuItem.Gallery
20 | import com.example.lifelike.composable.loggedin.Menu.MenuItem.News
21 | import com.example.lifelike.composable.loggedin.Menu.MenuItem.Profile
22 |
23 | interface Menu {
24 |
25 | sealed class MenuItem {
26 | object Gallery : MenuItem()
27 | object News : MenuItem()
28 | object Profile : MenuItem()
29 | }
30 |
31 | data class State(
32 | val menuItems: List