aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt49
1 files changed, 27 insertions, 22 deletions
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<SearchItem>()
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()
}
}