Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions composeApp/src/commonMain/kotlin/DI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import ui.device.DeviceHomeViewInteractor
import ui.file.FileSystemViewInteractor
import ui.home.HomeViewInteractor
import ui.iosServices.IOSServicesScreenViewInteractor
import ui.openForResultExample.OpenForResultConfirmationViewInteractor
import ui.openForResultExample.OpenForResultExampleViewInteractor
import ui.popups.PopupsScreenViewInteractor
import ui.viewStateExample.ViewStateExampleViewInteractor

Expand Down Expand Up @@ -59,4 +61,6 @@ fun commonModule() = module {
factory { IOSServicesScreenViewInteractor(get()) }
factory { CapabilityScreenViewInteractor(get()) }
factory { ColorPickerViewInteractor() }
factory { OpenForResultExampleViewInteractor(get()) }
factory { OpenForResultConfirmationViewInteractor(get()) }
}
11 changes: 11 additions & 0 deletions composeApp/src/commonMain/kotlin/coordinator/AppCoordinator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,15 @@ class AppCoordinator(): Coordinator(
fun colorPickerClicked() = push(Route.ColorPicker)
fun htmlDemoClicked() = push(Route.WebDemo)
fun windowInfoClicked() = push(Route.WindowInfo)
fun openForResultExampleClicked() = push(Route.OpenForResultExample)
suspend fun openForResultExampleConfirmationClicked() = transactionWithResult(Boolean::class) {
push(Route.OpenForResultExampleConfirmation)
}
fun openForResultExampleConfirmationYesClicked() {
pop { withResult(true) }
}
fun openForResultExampleConfirmationNoClicked() {
pop { withResult(false) }
}

}
2 changes: 2 additions & 0 deletions composeApp/src/commonMain/kotlin/ui/Route.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ sealed class Route(
data object ColorPicker : Route(webRoutePath = "/color-picker")
data object WebDemo : Route(webRoutePath = "/web-demo")
data object WindowInfo : Route(webRoutePath = "/window-info")
data object OpenForResultExample : Route(webRoutePath = "/open-for-result")
data object OpenForResultExampleConfirmation : Route(webRoutePath = "/open-for-result-confirmation")

companion object {
val deepLinks = Router.buildDeepLinks {
Expand Down
4 changes: 4 additions & 0 deletions composeApp/src/commonMain/kotlin/ui/app/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import ui.markdown.MarkdownScreen
import ui.popups.PopupsScreen
import ui.viewStateExample.ViewStateExampleScreen
import ui.htmlDemo.HtmlDemoScreen
import ui.openForResultExample.OpenForResultConfirmationScreen
import ui.openForResultExample.OpenForResultExampleScreen
import ui.widgets.WidgetsScreen
import ui.windowInfo.WindowInfoScreen

Expand Down Expand Up @@ -62,6 +64,8 @@ fun App(
RouteTransitionDirection.Out
}
)
is Route.OpenForResultExample -> OpenForResultExampleScreen()
is Route.OpenForResultExampleConfirmation -> OpenForResultConfirmationScreen()
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions composeApp/src/commonMain/kotlin/ui/home/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ fun HomeScreen(
content = { Text("Window Info") },
onClick = interactor::windowInfoButtonClicked,
)
Button(
content = { Text("Open Route For Result Example") },
onClick = interactor::openForResultClicked,
)
Button(
content = { Text(rememberKmpString(Strings.iosServices)) },
onClick = interactor::iosServicesButtonClicked,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ class HomeViewInteractor(
fun colorPickerButtonClicked() = coordinator.colorPickerClicked()
fun htmlDemoButtonClicked() = coordinator.htmlDemoClicked()
fun windowInfoButtonClicked() = coordinator.windowInfoClicked()
fun openForResultClicked() = coordinator.openForResultExampleClicked()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package ui.openForResultExample

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.outsidesource.oskitcompose.interactor.collectAsState
import com.outsidesource.oskitcompose.lib.rememberInjectForRoute
import ui.common.Screen

@Composable
fun OpenForResultConfirmationScreen(
interactor: OpenForResultConfirmationViewInteractor = rememberInjectForRoute()
) {
val state = interactor.collectAsState()

Screen("Example Route with Result") {
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterVertically),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Text("Return Result:")

Row(
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
Button(
content = { Text("True") },
onClick = interactor::yesClicked
)
Button(
content = { Text("False") },
onClick = interactor::noClicked
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ui.openForResultExample

import com.outsidesource.oskitkmp.interactor.Interactor
import coordinator.AppCoordinator

data class ConfirmationViewState(
val result: Boolean? = null,
)

class OpenForResultConfirmationViewInteractor(
private val coordinator: AppCoordinator
): Interactor<ConfirmationViewState>(
initialState = ConfirmationViewState()
) {

fun yesClicked() {
coordinator.openForResultExampleConfirmationYesClicked()
}

fun noClicked() {
coordinator.openForResultExampleConfirmationNoClicked()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package ui.openForResultExample

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.outsidesource.oskitcompose.interactor.collectAsState
import com.outsidesource.oskitcompose.lib.rememberInjectForRoute
import ui.common.Screen

@Composable
fun OpenForResultExampleScreen(
interactor: OpenForResultExampleViewInteractor = rememberInjectForRoute()
) {
val state = interactor.collectAsState()

Screen("Open Route For Result Example") {
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterVertically),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Text(
"This example shows how to launch a route and await a result from it.\n" +
"Press the button to open the confirmation screen and receive " +
"the user’s selection as the result.\n",
textAlign = TextAlign.Center
)

Button(
content = { Text("Open Confirmation Route") },
onClick = interactor::openConfirmationRouteClicked
)

if (state.exampleDialogWasEverLaunched) {
Text("Returned result: ${state.result?.toString() ?: "Cancelled"}")
}

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ui.openForResultExample

import com.outsidesource.oskitkmp.interactor.Interactor
import com.outsidesource.oskitkmp.outcome.unwrapOrNull
import coordinator.AppCoordinator
import kotlinx.coroutines.launch

data class OpenForResultExampleViewState(
val result: Boolean? = null,
val exampleDialogWasEverLaunched: Boolean = false,
)

class OpenForResultExampleViewInteractor(
private val coordinator: AppCoordinator
): Interactor<OpenForResultExampleViewState>(
initialState = OpenForResultExampleViewState()
) {

fun openConfirmationRouteClicked() {
update { state -> state.copy(exampleDialogWasEverLaunched = true) }
interactorScope.launch {
val res = coordinator.openForResultExampleConfirmationClicked().unwrapOrNull()
update { state -> state.copy(result = res) }
}
}
}