From feefedf84268641198ee6ab742a000dd3220a471 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Tue, 29 Aug 2017 18:32:02 -0400 Subject: enhancement/searchview (#48) * Check if view is attached to window before checking card * Wrap open and close in post --- .../ca/allanwang/kau/searchview/SearchView.kt | 49 ++++++++++++---------- 1 file changed, 27 insertions(+), 22 deletions(-) (limited to 'searchview') diff --git a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt index e7d820e..491fbe9 100644 --- a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt +++ b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt @@ -5,6 +5,7 @@ import android.content.Context import android.content.res.ColorStateList import android.graphics.Color import android.support.annotation.ColorInt +import android.support.annotation.ColorRes import android.support.annotation.IdRes import android.support.transition.ChangeBounds import android.support.transition.TransitionManager @@ -214,7 +215,7 @@ class SearchView @JvmOverloads constructor( val adapter = FastItemAdapter() var menuItem: MenuItem? = null val isOpen: Boolean - get() = card.isVisible + get() = isAttachedToWindow && card.isVisible /* * Ripple start points and search view offset @@ -372,34 +373,38 @@ class SearchView @JvmOverloads constructor( fun revealOpen() { if (isOpen) return - /** - * The y component is relative to the cardView, but it hasn't been drawn yet so its own height is 0 - * We therefore use half the menuItem height, which is a close approximation to our intended value - * The cardView matches the parent's width, so menuX is correct - */ - configs.openListener?.invoke(this) - shadow.fadeIn() - editText.showKeyboard() - card.circularReveal(menuX, menuHalfHeight, duration = configs.revealDuration) { - cardTransition() - recycler.visible() + post { + /** + * The y component is relative to the cardView, but it hasn't been drawn yet so its own height is 0 + * We therefore use half the menuItem height, which is a close approximation to our intended value + * The cardView matches the parent's width, so menuX is correct + */ + configs.openListener?.invoke(this) + shadow.fadeIn() + editText.showKeyboard() + card.circularReveal(menuX, menuHalfHeight, duration = configs.revealDuration) { + cardTransition() + recycler.visible() + } } } fun revealClose() { if (!isOpen) return - shadow.fadeOut(duration = configs.transitionDuration) - cardTransition { - addEndListener { - card.circularHide(menuX, menuHalfHeight, duration = configs.revealDuration, - onFinish = { - configs.closeListener?.invoke(this@SearchView) - if (configs.shouldClearOnClose) editText.text.clear() - }) + post { + shadow.fadeOut(duration = configs.transitionDuration) + cardTransition { + addEndListener { + card.circularHide(menuX, menuHalfHeight, duration = configs.revealDuration, + onFinish = { + configs.closeListener?.invoke(this@SearchView) + if (configs.shouldClearOnClose) editText.text.clear() + }) + } } + recycler.gone() + editText.hideKeyboard() } - recycler.gone() - editText.hideKeyboard() } } -- cgit v1.2.3