aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-08-29 18:32:02 -0400
committerAllan Wang <me@allanwang.ca>2017-08-30 12:24:19 -0400
commitfeefedf84268641198ee6ab742a000dd3220a471 (patch)
tree2741122fa94b4fae32498dc2bbacf6ef7f837d7c
parent33977d96c6d19a0696dcc08423baba925b219fc3 (diff)
downloadkau-feefedf84268641198ee6ab742a000dd3220a471.tar.gz
kau-feefedf84268641198ee6ab742a000dd3220a471.tar.bz2
kau-feefedf84268641198ee6ab742a000dd3220a471.zip
enhancement/searchview (#48)
* Check if view is attached to window before checking card * Wrap open and close in post
-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()
}
}