-
Notifications
You must be signed in to change notification settings - Fork 841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
We may have to make breaking API changes for Presenter #262
Comments
I have some concerns about the 1st option. Although Mosby doesn't specify that calls to So I think this will make this callback potentially misused, by a misguided user. I understand that this is a workaround and they tend to be ugly. I'm not sure exactly what better option for |
Exactly my thoughts, thanks for your feedback. I would also go with Option 2 and add a interface MvpPresenter<V extends MvpView> {
public void attachView(V view);
@Deprecated public void detachView(boolean retain); // old
public void detachView(); // new
public void destroy(); // new
} class MvpBasePresenter<V> implements MvpPresenter<V> {
@Deprecated
@Override
public void detachView(boolean retainInstance){
}
@Override
public void detachView(){
detachView(true);
}
@Override
public void destroy(){
detachView(false);
}
} However, the only remainig question is whether or not we can remove interface MvpPresenter<V extends MvpView> {
public void attachView(V view);
public void detachView(); // new
public void destroy(); // new
} I think it is possible to do so because in concrete class So basically remove the deprecated method from interface but add it to each Presenter class to avoid compile errors. |
I think it's best to go with option 2 but without making it a breaking change. You should be able to remove the method I'm currently having some issues with the Fragment's back stack and option 2 should solve this. |
See #274 |
Reading this I have a quick question regarding the current's presenter lifecycle. Is there any method that currently signalize an |
Until now
Presenter
basically just have to "lifecycle callbacks":Presenter.attachViiew(V view)
andPresenter.detachView(boolean retainInstance)
.Activity and Fragment (since #257 ) use the lifecycle pair
onStart()
-onStop()
to callpresenter.attachView()
andpresenter.detachView(retainInstance)
.There are some problems with this while determining if a presenter should be retained (the boolean flag of
presenter.detachView(retainInstance)
). The problem is that inonStop()
we don't know whether or not the Activity or Fragment will finish and therefore Presenter destroyed permanently (presenter.detachView(retainInstance = false)
).Example Activity with
FLAG_ACTIVITY_CLEAR_TOP
. Let's say we have the following Activities:A -> B -> C -> D -> E (E foreground)
and then we call start the ActivityB
withFLAG_ACTIVITY_CLEAR_TOP
fromE
. Then Activity C and D have reachedonStop()
before and calledpresenter.detachView( retainInstance = true )�
but afterwards C.onDestoy() and D.onDestroy() is called but we don't callpresenter.detachView(retainInstance = false)
from there.So we could change the lifecylce from pair
onStart()
-onStop()
toonCreate()
-onDestroy()
but this has other complications like for MVI intents might be triggered in Activitysuper.onCreate()
but the UI hasn't been initialized yet (i.e.setContentView()
is traditionally called after super.onCreate() ).The easier path to solve this problem is to keep
onStart()
-onStop()
pair but either:presenter.detachView()
inonStop()
and maybe inonDestroy()
again. We guarantee thatpresenter.detachView(retainInstance = false )
is called only once. Example from the previous withFLAG_ACTIVITY_CLEAR_TOP
. Then Activity C.onStop() callspresenter.detachView(retainInstance = true)
and some time laterpresenter.detachView(retainInstance = false)
is called too (when Activity B is started with with FLAG_ACTIVITY_CLEAR_TOP).Presenter.detachView(boolean retainInstance)
into two methodspresenter.detachView()
(without boolean parameter) and this one is called inonStop()
andpresenter.destroy()
which is called inonDestroy()
once we are sure that the Activity / Fragment is destroyed permanently. Sopresenter.destroy()
is exactly the same aspresenter.detachView(retainInstance = false)
right now.Option 1. is not a breaking API change and most apps should be fine. We also never claimed that there are equaly many
presenter.attachView()
andpresenter.detachView()
calls.Option 2. is a breaking API change and would be released as Mosby 4.0.0
I would like to hear your feedback. Any thoughts?
The text was updated successfully, but these errors were encountered: