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
struct JuicyScreenTemplate<ViewState: KotlinBase, Content: View>: View { | |
let screenBackgroundColor: Color | |
let screenState: ScreenState | |
let content: () -> Content | |
let screenToolbarViewState: ScreenToolbarViewState? | |
let screenCallToActionViewState: ScreenCallToActionViewState? | |
let onCallToActionTapped: () -> Void | |
init( | |
screenBackgroundColor: Color = .white, |
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
@Composable | |
fun ScreenTemplate( | |
screenBackgroundColor: Color = MaterialTheme.colors.surface, | |
screenState: ScreenState, | |
loadedState: @Composable () -> Unit, | |
screenToolbarViewState: ScreenToolbarViewState? = null, | |
screenCallToActionViewState: ScreenCallToActionViewState? = null, | |
onCallToActionClicked: () -> Unit = { }, | |
) { | |
Surface( |
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
// Jetpack compose | |
@Composable | |
fun ScreenTemplate( | |
screenBackgroundColor: Color = MaterialTheme.colors.surface, | |
screenState: ScreenState, | |
loadedState: @Composable () -> Unit, | |
screenToolbarViewState: ScreenToolbarViewState? = null, | |
screenCallToActionViewState: ScreenCallToActionViewState? = null, | |
onCallToActionClicked: () -> Unit = { }, | |
) { |
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
struct CallToAction: View { | |
let screenCallToActionViewState: ScreenCallToActionViewState | |
let onCallToActionTapped: () -> Void | |
var body: some View { | |
Button( | |
screenCallToActionViewState.buttonText, | |
action: onCallToActionTapped | |
) | |
} |
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
// Jetpack Compose | |
@Composable | |
fun CallToAction( | |
modifier: Modifier = Modifier, | |
screenCallToActionViewState: ScreenCallToActionViewState, | |
onClicked: () -> Unit, | |
) { | |
Button( | |
modifier = modifier, | |
shape = MaterialTheme.shapes.small, |
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
struct MyFabScreenDestination: View { | |
let myFabScreenViewModel: MyFabScreenViewModel | |
@State private var viewState: MyFabScreenViewModel.ViewState | |
init(myFabScreenViewModel: MyFabScreenViewModel) { | |
self.myFabScreenViewModel = myFabScreenViewModel | |
_viewState = State(initialValue: myFabScreenViewModel.defaultViewState()) | |
} | |
var body: some View { |
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
@Composable | |
fun MyFabDestination( | |
myFabScreenViewModel: MyFabScreenViewModel, | |
) { | |
LifecycleHandler(myFabScreenViewModel) | |
val viewState = myFabScreenViewModel.viewStateStream() | |
.collectAsState(myFabScreenViewModel.defaultViewState()) | |
val onNextClicked = |
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
class MyFabScreenViewModel( | |
private val navigator: Navigator, | |
) : MotherViewModel<MyFabScreenViewModel.ViewState, MyFabScreenViewModel.UiAction>() { | |
override fun onAttach() { | |
super.onAttach() | |
flowOf(ScreenState.Loaded) | |
.onEach { delay(5000) } | |
.flowOn(Dispatchers.Default) | |
.onEach { emit(lastViewState.copy(screenState = it)) } |
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
sealed interface ScreenState { | |
object Loading : ScreenState | |
data class Error( | |
val message: String | |
) : ScreenState | |
object Loaded : ScreenState | |
} | |
data class ScreenCallToActionViewState( |
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
class MviViewModel( | |
private val answerService: AnswerService, | |
) { | |
private val coroutineScope = MainScope() | |
private val _viewState: MutableStateFlow<ViewState> = MutableStateFlow(ViewState()) | |
val viewState = _viewState.asStateFlow() | |
// See https://proandroiddev.com/android-singleliveevent-redux-with-kotlin-flow-b755c70bb055 |
NewerOlder