REACTIVE APPS WITH Model-view-intent-Part 8-navigation REACTIVE APPS WITH Model-view-intent-Part 8-navigation

In our last blog post, we looked at how coordination mode is applied to Android. This time I want to show you how to use it in Model-view-Intent.

If you don’t already know what the coordinator pattern is, I strongly encourage you to go back and read the above.

Applying this pattern in MVI is not that different from MVVM or MVP: we pass lambda to our MviBasePresenter as a callback to the navigation. The interesting thing is how do we trigger these callbacks in a state-driven architecture? Let’s look at a specific example:

class FooPresenter(
  private var navigationCallback: ( () -> Unit)? : MviBasePresenter<FooView> {lateinit var disposable : Disposable
  override fun bindIntents(a){
    val intent1 = ...
    val intent2 = ...
    val intents = Observable.merge(intent1, intent2)

    val state = intents.switchMap { ... }

    // This is the interesting part
    val sharedState = state.share()
    disposable = sharedState.filter{ state ->
      state isState.Foo }.subscribe { navigationCallback!! () } subscribeViewState(sharedState, FooView::render) }override fun unbindIntents(a){
    disposable.dispose() / / the disposable navigation
    navigationCallback = null // Avoid memory leaks}}Copy the code

The idea is: The Share () operator of RxJava reuses the Observable that normally renders the state of the View layer. Combined with the.filter() operator, the Observable can listen to a certain state. After that, when the state is observed, the corresponding navigation operation is triggered. The coordinator pattern then works as described in my previous blog post.


Series directory

Building responsive Apps with MVI

  • Part 1: Model
  • Part 2: View and Intent
  • Part 3: State Reducer
  • Part 4: Independent UI Components
  • Part 5: Debugging with ease
  • Part 6: Restoring State
  • Part 7: Timing (SingleLiveEvent problem)
  • Part 8: In-App Navigation

Building responsive Apps with MVI

  • Building Responsive Apps with MVI (1): What is a Model
  • Build a responsive APP with MVI :View layer and Intent Layer
  • Building responsive Apps with MVI [C]: State folding
  • Build responsive Apps with MVI [4]: Independent UI components
  • Build responsive Apps with MVI: Easy Debug
  • Build a responsive APP with MVI [vi]: Restore state
  • Building responsive Apps with MVI [7]: Timing (SingleLiveEvent Problem)
  • Building responsive Apps with MVI [8]: Navigation

“Use MVI to build responsive APP” actual combat

  • Combat: Use MVI to build responsive & functional Github client

About me

If you think this article is valuable to you, welcome to ❤️, and also welcome to follow my blog or Github.

If you feel that the article is not enough, please also urge me to write a better article by paying attention to it — in case I make progress one day?

  • My Android learning system
  • About the article error correction
  • About paying for knowledge