/mvp-compose

Sample to demonstrate the usage of MVP within a Compose application.

Primary LanguageKotlin

sealed interface CounterEvent : Event {
  data object Increment : CounterEvent
  data object Decrement : CounterEvent
}

data class CounterState(
  val count: Int,
  override val eventSink: (CounterEvent) -> Unit,
) : State<CounterEvent>

class CounterPresenter : Presenter<CounterState> {

  @Composable
  override fun present(): CounterState {
    var count by rememberSaveable { mutableIntStateOf(0) }

    return CounterState(
      count = count,
      eventSink = { event ->
        when (event) {
          Increment -> count += 1
          Decrement -> count -= 1
        }
      }
    )
  }
}

@Composable
fun CounterScreen(presenter: CounterPresenter) {
  val state = presenter.present()
  CounterContent(state)
}

Screenshots