Skip to content

Commit

Permalink
Solivagant
Browse files Browse the repository at this point in the history
  • Loading branch information
hoc081098 committed Apr 27, 2024
1 parent 63101f2 commit 4fd1ab3
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm") version "1.9.23"
id("org.jetbrains.compose") version "1.6.10-beta02"
}

group = "com.hoc.kotlin_playground"
Expand All @@ -26,12 +27,21 @@ dependencies {
testImplementation(kotlin("test"))

implementation("io.github.hoc081098:FlowExt:0.8.0")
implementation("io.github.hoc081098:kmp-viewmodel:0.7.1")
val kmpViewModel = "0.7.1"
implementation("io.github.hoc081098:kmp-viewmodel:$kmpViewModel")
implementation("io.github.hoc081098:kmp-viewmodel-savedstate:$kmpViewModel")
implementation("io.github.hoc081098:kmp-viewmodel-compose:$kmpViewModel")
implementation("io.github.hoc081098:channel-event-bus:0.0.2")
implementation("io.github.hoc081098:solivagant-navigation:0.3.0")
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material3)
implementation(compose.materialIconsExtended)
implementation(compose.desktop.currentOs)

implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-swing:1.8.0")
val coroutines = "1.8.0"
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-swing:$coroutines")
implementation("org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.7")

implementation("io.reactivex.rxjava3:rxjava:3.1.8")
Expand Down
83 changes: 83 additions & 0 deletions src/main/kotlin/com/hoc081098/kotlin_playground/solivagant/main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.hoc081098.kotlin_playground.solivagant

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import com.hoc081098.solivagant.lifecycle.LocalLifecycleOwner
import com.hoc081098.solivagant.navigation.ClearOnDispose
import com.hoc081098.solivagant.navigation.NavEventNavigator
import com.hoc081098.solivagant.navigation.NavHost
import com.hoc081098.solivagant.navigation.NavRoot
import com.hoc081098.solivagant.navigation.NavRoute
import com.hoc081098.solivagant.navigation.ProvideCompositionLocals
import com.hoc081098.solivagant.navigation.SavedStateSupport
import com.hoc081098.solivagant.navigation.ScreenDestination
import com.hoc081098.solivagant.navigation.rememberWindowLifecycleOwner
import kotlinx.collections.immutable.persistentSetOf

fun main() {
val savedStateSupport = SavedStateSupport()

application {
savedStateSupport.ClearOnDispose()
Window(
onCloseRequest = ::exitApplication,
title = "Solivagant",
) {
val lifecycleOwner = checkNotNull(rememberWindowLifecycleOwner()) { "rememberWindowLifecycleOwner returns null" }
savedStateSupport.ProvideCompositionLocals(LocalLifecycleOwner provides lifecycleOwner) { MyApp() }
}
}
}

val Navigator by lazy(LazyThreadSafetyMode.NONE) { NavEventNavigator() }

@Composable
fun MyApp() =
NavHost(
startRoute = FirstRoute,
destinations = remember {
persistentSetOf(
FirstRouteDestination,
SecondRouteDestination,
)
},
navEventNavigator = Navigator,
)

@Immutable
data object FirstRoute : NavRoot

val FirstRouteDestination = ScreenDestination<FirstRoute> { _, modifier ->
Box(
modifier = modifier.background(Color.Red.copy(alpha = 0.2f)),
contentAlignment = Alignment.Center,
) {
Button(onClick = { Navigator.navigateTo(SecondRoute) }) {
Text("Go to second route")
}
}
}


@Immutable
data object SecondRoute : NavRoute

val SecondRouteDestination = ScreenDestination<SecondRoute> { _, modifier ->
Box(
modifier = modifier.background(Color.Green.copy(alpha = 0.2f)),
contentAlignment = Alignment.Center,
) {
Button(onClick = Navigator::navigateBack) {
Text("Back to first route")
}
}
}

0 comments on commit 4fd1ab3

Please sign in to comment.