Navigation in MVi
See original GitHub issueConsider 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:
- Created 6 years ago
- Reactions:5
- Comments:11 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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:
Here you go: http://hannesdorfmann.com/android/mosby3-mvi-8
Hope someone find it helpful.