-
Notifications
You must be signed in to change notification settings - Fork 10
/
SharedUIViewControllers.kt
52 lines (42 loc) · 1.87 KB
/
SharedUIViewControllers.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
@file:Suppress("unused", "SpellCheckingInspection")
package com.expressus.compose
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.window.ComposeUIViewController
import com.expressus.compose.components.CoffeeSelectorsMobile
import com.expressus.compose.components.ExpressusMobile
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
import platform.UIKit.UIViewController
object ExpressusUIViewController {
//https://github.com/JetBrains/compose-multiplatform/issues/3478
private val viewState = MutableStateFlow(ViewState())
private data class ViewState(
val isGrinding: Boolean = false,
val isPouring: Boolean = false,
val isMakingCoffee: Boolean = false,
val status: String = ""
)
fun composable(makeCoffee: () -> Unit): UIViewController {
return ComposeUIViewController {
with(viewState.collectAsState().value) {
ExpressusMobile(isGrinding, isPouring, isMakingCoffee, status, makeCoffee)
}
}
}
fun update(isGrinding: Boolean, isPouring: Boolean, isMakingCoffee: Boolean, status: String) {
viewState.update { ViewState(isGrinding = isGrinding, isPouring = isPouring, isMakingCoffee = isMakingCoffee, status = status) }
}
}
object CoffeeSelectorsUIViewController {
//https://github.com/JetBrains/compose-multiplatform/issues/3478
private val isMakingCoffee = mutableStateOf(false)
fun composable(onAnyClick: () -> Unit, onSwiftUiClick: () -> Unit, onComposeClick: () -> Unit): UIViewController {
return ComposeUIViewController {
CoffeeSelectorsMobile(isMakingCoffee.value, onAnyClick, onSwiftUiClick, onComposeClick)
}
}
fun update(isMakingCoffee: Boolean) {
this.isMakingCoffee.value = isMakingCoffee
}
}