From 1890608cb35bb89aea86263ed4000d3284872798 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 15 Dec 2020 12:49:50 +0600 Subject: [PATCH 1/3] start 0.4.13 --- CHANGELOG.md | 2 ++ gradle.properties | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93a27ec0c30..d0cc0f37d24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.4.13 + ## 0.4.12 * `Coroutines` diff --git a/gradle.properties b/gradle.properties index fad45ef5161..3ed06c10d30 100644 --- a/gradle.properties +++ b/gradle.properties @@ -40,5 +40,5 @@ dokka_version=1.4.20 # Project data group=dev.inmo -version=0.4.12 -android_code_version=16 +version=0.4.13 +android_code_version=17 From 830b7aee56c84ca79ce61fdf92cfb9e8fff31bf5 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 15 Dec 2020 13:25:01 +0600 Subject: [PATCH 2/3] horizontal expand/collapse --- CHANGELOG.md | 4 + .../inmo/micro_utils/common/ExpandCollapse.kt | 108 ++++++++++++++---- 2 files changed, 90 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0cc0f37d24..8b371ee67d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.4.13 +* `Common` + * `Android` + * Add expand/collapse functionality for horizontal expand/collapse + ## 0.4.12 * `Coroutines` diff --git a/common/src/main/kotlin/dev/inmo/micro_utils/common/ExpandCollapse.kt b/common/src/main/kotlin/dev/inmo/micro_utils/common/ExpandCollapse.kt index 4fba2b56349..33e8a8322ed 100644 --- a/common/src/main/kotlin/dev/inmo/micro_utils/common/ExpandCollapse.kt +++ b/common/src/main/kotlin/dev/inmo/micro_utils/common/ExpandCollapse.kt @@ -5,23 +5,44 @@ import android.view.ViewGroup import android.view.animation.Animation import android.view.animation.Transformation -@PreviewFeature -fun View.expand( +private fun View.performExpand( duration: Long = 500, targetWidth: Int = ViewGroup.LayoutParams.MATCH_PARENT, - targetHeight: Int = ViewGroup.LayoutParams.WRAP_CONTENT + targetHeight: Int = ViewGroup.LayoutParams.WRAP_CONTENT, + onMeasured: View.() -> Unit, + onPerformAnimation: View.(interpolatedTime: Float, t: Transformation?) -> Unit ) { measure(targetWidth, targetHeight) - val measuredHeight: Int = measuredHeight - layoutParams.height = 0 + onMeasured() visibility = View.VISIBLE val a: Animation = object : Animation() { override fun applyTransformation(interpolatedTime: Float, t: Transformation?) { super.applyTransformation(interpolatedTime, t) - layoutParams.height = if (interpolatedTime == 1f) targetHeight else (measuredHeight * interpolatedTime).toInt() + onPerformAnimation(interpolatedTime, t) requestLayout() } + override fun willChangeBounds(): Boolean = true + } + + a.duration = duration + startAnimation(a) +} + +private fun View.performCollapse( + duration: Long = 500, + onPerformAnimation: View.(interpolatedTime: Float, t: Transformation?) -> Unit +) { + val a: Animation = object : Animation() { + override fun applyTransformation(interpolatedTime: Float, t: Transformation?) { + if (interpolatedTime == 1f) { + gone() + } else { + onPerformAnimation(interpolatedTime, t) + requestLayout() + } + } + override fun willChangeBounds(): Boolean { return true } @@ -32,27 +53,58 @@ fun View.expand( startAnimation(a) } +@PreviewFeature +fun View.expand( + duration: Long = 500, + targetWidth: Int = ViewGroup.LayoutParams.MATCH_PARENT, + targetHeight: Int = ViewGroup.LayoutParams.WRAP_CONTENT +) { + var measuredHeight = 0 + performExpand( + duration, + targetWidth, + targetHeight, + { + measuredHeight = this.measuredHeight + } + ) { interpolatedTime, _ -> + layoutParams.height = if (interpolatedTime == 1f) targetHeight else (measuredHeight * interpolatedTime).toInt() + } +} + +@PreviewFeature +fun View.expandHorizontally( + duration: Long = 500, + targetWidth: Int = ViewGroup.LayoutParams.MATCH_PARENT, + targetHeight: Int = ViewGroup.LayoutParams.WRAP_CONTENT +) { + var measuredWidth = 0 + performExpand( + duration, + targetWidth, + targetHeight, + { + measuredWidth = this.measuredWidth + } + ) { interpolatedTime, _ -> + layoutParams.width = if (interpolatedTime == 1f) targetWidth else (measuredWidth * interpolatedTime).toInt() + } +} + @PreviewFeature fun View.collapse(duration: Long = 500) { val initialHeight: Int = measuredHeight - val a: Animation = object : Animation() { - override fun applyTransformation(interpolatedTime: Float, t: Transformation?) { - if (interpolatedTime == 1f) { - visibility = View.GONE - } else { - layoutParams.height = initialHeight - (initialHeight * interpolatedTime).toInt() - requestLayout() - } - } - - override fun willChangeBounds(): Boolean { - return true - } + performCollapse(duration) { interpolatedTime, _ -> + layoutParams.height = initialHeight - (initialHeight * interpolatedTime).toInt() } +} - a.duration = duration - - startAnimation(a) +@PreviewFeature +fun View.collapseHorizontally(duration: Long = 500) { + val initialWidth: Int = measuredWidth + performCollapse(duration) { interpolatedTime, _ -> + layoutParams.width = initialWidth - (initialWidth * interpolatedTime).toInt() + } } @PreviewFeature @@ -74,3 +126,15 @@ fun View.toggleExpandState(duration: Long = 500): Boolean = if (isCollapsed) { collapse(duration) false } + +/** + * @return true in case of expanding + */ +@PreviewFeature +fun View.toggleExpandHorizontallyState(duration: Long = 500): Boolean = if (isCollapsed) { + expandHorizontally(duration) + true +} else { + collapseHorizontally(duration) + false +} From 67c595b44071abd90d57e80ff2a25acd41291e79 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 15 Dec 2020 13:26:34 +0600 Subject: [PATCH 3/3] small refactor in expand/collapse --- .../main/kotlin/dev/inmo/micro_utils/common/ExpandCollapse.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/kotlin/dev/inmo/micro_utils/common/ExpandCollapse.kt b/common/src/main/kotlin/dev/inmo/micro_utils/common/ExpandCollapse.kt index 33e8a8322ed..587747864fb 100644 --- a/common/src/main/kotlin/dev/inmo/micro_utils/common/ExpandCollapse.kt +++ b/common/src/main/kotlin/dev/inmo/micro_utils/common/ExpandCollapse.kt @@ -14,7 +14,7 @@ private fun View.performExpand( ) { measure(targetWidth, targetHeight) onMeasured() - visibility = View.VISIBLE + show() val a: Animation = object : Animation() { override fun applyTransformation(interpolatedTime: Float, t: Transformation?) { super.applyTransformation(interpolatedTime, t)