mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 12:07:28 +00:00
Create Presentation module and remove Presenter from core
This commit is contained in:
@@ -0,0 +1 @@
|
||||
/build
|
||||
@@ -0,0 +1,14 @@
|
||||
plugins {
|
||||
id("io.element.android-library")
|
||||
alias(libs.plugins.molecule)
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "io.element.android.x.libraries.presentation"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(libs.dagger)
|
||||
api(libs.appyx.core)
|
||||
api(libs.androidx.lifecycle.runtime)
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package io.element.android.x.presentation
|
||||
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import app.cash.molecule.AndroidUiDispatcher
|
||||
import app.cash.molecule.RecompositionClock
|
||||
import app.cash.molecule.launchMolecule
|
||||
import com.bumble.appyx.core.node.Node
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
inline fun <reified State, reified Event> Node.presenterConnector(presenter: Presenter<State, Event>): NodePresenterConnector<State, Event> {
|
||||
return NodePresenterConnector(node = this, presenter = presenter)
|
||||
}
|
||||
|
||||
class NodePresenterConnector<State, Event>(private val node: Node, presenter: Presenter<State, Event>) {
|
||||
|
||||
private val moleculeScope = CoroutineScope(node.lifecycleScope.coroutineContext + AndroidUiDispatcher.Main)
|
||||
private val eventFlow: MutableSharedFlow<Event> = MutableSharedFlow(extraBufferCapacity = 64)
|
||||
|
||||
val stateFlow: StateFlow<State> = moleculeScope.launchMolecule(RecompositionClock.ContextClock) {
|
||||
presenter.present(events = eventFlow)
|
||||
}
|
||||
|
||||
fun emitEvent(event: Event) {
|
||||
eventFlow.tryEmit(event)
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package io.element.android.x.core.architecture
|
||||
package io.element.android.x.presentation
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
Reference in New Issue
Block a user