-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
181 additions
and
145 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,10 +18,10 @@ jobs: | |
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up JDK 11 | ||
- name: Set up JDK 22 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '11' | ||
java-version: '22' | ||
distribution: 'zulu' | ||
- name: Build with Gradle | ||
uses: gradle/[email protected] | ||
|
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
76 changes: 76 additions & 0 deletions
76
src/main/kotlin/com/hoc081098/kotlin_playground/solivagant/FirstRoute.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,76 @@ | ||
package com.hoc081098.kotlin_playground.solivagant | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Immutable | ||
import androidx.compose.runtime.Stable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.text.style.TextAlign | ||
import com.hoc081098.channeleventbus.ChannelEventBusException | ||
import com.hoc081098.channeleventbus.ValidationBeforeClosing | ||
import com.hoc081098.flowext.FlowExtPreview | ||
import com.hoc081098.flowext.catchAndResume | ||
import com.hoc081098.kmp.viewmodel.Closeable | ||
import com.hoc081098.solivagant.lifecycle.compose.collectAsStateWithLifecycle | ||
import com.hoc081098.solivagant.navigation.NavRoot | ||
import com.hoc081098.solivagant.navigation.ScreenDestination | ||
import com.hoc081098.solivagant.navigation.rememberCloseableOnRoute | ||
import kotlin.random.Random | ||
import kotlinx.coroutines.flow.emptyFlow | ||
|
||
@Immutable | ||
data object FirstRoute : NavRoot { | ||
@OptIn(FlowExtPreview::class) | ||
@JvmStatic | ||
@Stable | ||
val Destination = ScreenDestination<FirstRoute> { route, modifier -> | ||
val result by remember { | ||
EventBus | ||
.receiveAsFlow(SecondResultToFirst) | ||
.catchAndResume { | ||
if (it is ChannelEventBusException.FlowAlreadyCollected) emptyFlow() | ||
else throw it | ||
} | ||
}.collectAsStateWithLifecycle(null) | ||
|
||
rememberCloseableOnRoute(route) { | ||
Closeable { | ||
EventBus.closeKey( | ||
key = SecondResultToFirst, | ||
validations = ValidationBeforeClosing.NONE, | ||
) | ||
} | ||
} | ||
|
||
Box( | ||
modifier = modifier.background(Color.Red.copy(alpha = 0.2f)), | ||
contentAlignment = Alignment.Center, | ||
) { | ||
Column(horizontalAlignment = Alignment.CenterHorizontally) { | ||
Text( | ||
text = "result: $result", | ||
textAlign = TextAlign.Center, | ||
style = MaterialTheme.typography.titleLarge, | ||
) | ||
|
||
Button( | ||
onClick = { | ||
Navigator.navigateTo( | ||
SecondRoute( | ||
id = Random.nextInt().toString(), | ||
otherIds = List(2) { Random.nextInt().toString() } | ||
) | ||
) | ||
} | ||
) { Text("Go to second route") } | ||
} | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/kotlin/com/hoc081098/kotlin_playground/solivagant/SecondResultToFirst.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,12 @@ | ||
package com.hoc081098.kotlin_playground.solivagant | ||
|
||
import androidx.compose.runtime.Immutable | ||
import com.hoc081098.channeleventbus.ChannelEvent | ||
import com.hoc081098.channeleventbus.ChannelEventKey | ||
|
||
@Immutable | ||
data class SecondResultToFirst(val number: Int) : ChannelEvent<SecondResultToFirst> { | ||
override val key = Key | ||
|
||
companion object Key : ChannelEventKey<SecondResultToFirst>(SecondResultToFirst::class) | ||
} |
62 changes: 62 additions & 0 deletions
62
src/main/kotlin/com/hoc081098/kotlin_playground/solivagant/SecondRoute.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,62 @@ | ||
package com.hoc081098.kotlin_playground.solivagant | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Immutable | ||
import androidx.compose.runtime.Stable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.unit.dp | ||
import com.hoc081098.channeleventbus.OptionWhenSendingToBusDoesNotExist | ||
import com.hoc081098.solivagant.navigation.NavRoute | ||
import com.hoc081098.solivagant.navigation.ScreenDestination | ||
import kotlin.random.Random | ||
|
||
@Immutable | ||
data class SecondRoute( | ||
val id: String, | ||
val otherIds: List<String> | ||
) : NavRoute { | ||
companion object { | ||
@JvmStatic | ||
@Stable | ||
val Destination = ScreenDestination<SecondRoute> { route, modifier -> | ||
Box( | ||
modifier = modifier.background(Color.Green.copy(alpha = 0.2f)), | ||
contentAlignment = Alignment.Center, | ||
) { | ||
Column( | ||
modifier = Modifier.padding(16.dp), | ||
horizontalAlignment = Alignment.CenterHorizontally | ||
) { | ||
Text( | ||
text = route.toString(), | ||
textAlign = TextAlign.Center, | ||
style = MaterialTheme.typography.titleLarge, | ||
) | ||
Spacer(Modifier.height(16.dp)) | ||
Button( | ||
onClick = { | ||
Navigator.navigateBack() | ||
EventBus.send( | ||
event = SecondResultToFirst(number = Random.nextInt()), | ||
option = OptionWhenSendingToBusDoesNotExist.DO_NOTHING | ||
) | ||
} | ||
) { | ||
Text("Back to first route") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.