GCX-HCI / ThirtyInch

a MVP library for Android favoring a stateful Presenter
Apache License 2.0
1.03k stars 101 forks source link

sendToView #155

Closed mikaelzero closed 6 years ago

mikaelzero commented 6 years ago

have to use sendToView() to update the view? why not bindView in onCreate

passsy commented 6 years ago

The view is bound after it is ready to use, which is after onStart. This prevents you from accessing the view before the layout is inflated or fragments are commited.

The presenter #onCreate is called before your Activity#onCreate().

mikaelzero commented 6 years ago

Thank you for your answer

use sendToView before onStart use getView other state is right?

passsy commented 6 years ago

It depends. I use getView when the view calls a method of my presenter and I can synchronously update the view. If anything is async I'd use sendToView.

Alternatively you can write some kind of render method. Update you model in the presenter and call render which is the only place the view gets updated. Like this:

private val count = 0

override fun onAttachView(view: MyView) {
    render()
}

override fun onButtonPressed() {
    count++
    render()
}

private fun render() {
    if (view == null) return // view not attached

    view.updateCount(count)
    // ...
}
mikaelzero commented 6 years ago

i think you use sendToView becasue of not call setContetView() if i call bindView after setContentView() or inflate() getView() can work i think...