question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Navigation in MVi

See original GitHub issue

Consider such a demand:Click the button to post data to the server and then navigate to the other Activity when request success. I modified the ProductDetailsPresenter and ProductDetailsActivity to provide some test for me.

I add a testBtnIntent() method for the ProductDetailsView to handle a click intent.

public class ProductDetailsActivity extends MviActivity<ProductDetailsView, ProductDetailsPresenter>
    implements ProductDetailsView {

    @Override
    public Observable<Boolean> testBtnIntent() {
      return RxView.clicks(btnTest).share().map(it -> true);;
    }

    @Override public void render(ProductDetailsViewState state) {
    Timber.d("render " + state);

    if (state instanceof ProductDetailsViewState.LoadingState) {
      renderLoading();
    } else if (state instanceof ProductDetailsViewState.DataState) {
      renderData((ProductDetailsViewState.DataState) state);
    } else if (state instanceof ProductDetailsViewState.ErrorState) {
      renderError();
    } else if (state instanceof ProductDetailsViewState.TestViewState) {
      TestClickActivity.start(this);
    } else {
      throw new IllegalStateException("Unknown state " + state);
    }
  }
}

And then mergeWith the loadDetails method

 @Override protected void bindIntents() {
    ...
    Observable<ProductDetailsViewState> loadDetails =
        intent(ProductDetailsView::loadDetailsIntent)
            .doOnNext(productId -> Timber.d("intent: load details for product id = %s", productId))
            .flatMap(interactor::getDetails)
            .observeOn(AndroidSchedulers.mainThread());

    Observable<ProductDetailsViewState> clickTest =
        intent(ProductDetailsView::testBtnIntent)
        .map((aBoolean) ->  new ProductDetailsViewState.TestViewState());

    subscribeViewState(loadDetails.mergeWith(clickTest), ProductDetailsView::render);
  }

Because the viewStateBehaviorSubject will reemit the latest viewstate , so it will always reemit the clickTest when I go back the previous page and the TestClickActivity will open again and again, The expected should be to go back to the previous page without reemit the click event. Sorry for my bad English. hope I can explanation of this. And can you give me some suggestion?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:5
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
sockeqwecommented, Apr 11, 2018

Jfyi: I have figured out a simple pattern of how to do navigation properly (not only MVI related, but works well with MVI).

I can share it next week as I’m going to present it on a Meetup next Monday.

Stay tuned.

Andy Byrnes notifications@github.com schrieb am Mi., 11. Apr. 2018, 06:22:

Would it be feasible to allow certain View States to be consumed instead of replacing the previous one?

@skykelsey https://github.com/skykelsey For this I’ve been having a dummy state that gets emitted by navigation intents (I call it NoOp) and is just filtered out to avoid any unnecessary renderings:

val intent1 = intent(…)val intent2 = intent(…) val viewStateObservable = Observable.merge(intent1, intent1).filter { it !is NoOp } subscribeViewState(viewStateObservable, View::render)

This, however, doesn’t solve the main problem at hand, for which I still haven’t come up with an elegant solution, unfortunately. It doesn’t seem like Mosby is well equipped to handle navigation in the presentation layer. So in the meantime I’ve implemented a base presenter that inherits from MviPresenter and hacks away at its implementation details to retrieve the previous view state, if it exists, and directly notify the view that a navigation event has occurred. This, combined with filtering out NoOp view states, has yet to cause me any issues.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sockeqwe/mosby/issues/261#issuecomment-380322785, or mute the thread https://github.com/notifications/unsubscribe-auth/AAjnrgjDcIoSd1TIj7nYK38vlE5ctmrdks5tnYUegaJpZM4ONlOH .

3reactions
sockeqwecommented, May 6, 2018

Here you go: http://hannesdorfmann.com/android/mosby3-mvi-8

Hope someone find it helpful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

GithubCompose (Kotlin + Jetpack Compose + Navigation + MVI)
GithubCompose is a sample project that uses Compose + MVI + Navigation Component to presents a modern approach to Android app development.
Read more >
Reactive Apps with Model-View-Intent - Part 8: Navigation
Model-View-Intent MVI on Android by using Mosby 3. Navigation in MVI.
Read more >
MVI — another member of the MV* band - ProAndroidDev
Navigation. Navigation in MVI architecture is still an open question. One approach is that navigation should be a part of our state.
Read more >
MVI Inc. - Facebook
MVI Inc., Broomfield, Colorado. 7428 likes · 9 talking about this. Mobile Video Integration Inc. http://gm-navigation.com.
Read more >
GPS Navigation System from OEM Manufactures
MVI Inc is the leading direct to consumer distributor for OEM GPS Navigation, Camera Systems and Mobile Video Entertainment.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found