nhaarman / acorn

Mastering Android navigation :chipmunk:
https://nhaarman.github.io/acorn
Apache License 2.0
181 stars 7 forks source link

ViewController reacts to the scene transition ends #162

Closed manueldidonna closed 4 years ago

manueldidonna commented 4 years ago

I need to show the soft keyboard if the view list is empty. Anyway the apperance of the soft keyboard resizes the activity's view (default behaviour), so I delayed that action until the scene transition ends with view.postOnAnimationDelayed(HARDCODED_TRANSITION_DURATION) { view.showKeyboard() } but I want to get rid of dependence on the exact value of duration

What do you think about that workaround?


interface OnSceneTransitionListener {
    fun onSceneTransitionEnd()
}

class MyViewController : ViewController,  OnSceneTransitionListener {
    override fun onSceneTransitionEnd() {
        // show the soft keyboard
    }
}

// transition
val newController = viewControllerFor(parent)
callback.attach(newController)
fakeAnimationMethod()
    .doOnEnd {
        callback.complete(newController)
        (newController as? OnSceneTransitionListener)?.onSceneTransitionEnd()
    }