Composing Magic
MVI with Kotlin Flow & Jetpack Compose
Next -> Next -> Modern Android Architecture
Kotlin StateFlow
Kotlin StateFlow
MVI
Compose
Kotlin Flow
Suspend
ViewState
Coroutines
Suspend
Coil
Model View Intent http://hannesdorfmann.com/android/model-view-intent
RxJava
“Use RxJava scan() to apply reduce() to the previous state of app and return the new state.”
MVVM
ViewModel
View
UI Event
UI Event
UI Event
State
Repo
Logic
Room DB
Data Binding to update UI
Full post here: https://danlowe.me/post/2019-08-15-mvi/
MVI
View/Activity
UI Event
UI Event
UI Event
New State
Reducer
Accumulator / Actor
Room DB
New ViewState to Update UI
ViewModel
Intents
Old
Change
Render
Listening (V)
Rendering (V)
Business Logic (M)
MVI_Lite Flow with LiveData https://proandroiddev.com/android-unidirectional-state-flow-without-rx-596f2f7637bb
Kotlin (State/Shared)Flow https://quickbirdstudios.com/blog/android-mvi-kotlin-coroutines-flow/
You can think of a channel as a pipe between two coroutines. That pipe facilitates the transfer of information between those two coroutines. One coroutine can send information on that pipe. The other coroutine will wait to receive the information. This concept of communication between coroutines is different than threads.
Do not communicate by sharing memory; instead, share state by communicating.
Hot Steam vs Cold Stream
Data
Data
Data
Channel - HOT Streams
Flow - COLD Streams
Data Steam
Data Steam
Data Steam
Data Steam
Data Steam
Hot Stream (Kotlin Channel) vs Cold Stream (Kotlin Flow) https://www.stefandouma.nl/reactor-hot-stream-vs-cold-stream/
A radio channel is a hot stream.
A CD is a cold stream
Flow - Cold Stream - No Synchronization
Just like a sequence, a flow represents a cold stream of sequential values - ‘asynchronous data streams’.
Channels - Hot Stream - Needs Synchronization
Channels are a great fit to model data sources that are intrinsically hot, data sources that exist without application’s requests for them: incoming network connections, event streams, etc.
Channels are not scoped to a specific lifecycle like Flow. A Channel survives across screens and lifecycles!
The (MV) Intent Channel
Kotlin StateFlow to ShardFlow
Introduce SharedFlow #2034 https://github.com/Kotlin/kotlinx.coroutines/issues/2034
Transforming Android Arch Components
Compose
Kotlin Flow
Kotlin Coroutines
Suspend
Review of App.
Activity/XML to Compose (MainComposeUI.kt)
UI Modifiers
Jetpack Compose
SwiftUI
UI Constraints (Motion Editor) (AddWordComposeUI.kt)
Nav is just Flipp’n Screens (MainActivity.kt)
Set Fun{} on Interactive UI
doSomething = f{}
LiveData to Kotlin Flow (WordDao.kt)
Dagger to Dagger Hilt (StateModule.kt)
Coil (MainComposeUI)
StateFlow/SharedFlow/?Flow (RxJava)
Android 11 and beyond https://www.youtube.com/watch?v=NMFGuy6TRqk
iOS & Combine Framework https://www.youtube.com/watch?v=4GjXq2Sr55Q&feature=youtu.be iOS CS 193P @ Stanford
Questions
-- @Biocodes --