ui: migrate fully to physics animations
More or less looks the same, mostly since I can't figure out how to make springs work well. But it's fine enough.
This commit is contained in:
@@ -40,6 +40,7 @@ import androidx.core.view.doOnLayout
|
|||||||
import androidx.core.view.isEmpty
|
import androidx.core.view.isEmpty
|
||||||
import androidx.core.view.updateMarginsRelative
|
import androidx.core.view.updateMarginsRelative
|
||||||
import androidx.core.widget.ImageViewCompat
|
import androidx.core.widget.ImageViewCompat
|
||||||
|
import androidx.dynamicanimation.animation.SpringAnimation
|
||||||
import coil3.ImageLoader
|
import coil3.ImageLoader
|
||||||
import coil3.asImage
|
import coil3.asImage
|
||||||
import coil3.request.ImageRequest
|
import coil3.request.ImageRequest
|
||||||
@@ -60,8 +61,8 @@ import org.oxycblt.auxio.image.coil.RoundedRectTransformation
|
|||||||
import org.oxycblt.auxio.image.coil.SmatteringCoverCollection
|
import org.oxycblt.auxio.image.coil.SmatteringCoverCollection
|
||||||
import org.oxycblt.auxio.image.coil.SquareCropTransformation
|
import org.oxycblt.auxio.image.coil.SquareCropTransformation
|
||||||
import org.oxycblt.auxio.image.coil.StackCoverCollection
|
import org.oxycblt.auxio.image.coil.StackCoverCollection
|
||||||
import org.oxycblt.auxio.ui.MaterialFader
|
import org.oxycblt.auxio.ui.Effect
|
||||||
import org.oxycblt.auxio.ui.MotionHandle
|
import org.oxycblt.auxio.ui.Spatial
|
||||||
import org.oxycblt.auxio.ui.UISettings
|
import org.oxycblt.auxio.ui.UISettings
|
||||||
import org.oxycblt.auxio.util.getAttrColorCompat
|
import org.oxycblt.auxio.util.getAttrColorCompat
|
||||||
import org.oxycblt.auxio.util.getColorCompat
|
import org.oxycblt.auxio.util.getColorCompat
|
||||||
@@ -104,8 +105,9 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
|||||||
private val selectionBadge: ImageView?
|
private val selectionBadge: ImageView?
|
||||||
private val iconSize: Int?
|
private val iconSize: Int?
|
||||||
|
|
||||||
private val fader = MaterialFader.new(context)
|
private val checkScaleSpring = Spatial.FAST
|
||||||
private var fadeAnimator: MotionHandle? = null
|
private val checkAlphaSpring = Effect.FAST
|
||||||
|
private var fadeAnimators: List<SpringAnimation>? = null
|
||||||
private val indicatorMatrix = Matrix()
|
private val indicatorMatrix = Matrix()
|
||||||
private val indicatorMatrixSrc = RectF()
|
private val indicatorMatrixSrc = RectF()
|
||||||
private val indicatorMatrixDst = RectF()
|
private val indicatorMatrixDst = RectF()
|
||||||
@@ -340,10 +342,17 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun invalidateSelectionIndicatorAlpha(selectionBadge: ImageView) {
|
private fun invalidateSelectionIndicatorAlpha(selectionBadge: ImageView) {
|
||||||
fadeAnimator?.cancel()
|
fadeAnimators?.forEach { it.cancel() }
|
||||||
fadeAnimator =
|
val scaleAnim: SpringAnimation
|
||||||
(if (isActivated) fader.fadeIn(selectionBadge) else fader.fadeOut(selectionBadge))
|
val alphaAnim: SpringAnimation
|
||||||
.also { it.start() }
|
if (isActivated) {
|
||||||
|
scaleAnim = checkScaleSpring.scale(selectionBadge, 1.0f)
|
||||||
|
alphaAnim = checkAlphaSpring.alpha(selectionBadge, 1.0f)
|
||||||
|
} else {
|
||||||
|
scaleAnim = checkScaleSpring.scale(selectionBadge, 0.9f)
|
||||||
|
alphaAnim = checkAlphaSpring.alpha(selectionBadge, 0.0f)
|
||||||
|
}
|
||||||
|
fadeAnimators = listOf(scaleAnim, alphaAnim)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -60,15 +60,16 @@ import kotlin.math.max
|
|||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
import org.oxycblt.auxio.R
|
import org.oxycblt.auxio.R
|
||||||
|
import org.oxycblt.auxio.ui.Effect
|
||||||
import org.oxycblt.auxio.ui.ExpressiveShapes
|
import org.oxycblt.auxio.ui.ExpressiveShapes
|
||||||
import org.oxycblt.auxio.ui.MaterialSlider
|
import org.oxycblt.auxio.ui.Spatial
|
||||||
import org.oxycblt.auxio.ui.MotionHandle
|
|
||||||
import org.oxycblt.auxio.util.getAttrColorCompat
|
import org.oxycblt.auxio.util.getAttrColorCompat
|
||||||
import org.oxycblt.auxio.util.getAttrResourceId
|
import org.oxycblt.auxio.util.getAttrResourceId
|
||||||
import org.oxycblt.auxio.util.getDimenPixels
|
import org.oxycblt.auxio.util.getDimenPixels
|
||||||
import org.oxycblt.auxio.util.inflater
|
import org.oxycblt.auxio.util.inflater
|
||||||
import org.oxycblt.auxio.util.isRtl
|
import org.oxycblt.auxio.util.isRtl
|
||||||
import org.oxycblt.auxio.util.isUnder
|
import org.oxycblt.auxio.util.isUnder
|
||||||
|
import org.oxycblt.auxio.util.scale
|
||||||
import org.oxycblt.auxio.util.systemBarInsetsCompat
|
import org.oxycblt.auxio.util.systemBarInsetsCompat
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -107,17 +108,22 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
|||||||
// Thumb
|
// Thumb
|
||||||
private val thumbWidth = context.getDimenPixels(R.dimen.spacing_mid_medium)
|
private val thumbWidth = context.getDimenPixels(R.dimen.spacing_mid_medium)
|
||||||
private val thumbHeight = context.getDimenPixels(R.dimen.size_touchable_medium)
|
private val thumbHeight = context.getDimenPixels(R.dimen.size_touchable_medium)
|
||||||
private val thumbSlider = MaterialSlider.small(context, thumbWidth)
|
private var thumbAnimator: SpringAnimation? = null
|
||||||
private var thumbAnimator: MotionHandle? = null
|
|
||||||
|
|
||||||
@SuppressLint("InflateParams")
|
@SuppressLint("InflateParams")
|
||||||
private val thumbView =
|
private val thumbView =
|
||||||
context.inflater.inflate(R.layout.view_scroll_thumb, null).apply {
|
context.inflater.inflate(R.layout.view_scroll_thumb, null).apply {
|
||||||
thumbSlider.jumpOut(this)
|
translationX = thumbWidth.toFloat()
|
||||||
}
|
}
|
||||||
private val thumbPadding = Rect(0, 0, 0, 0)
|
private val thumbPadding = Rect(0, 0, 0, 0)
|
||||||
private var thumbOffset = 0
|
private var thumbOffset = 0
|
||||||
|
|
||||||
|
private val thumbTranslateInSpring = Spatial.DEFAULT
|
||||||
|
private val thumbTranslateOutSpring = Spatial.FAST
|
||||||
|
|
||||||
|
private val popupScaleSpring = Spatial.DEFAULT
|
||||||
|
private val popupAlphaSpring = Effect.DEFAULT
|
||||||
|
|
||||||
private var showingThumb = false
|
private var showingThumb = false
|
||||||
private val hideThumbRunnable = Runnable {
|
private val hideThumbRunnable = Runnable {
|
||||||
if (!dragging) {
|
if (!dragging) {
|
||||||
@@ -186,6 +192,8 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
|||||||
marginEnd = context.getDimenPixels(R.dimen.size_touchable_small)
|
marginEnd = context.getDimenPixels(R.dimen.size_touchable_small)
|
||||||
gravity = Gravity.CENTER_HORIZONTAL or Gravity.TOP
|
gravity = Gravity.CENTER_HORIZONTAL or Gravity.TOP
|
||||||
}
|
}
|
||||||
|
scale = 0.5f
|
||||||
|
alpha = 0.0f
|
||||||
}
|
}
|
||||||
private val popupTextStaggerDelayMillis =
|
private val popupTextStaggerDelayMillis =
|
||||||
MotionUtils.resolveThemeDuration(context, MR.attr.motionDurationShort2, 100).toLong()
|
MotionUtils.resolveThemeDuration(context, MR.attr.motionDurationShort2, 100).toLong()
|
||||||
@@ -207,7 +215,8 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
|||||||
private var popupTextAlphaAnimation: SpringAnimation? = null
|
private var popupTextAlphaAnimation: SpringAnimation? = null
|
||||||
private val popupTextRevealRunnable = Runnable {
|
private val popupTextRevealRunnable = Runnable {
|
||||||
if (showingPopup) {
|
if (showingPopup) {
|
||||||
animatePopupTextIn()
|
popupShapeScaleAnimation?.cancel()
|
||||||
|
popupShapeScaleAnimation = popupScaleSpring.scale(popupView, 0f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private var showingPopup = false
|
private var showingPopup = false
|
||||||
@@ -272,7 +281,6 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
|||||||
init {
|
init {
|
||||||
overlay.add(thumbView)
|
overlay.add(thumbView)
|
||||||
overlay.add(popupView)
|
overlay.add(popupView)
|
||||||
jumpOutPopup()
|
|
||||||
|
|
||||||
addItemDecoration(
|
addItemDecoration(
|
||||||
object : ItemDecoration() {
|
object : ItemDecoration() {
|
||||||
@@ -543,7 +551,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
|||||||
|
|
||||||
showingThumb = true
|
showingThumb = true
|
||||||
thumbAnimator?.cancel()
|
thumbAnimator?.cancel()
|
||||||
thumbAnimator = thumbSlider.slideIn(thumbView).also { it.start() }
|
thumbAnimator = thumbTranslateInSpring.translateX(thumbView, 0f)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun hideThumb() {
|
private fun hideThumb() {
|
||||||
@@ -553,7 +561,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
|||||||
|
|
||||||
showingThumb = false
|
showingThumb = false
|
||||||
thumbAnimator?.cancel()
|
thumbAnimator?.cancel()
|
||||||
thumbAnimator = thumbSlider.slideOut(thumbView).also { it.start() }
|
thumbAnimator = thumbTranslateOutSpring.translateX(thumbView, thumbWidth.toFloat())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showPopup() {
|
private fun showPopup() {
|
||||||
@@ -566,9 +574,10 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
|||||||
|
|
||||||
showingPopup = true
|
showingPopup = true
|
||||||
resetPopupTextAutoScaleConfig()
|
resetPopupTextAutoScaleConfig()
|
||||||
cancelPopupAnimations()
|
popupShapeScaleAnimation?.cancel()
|
||||||
animatePopupShapeIn()
|
popupShapeAlphaAnimation?.cancel()
|
||||||
popupView.postDelayed(popupTextRevealRunnable, popupTextStaggerDelayMillis)
|
popupShapeScaleAnimation = popupScaleSpring.scale(popupView, 1f)
|
||||||
|
popupShapeAlphaAnimation = popupAlphaSpring.alpha(popupView, 1f)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun hidePopup() {
|
private fun hidePopup() {
|
||||||
@@ -577,115 +586,10 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
|||||||
}
|
}
|
||||||
|
|
||||||
showingPopup = false
|
showingPopup = false
|
||||||
cancelPopupAnimations()
|
|
||||||
animatePopupTextOut()
|
|
||||||
animatePopupShapeOut()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun jumpOutPopup() {
|
|
||||||
popupBackgroundDrawable.revealScale = POPUP_SHAPE_HIDDEN_SCALE
|
|
||||||
popupBackgroundDrawable.revealAlpha = 0f
|
|
||||||
popupTextView.alpha = 0f
|
|
||||||
popupTextView.scaleX = POPUP_TEXT_HIDDEN_SCALE
|
|
||||||
popupTextView.scaleY = POPUP_TEXT_HIDDEN_SCALE
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun cancelPopupAnimations() {
|
|
||||||
popupView.removeCallbacks(popupTextRevealRunnable)
|
|
||||||
popupShapeScaleAnimation?.cancel()
|
popupShapeScaleAnimation?.cancel()
|
||||||
popupShapeScaleAnimation = null
|
|
||||||
popupShapeAlphaAnimation?.cancel()
|
popupShapeAlphaAnimation?.cancel()
|
||||||
popupShapeAlphaAnimation = null
|
popupShapeScaleAnimation = popupScaleSpring.scale(popupView, 0.5f)
|
||||||
popupTextScaleAnimation?.cancel()
|
popupShapeAlphaAnimation = popupAlphaSpring.alpha(popupView, 0f)
|
||||||
popupTextScaleAnimation = null
|
|
||||||
popupTextAlphaAnimation?.cancel()
|
|
||||||
popupTextAlphaAnimation = null
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun animatePopupShapeIn() {
|
|
||||||
popupShapeScaleAnimation =
|
|
||||||
springTo(
|
|
||||||
startValue = popupBackgroundDrawable.revealScale,
|
|
||||||
finalValue = 1f,
|
|
||||||
springTemplate = popupSpatialSpring,
|
|
||||||
minimumVisibleChange = 0.001f,
|
|
||||||
) {
|
|
||||||
popupBackgroundDrawable.revealScale = it
|
|
||||||
}
|
|
||||||
popupShapeAlphaAnimation =
|
|
||||||
springTo(
|
|
||||||
startValue = popupBackgroundDrawable.revealAlpha,
|
|
||||||
finalValue = 1f,
|
|
||||||
springTemplate = popupEffectsSpring,
|
|
||||||
minimumVisibleChange = 1f / 255f,
|
|
||||||
) {
|
|
||||||
popupBackgroundDrawable.revealAlpha = it
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun animatePopupShapeOut() {
|
|
||||||
popupShapeScaleAnimation =
|
|
||||||
springTo(
|
|
||||||
startValue = popupBackgroundDrawable.revealScale,
|
|
||||||
finalValue = POPUP_SHAPE_HIDDEN_SCALE,
|
|
||||||
springTemplate = popupSpatialSpring,
|
|
||||||
minimumVisibleChange = 0.001f,
|
|
||||||
) {
|
|
||||||
popupBackgroundDrawable.revealScale = it
|
|
||||||
}
|
|
||||||
popupShapeAlphaAnimation =
|
|
||||||
springTo(
|
|
||||||
startValue = popupBackgroundDrawable.revealAlpha,
|
|
||||||
finalValue = 0f,
|
|
||||||
springTemplate = popupEffectsSpring,
|
|
||||||
minimumVisibleChange = 1f / 255f,
|
|
||||||
) {
|
|
||||||
popupBackgroundDrawable.revealAlpha = it
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun animatePopupTextIn() {
|
|
||||||
popupTextScaleAnimation =
|
|
||||||
springTo(
|
|
||||||
startValue = popupTextView.scaleX,
|
|
||||||
finalValue = 1f,
|
|
||||||
springTemplate = popupSpatialSpring,
|
|
||||||
minimumVisibleChange = 0.001f,
|
|
||||||
) {
|
|
||||||
popupTextView.scaleX = it
|
|
||||||
popupTextView.scaleY = it
|
|
||||||
}
|
|
||||||
popupTextAlphaAnimation =
|
|
||||||
springTo(
|
|
||||||
startValue = popupTextView.alpha,
|
|
||||||
finalValue = 1f,
|
|
||||||
springTemplate = popupEffectsSpring,
|
|
||||||
minimumVisibleChange = 1f / 255f,
|
|
||||||
) {
|
|
||||||
popupTextView.alpha = it
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun animatePopupTextOut() {
|
|
||||||
popupTextScaleAnimation =
|
|
||||||
springTo(
|
|
||||||
startValue = popupTextView.scaleX,
|
|
||||||
finalValue = POPUP_TEXT_HIDDEN_SCALE,
|
|
||||||
springTemplate = popupSpatialSpring,
|
|
||||||
minimumVisibleChange = 0.001f,
|
|
||||||
) {
|
|
||||||
popupTextView.scaleX = it
|
|
||||||
popupTextView.scaleY = it
|
|
||||||
}
|
|
||||||
popupTextAlphaAnimation =
|
|
||||||
springTo(
|
|
||||||
startValue = popupTextView.alpha,
|
|
||||||
finalValue = 0f,
|
|
||||||
springTemplate = popupEffectsSpring,
|
|
||||||
minimumVisibleChange = 1f / 255f,
|
|
||||||
) {
|
|
||||||
popupTextView.alpha = it
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createPopupTextView(context: Context): MaterialTextView =
|
private fun createPopupTextView(context: Context): MaterialTextView =
|
||||||
@@ -787,13 +691,14 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
|||||||
finalValue: Float,
|
finalValue: Float,
|
||||||
springTemplate: SpringForce,
|
springTemplate: SpringForce,
|
||||||
minimumVisibleChange: Float,
|
minimumVisibleChange: Float,
|
||||||
|
dampingOverride: Float? = null,
|
||||||
update: (Float) -> Unit,
|
update: (Float) -> Unit,
|
||||||
): SpringAnimation {
|
): SpringAnimation {
|
||||||
val animation =
|
val animation =
|
||||||
SpringAnimation(FloatValueHolder(startValue)).apply {
|
SpringAnimation(FloatValueHolder(startValue)).apply {
|
||||||
spring =
|
spring =
|
||||||
SpringForce().apply {
|
SpringForce().apply {
|
||||||
dampingRatio = springTemplate.dampingRatio
|
dampingRatio = dampingOverride ?: springTemplate.dampingRatio
|
||||||
stiffness = springTemplate.stiffness
|
stiffness = springTemplate.stiffness
|
||||||
finalPosition = finalValue
|
finalPosition = finalValue
|
||||||
}
|
}
|
||||||
@@ -877,7 +782,7 @@ private class SoftBurstPopupDrawable(context: Context) : Drawable() {
|
|||||||
private var shapeAlpha = 255
|
private var shapeAlpha = 255
|
||||||
var revealScale = 1f
|
var revealScale = 1f
|
||||||
set(value) {
|
set(value) {
|
||||||
val clampedValue = value.coerceIn(0f, 1f)
|
val clampedValue = value.coerceAtLeast(0f)
|
||||||
if (field == clampedValue) {
|
if (field == clampedValue) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import android.view.LayoutInflater
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.annotation.XmlRes
|
import androidx.annotation.XmlRes
|
||||||
import androidx.appcompat.widget.Toolbar
|
|
||||||
import androidx.core.view.updatePadding
|
import androidx.core.view.updatePadding
|
||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
@@ -37,6 +36,7 @@ import org.oxycblt.auxio.settings.ui.IntListPreference
|
|||||||
import org.oxycblt.auxio.settings.ui.IntListPreferenceDialog
|
import org.oxycblt.auxio.settings.ui.IntListPreferenceDialog
|
||||||
import org.oxycblt.auxio.settings.ui.PreferenceHeaderItemDecoration
|
import org.oxycblt.auxio.settings.ui.PreferenceHeaderItemDecoration
|
||||||
import org.oxycblt.auxio.settings.ui.WrappedDialogPreference
|
import org.oxycblt.auxio.settings.ui.WrappedDialogPreference
|
||||||
|
import org.oxycblt.auxio.ui.AuxioToolbar
|
||||||
import org.oxycblt.auxio.util.systemBarInsetsCompat
|
import org.oxycblt.auxio.util.systemBarInsetsCompat
|
||||||
import timber.log.Timber as L
|
import timber.log.Timber as L
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ abstract class BasePreferenceFragment(@XmlRes private val screen: Int) :
|
|||||||
|
|
||||||
view.findViewById<AppBarLayout>(R.id.preferences_appbar).liftOnScrollTargetViewId =
|
view.findViewById<AppBarLayout>(R.id.preferences_appbar).liftOnScrollTargetViewId =
|
||||||
androidx.preference.R.id.recycler_view
|
androidx.preference.R.id.recycler_view
|
||||||
view.findViewById<Toolbar>(R.id.preferences_toolbar).apply {
|
view.findViewById<AuxioToolbar>(R.id.preferences_toolbar).apply {
|
||||||
title = preferenceScreen.title
|
title = preferenceScreen.title
|
||||||
setNavigationOnClickListener { findNavController().navigateUp() }
|
setNavigationOnClickListener { findNavController().navigateUp() }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,403 +18,102 @@
|
|||||||
|
|
||||||
package org.oxycblt.auxio.ui
|
package org.oxycblt.auxio.ui
|
||||||
|
|
||||||
import android.animation.TimeInterpolator
|
|
||||||
import android.animation.ValueAnimator
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.annotation.AttrRes
|
import androidx.annotation.AttrRes
|
||||||
import androidx.annotation.StyleRes
|
import androidx.annotation.StyleRes
|
||||||
import androidx.core.view.isInvisible
|
|
||||||
import androidx.dynamicanimation.animation.FloatValueHolder
|
import androidx.dynamicanimation.animation.FloatValueHolder
|
||||||
import androidx.dynamicanimation.animation.SpringAnimation
|
import androidx.dynamicanimation.animation.SpringAnimation
|
||||||
import androidx.dynamicanimation.animation.SpringForce
|
|
||||||
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
|
|
||||||
import com.google.android.material.R as MR
|
import com.google.android.material.R as MR
|
||||||
import com.google.android.material.motion.MotionUtils
|
import com.google.android.material.motion.MotionUtils
|
||||||
|
import org.oxycblt.auxio.util.scale
|
||||||
|
|
||||||
class AnimConfig(
|
class Spatial private constructor(@AttrRes val attr: Int, val defaultStyle: Int) {
|
||||||
context: Context,
|
private fun resolve(context: Context) =
|
||||||
@AttrRes interpolatorRes: Int,
|
MotionUtils.resolveThemeSpringForce(context, attr, defaultStyle)
|
||||||
@AttrRes durationRes: Int,
|
|
||||||
defaultDuration: Int,
|
|
||||||
) {
|
|
||||||
val interpolator: TimeInterpolator =
|
|
||||||
MotionUtils.resolveThemeInterpolator(context, interpolatorRes, FastOutSlowInInterpolator())
|
|
||||||
val duration: Long =
|
|
||||||
MotionUtils.resolveThemeDuration(context, durationRes, defaultDuration).toLong()
|
|
||||||
|
|
||||||
companion object {
|
fun scale(view: View, to: Float, jumpOnCancellation: Boolean = false): SpringAnimation {
|
||||||
val STANDARD = MR.attr.motionEasingStandardInterpolator
|
val from = view.scale
|
||||||
val MEDIUM2 = MR.attr.motionDurationMedium2 to 300
|
val springForce = resolve(view.context)
|
||||||
|
return SpringAnimation(FloatValueHolder(from)).apply {
|
||||||
fun of(context: Context, @AttrRes interpolator: Int, duration: Pair<Int, Int>) =
|
spring = springForce
|
||||||
AnimConfig(context, interpolator, duration.first, duration.second)
|
setStartValue(from)
|
||||||
}
|
setMinimumVisibleChange(0.0001f)
|
||||||
|
addUpdateListener { _, value, _ -> view.scale = value }
|
||||||
inline fun genericFloat(
|
addEndListener { _, canceled, value, _ ->
|
||||||
from: Float,
|
view.scale = if (!canceled || jumpOnCancellation) to else value
|
||||||
to: Float,
|
|
||||||
delayMs: Long = 0,
|
|
||||||
crossinline update: (Float) -> Unit,
|
|
||||||
): ValueAnimator =
|
|
||||||
ValueAnimator.ofFloat(from, to).apply {
|
|
||||||
startDelay = delayMs
|
|
||||||
duration = this@AnimConfig.duration
|
|
||||||
interpolator = this@AnimConfig.interpolator
|
|
||||||
addUpdateListener { update(animatedValue as Float) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface MotionHandle {
|
|
||||||
fun start()
|
|
||||||
|
|
||||||
fun cancel()
|
|
||||||
}
|
|
||||||
|
|
||||||
private object NoOpMotionHandle : MotionHandle {
|
|
||||||
override fun start() = Unit
|
|
||||||
|
|
||||||
override fun cancel() = Unit
|
|
||||||
}
|
|
||||||
|
|
||||||
private class SnapMotionHandle(private val action: () -> Unit) : MotionHandle {
|
|
||||||
private var canceled = false
|
|
||||||
|
|
||||||
override fun start() {
|
|
||||||
if (!canceled) {
|
|
||||||
action()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun cancel() {
|
|
||||||
canceled = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class CompositeMotionHandle(
|
|
||||||
private val handles: List<MotionHandle>,
|
|
||||||
private val onStart: (() -> Unit)? = null,
|
|
||||||
) : MotionHandle {
|
|
||||||
override fun start() {
|
|
||||||
onStart?.invoke()
|
|
||||||
for (handle in handles) {
|
|
||||||
handle.start()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun cancel() {
|
|
||||||
for (handle in handles) {
|
|
||||||
handle.cancel()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private data class SpringToken(@AttrRes val attr: Int, @StyleRes val defaultStyle: Int)
|
|
||||||
|
|
||||||
private object MotionSpringTokens {
|
|
||||||
val FAST_EFFECTS =
|
|
||||||
SpringToken(
|
|
||||||
MR.attr.motionSpringFastEffects,
|
|
||||||
MR.style.Motion_Material3_Spring_Standard_Fast_Effects,
|
|
||||||
)
|
|
||||||
// val DEFAULT_EFFECTS =
|
|
||||||
// SpringToken(
|
|
||||||
// MR.attr.motionSpringDefaultEffects,
|
|
||||||
// MR.style.Motion_Material3_Spring_Standard_Default_Effects,
|
|
||||||
// )
|
|
||||||
// val SLOW_EFFECTS =
|
|
||||||
// SpringToken(
|
|
||||||
// MR.attr.motionSpringSlowEffects,
|
|
||||||
// MR.style.Motion_Material3_Spring_Standard_Slow_Effects,
|
|
||||||
// )
|
|
||||||
val FAST_SPATIAL =
|
|
||||||
SpringToken(
|
|
||||||
MR.attr.motionSpringFastSpatial,
|
|
||||||
MR.style.Motion_Material3_Spring_Standard_Fast_Spatial,
|
|
||||||
)
|
|
||||||
val DEFAULT_SPATIAL =
|
|
||||||
SpringToken(
|
|
||||||
MR.attr.motionSpringDefaultSpatial,
|
|
||||||
MR.style.Motion_Material3_Spring_Standard_Default_Spatial,
|
|
||||||
)
|
|
||||||
// val SLOW_SPATIAL =
|
|
||||||
// SpringToken(
|
|
||||||
// MR.attr.motionSpringSlowSpatial,
|
|
||||||
// MR.style.Motion_Material3_Spring_Standard_Slow_Spatial,
|
|
||||||
// )
|
|
||||||
}
|
|
||||||
|
|
||||||
private class MotionSpring(
|
|
||||||
context: Context,
|
|
||||||
token: SpringToken,
|
|
||||||
private val dampingRatioOverride: Float? = null,
|
|
||||||
) {
|
|
||||||
private val springTemplate =
|
|
||||||
MotionUtils.resolveThemeSpringForce(context, token.attr, token.defaultStyle)
|
|
||||||
|
|
||||||
fun create(
|
|
||||||
startValue: Float,
|
|
||||||
finalValue: Float,
|
|
||||||
minimumVisibleChange: Float,
|
|
||||||
update: (Float) -> Unit,
|
|
||||||
onEnd: ((canceled: Boolean) -> Unit)? = null,
|
|
||||||
): MotionHandle {
|
|
||||||
val animation =
|
|
||||||
SpringAnimation(FloatValueHolder(startValue)).apply {
|
|
||||||
spring =
|
|
||||||
SpringForce().apply {
|
|
||||||
dampingRatio = dampingRatioOverride ?: springTemplate.dampingRatio
|
|
||||||
stiffness = springTemplate.stiffness
|
|
||||||
finalPosition = finalValue
|
|
||||||
}
|
|
||||||
setStartValue(startValue)
|
|
||||||
setMinimumVisibleChange(minimumVisibleChange)
|
|
||||||
addUpdateListener { _, value, _ -> update(value) }
|
|
||||||
addEndListener { _, canceled, value, _ ->
|
|
||||||
update(if (canceled) value else finalValue)
|
|
||||||
onEnd?.invoke(canceled)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return object : MotionHandle {
|
animateToFinalPosition(to)
|
||||||
override fun start() {
|
}
|
||||||
animation.animateToFinalPosition(finalValue)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override fun cancel() {
|
fun translateX(view: View, to: Float, jumpOnCancellation: Boolean = false): SpringAnimation {
|
||||||
animation.cancel()
|
val from = view.translationX
|
||||||
|
val springForce = resolve(view.context)
|
||||||
|
return SpringAnimation(FloatValueHolder(from)).apply {
|
||||||
|
spring = springForce
|
||||||
|
setStartValue(from)
|
||||||
|
setMinimumVisibleChange(0.0001f)
|
||||||
|
addUpdateListener { _, value, _ -> view.translationX = value }
|
||||||
|
addEndListener { _, canceled, value, _ ->
|
||||||
|
view.translationX = if (!canceled || jumpOnCancellation) to else value
|
||||||
}
|
}
|
||||||
|
animateToFinalPosition(to)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun View.resolveSlideTarget(x: Int?): Float {
|
|
||||||
if (x != null) {
|
|
||||||
return x.toFloat()
|
|
||||||
}
|
|
||||||
|
|
||||||
val resolvedWidth = width.takeIf { it > 0 } ?: measuredWidth.takeIf { it > 0 }
|
|
||||||
return (resolvedWidth ?: OFFSCREEN_TRANSLATION_PX.toInt()).toFloat()
|
|
||||||
}
|
|
||||||
|
|
||||||
class MaterialFader
|
|
||||||
private constructor(
|
|
||||||
context: Context,
|
|
||||||
private val scale: Float,
|
|
||||||
alphaOutToken: SpringToken,
|
|
||||||
scaleOutToken: SpringToken,
|
|
||||||
alphaInToken: SpringToken,
|
|
||||||
scaleInToken: SpringToken,
|
|
||||||
scaleOutDampingRatioOverride: Float? = null,
|
|
||||||
scaleInDampingRatioOverride: Float? = null,
|
|
||||||
) {
|
|
||||||
private val alphaOutSpring = MotionSpring(context, alphaOutToken)
|
|
||||||
private val scaleOutSpring =
|
|
||||||
MotionSpring(context, scaleOutToken, dampingRatioOverride = scaleOutDampingRatioOverride)
|
|
||||||
private val alphaInSpring = MotionSpring(context, alphaInToken)
|
|
||||||
private val scaleInSpring =
|
|
||||||
MotionSpring(context, scaleInToken, dampingRatioOverride = scaleInDampingRatioOverride)
|
|
||||||
|
|
||||||
fun jumpToFadeOut(view: View) {
|
|
||||||
view.apply {
|
|
||||||
alpha = 0f
|
|
||||||
scaleX = scale
|
|
||||||
scaleY = scale
|
|
||||||
isInvisible = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun jumpToFadeIn(view: View) {
|
|
||||||
view.apply {
|
|
||||||
alpha = 1f
|
|
||||||
scaleX = 1.0f
|
|
||||||
scaleY = 1.0f
|
|
||||||
isInvisible = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun fadeOut(view: View, onEnd: (() -> Unit)? = null): MotionHandle {
|
|
||||||
if (!view.isLaidOut) {
|
|
||||||
return SnapMotionHandle {
|
|
||||||
jumpToFadeOut(view)
|
|
||||||
onEnd?.invoke()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val alphaMotion =
|
|
||||||
alphaOutSpring.create(
|
|
||||||
view.alpha,
|
|
||||||
0f,
|
|
||||||
ALPHA_MIN_VISIBLE_CHANGE,
|
|
||||||
update = { view.alpha = it },
|
|
||||||
onEnd = { canceled ->
|
|
||||||
view.isInvisible = !canceled
|
|
||||||
if (!canceled) {
|
|
||||||
onEnd?.invoke()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
val scaleXMotion =
|
|
||||||
scaleOutSpring.create(
|
|
||||||
view.scaleX,
|
|
||||||
scale,
|
|
||||||
SCALE_MIN_VISIBLE_CHANGE,
|
|
||||||
update = { view.scaleX = it },
|
|
||||||
)
|
|
||||||
val scaleYMotion =
|
|
||||||
scaleOutSpring.create(
|
|
||||||
view.scaleY,
|
|
||||||
scale,
|
|
||||||
SCALE_MIN_VISIBLE_CHANGE,
|
|
||||||
update = { view.scaleY = it },
|
|
||||||
)
|
|
||||||
return CompositeMotionHandle(
|
|
||||||
listOf(alphaMotion, scaleXMotion, scaleYMotion),
|
|
||||||
onStart = { view.isInvisible = false },
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun fadeIn(view: View, onEnd: (() -> Unit)? = null): MotionHandle {
|
|
||||||
if (!view.isLaidOut) {
|
|
||||||
return SnapMotionHandle {
|
|
||||||
jumpToFadeIn(view)
|
|
||||||
onEnd?.invoke()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val alphaMotion =
|
|
||||||
alphaInSpring.create(
|
|
||||||
view.alpha,
|
|
||||||
1f,
|
|
||||||
ALPHA_MIN_VISIBLE_CHANGE,
|
|
||||||
update = { view.alpha = it },
|
|
||||||
onEnd = { canceled ->
|
|
||||||
if (!canceled) {
|
|
||||||
onEnd?.invoke()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
val scaleXMotion =
|
|
||||||
scaleInSpring.create(
|
|
||||||
view.scaleX,
|
|
||||||
1.0f,
|
|
||||||
SCALE_MIN_VISIBLE_CHANGE,
|
|
||||||
update = { view.scaleX = it },
|
|
||||||
)
|
|
||||||
val scaleYMotion =
|
|
||||||
scaleInSpring.create(
|
|
||||||
view.scaleY,
|
|
||||||
1.0f,
|
|
||||||
SCALE_MIN_VISIBLE_CHANGE,
|
|
||||||
update = { view.scaleY = it },
|
|
||||||
)
|
|
||||||
return CompositeMotionHandle(
|
|
||||||
listOf(alphaMotion, scaleXMotion, scaleYMotion),
|
|
||||||
onStart = { view.isInvisible = false },
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun new(context: Context) =
|
val FAST =
|
||||||
MaterialFader(
|
Spatial(
|
||||||
context,
|
MR.attr.motionSpringFastSpatial,
|
||||||
0.9f,
|
MR.style.Motion_Material3_Spring_Standard_Fast_Spatial,
|
||||||
MotionSpringTokens.FAST_EFFECTS,
|
)
|
||||||
MotionSpringTokens.FAST_SPATIAL,
|
val DEFAULT =
|
||||||
MotionSpringTokens.FAST_EFFECTS,
|
Spatial(
|
||||||
MotionSpringTokens.FAST_SPATIAL,
|
MR.attr.motionSpringDefaultSpatial,
|
||||||
// Material's standard spatial springs are only slightly underdamped (0.9),
|
MR.style.Motion_Material3_Spring_Standard_Default_Spatial,
|
||||||
// which is too restrained for the toolbar swap to read as springy.
|
)
|
||||||
scaleOutDampingRatioOverride = 0.6f,
|
val SLOW =
|
||||||
scaleInDampingRatioOverride = 0.6f,
|
Spatial(
|
||||||
|
MR.attr.motionSpringSlowSpatial,
|
||||||
|
MR.style.Motion_Material3_Spring_Standard_Slow_Spatial,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MaterialFlipper(context: Context) {
|
class Effect private constructor(@AttrRes val attr: Int, @StyleRes val defaultStyle: Int) {
|
||||||
private val fader = MaterialFader.new(context)
|
fun resolve(context: Context) = MotionUtils.resolveThemeSpringForce(context, attr, defaultStyle)
|
||||||
|
|
||||||
fun jump(from: View) {
|
fun alpha(view: View, to: Float, jumpOnCancellation: Boolean = false): SpringAnimation {
|
||||||
fader.jumpToFadeOut(from)
|
val from = view.alpha
|
||||||
}
|
val springForce = resolve(view.context)
|
||||||
|
return SpringAnimation(FloatValueHolder(from)).apply {
|
||||||
fun flip(from: View, to: View): MotionHandle {
|
spring = springForce
|
||||||
var canceled = false
|
setStartValue(from)
|
||||||
var inMotion: MotionHandle = NoOpMotionHandle
|
setMinimumVisibleChange(1f / 255f)
|
||||||
val outMotion =
|
addUpdateListener { _, value, _ -> view.alpha = value }
|
||||||
fader.fadeOut(from) {
|
addEndListener { _, canceled, value, _ ->
|
||||||
if (!canceled) {
|
view.scale = if (!canceled || jumpOnCancellation) to else value
|
||||||
inMotion = fader.fadeIn(to)
|
|
||||||
inMotion.start()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return object : MotionHandle {
|
|
||||||
override fun start() {
|
|
||||||
canceled = false
|
|
||||||
outMotion.start()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun cancel() {
|
|
||||||
canceled = true
|
|
||||||
outMotion.cancel()
|
|
||||||
inMotion.cancel()
|
|
||||||
}
|
}
|
||||||
|
animateToFinalPosition(to)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
class MaterialSlider
|
|
||||||
private constructor(
|
|
||||||
context: Context,
|
|
||||||
private val x: Int?,
|
|
||||||
inSpringToken: SpringToken,
|
|
||||||
outSpringToken: SpringToken,
|
|
||||||
) {
|
|
||||||
private val outSpring = MotionSpring(context, outSpringToken)
|
|
||||||
private val inSpring = MotionSpring(context, inSpringToken)
|
|
||||||
|
|
||||||
fun jumpOut(view: View) {
|
|
||||||
view.translationX = view.resolveSlideTarget(x)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun slideOut(view: View): MotionHandle {
|
|
||||||
val target = view.resolveSlideTarget(x)
|
|
||||||
if (!view.isLaidOut) {
|
|
||||||
return SnapMotionHandle { view.translationX = target }
|
|
||||||
}
|
|
||||||
if (view.translationX > target) {
|
|
||||||
view.translationX = target
|
|
||||||
}
|
|
||||||
return outSpring.create(
|
|
||||||
view.translationX,
|
|
||||||
target,
|
|
||||||
SPATIAL_MIN_VISIBLE_CHANGE,
|
|
||||||
update = { view.translationX = it },
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun slideIn(view: View): MotionHandle {
|
|
||||||
if (!view.isLaidOut) {
|
|
||||||
return SnapMotionHandle { view.translationX = 0f }
|
|
||||||
}
|
|
||||||
return inSpring.create(
|
|
||||||
view.translationX,
|
|
||||||
0f,
|
|
||||||
SPATIAL_MIN_VISIBLE_CHANGE,
|
|
||||||
update = { view.translationX = it },
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun small(context: Context, x: Int?) =
|
val DEFAULT =
|
||||||
MaterialSlider(
|
Effect(
|
||||||
context,
|
MR.attr.motionSpringDefaultEffects,
|
||||||
x,
|
MR.style.Motion_Material3_Spring_Standard_Default_Effects,
|
||||||
MotionSpringTokens.FAST_SPATIAL,
|
)
|
||||||
MotionSpringTokens.DEFAULT_SPATIAL,
|
val SLOW =
|
||||||
|
Effect(
|
||||||
|
MR.attr.motionSpringSlowEffects,
|
||||||
|
MR.style.Motion_Material3_Spring_Standard_Slow_Effects,
|
||||||
|
)
|
||||||
|
val FAST =
|
||||||
|
Effect(
|
||||||
|
MR.attr.motionSpringFastEffects,
|
||||||
|
MR.style.Motion_Material3_Spring_Standard_Fast_Effects,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private const val ALPHA_MIN_VISIBLE_CHANGE = 1f / 512f
|
|
||||||
private const val SCALE_MIN_VISIBLE_CHANGE = 0.0001f
|
|
||||||
private const val SPATIAL_MIN_VISIBLE_CHANGE = 0.01f
|
|
||||||
private const val OFFSCREEN_TRANSLATION_PX = 100000f
|
|
||||||
|
|||||||
@@ -24,20 +24,29 @@ import android.widget.FrameLayout
|
|||||||
import androidx.annotation.AttrRes
|
import androidx.annotation.AttrRes
|
||||||
import androidx.annotation.IdRes
|
import androidx.annotation.IdRes
|
||||||
import androidx.core.view.children
|
import androidx.core.view.children
|
||||||
|
import androidx.dynamicanimation.animation.SpringAnimation
|
||||||
|
import org.oxycblt.auxio.util.scale
|
||||||
import timber.log.Timber as L
|
import timber.log.Timber as L
|
||||||
|
|
||||||
class MultiToolbar
|
class MultiToolbar
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr: Int = 0) :
|
constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr: Int = 0) :
|
||||||
FrameLayout(context, attrs, defStyleAttr) {
|
FrameLayout(context, attrs, defStyleAttr) {
|
||||||
private var animator: MotionHandle? = null
|
private var outAnimators: List<SpringAnimation>? = null
|
||||||
|
private var inAnimators: List<SpringAnimation>? = null
|
||||||
private var currentlyVisible = 0
|
private var currentlyVisible = 0
|
||||||
private val flipper = MaterialFlipper(context)
|
private val outScaleSpring = Spatial.FAST
|
||||||
|
private val outAlphaSpring = Effect.FAST
|
||||||
|
private val inScaleSpring = Spatial.DEFAULT
|
||||||
|
private val inAlphaSpring = Effect.DEFAULT
|
||||||
|
|
||||||
override fun onFinishInflate() {
|
override fun onFinishInflate() {
|
||||||
super.onFinishInflate()
|
super.onFinishInflate()
|
||||||
for (i in 1 until childCount) {
|
for (i in 1 until childCount) {
|
||||||
getChildAt(i).apply { flipper.jump(this) }
|
getChildAt(i).apply {
|
||||||
|
scale = 0.9f
|
||||||
|
alpha = 0f
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,8 +62,26 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
|
|||||||
// don't work due to translation)
|
// don't work due to translation)
|
||||||
// Set up the target transitions for both the inner and selection toolbars.
|
// Set up the target transitions for both the inner and selection toolbars.
|
||||||
L.d("Changing toolbar visibility $from -> 0f, $to -> 1f")
|
L.d("Changing toolbar visibility $from -> 0f, $to -> 1f")
|
||||||
animator?.cancel()
|
inAnimators?.forEach { it.cancel() }
|
||||||
animator = flipper.flip(getChildAt(from), getChildAt(to)).also { it.start() }
|
outAnimators?.forEach { it.cancel() }
|
||||||
|
val from = getChildAt(from)
|
||||||
|
val to = getChildAt(to)
|
||||||
|
// since we will lose track of the going-out view if we suddenly cancel it's probably better
|
||||||
|
// to just jump to the end rather than have overlapping views or a stuck toolbar
|
||||||
|
val outScaleAnimation = outScaleSpring.scale(from, 0.9f, jumpOnCancellation = true)
|
||||||
|
val outAlphaAnimation =
|
||||||
|
outAlphaSpring.alpha(from, 0.0f, jumpOnCancellation = true).addEndListener {
|
||||||
|
_,
|
||||||
|
cancelled,
|
||||||
|
_,
|
||||||
|
_ ->
|
||||||
|
if (!cancelled) {
|
||||||
|
val inScaleAnimation = inScaleSpring.scale(to, 1.0f)
|
||||||
|
val inAlphaAnimation = inAlphaSpring.alpha(to, 1.0f)
|
||||||
|
inAnimators = listOf(inScaleAnimation, inAlphaAnimation)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
outAnimators = listOf(outScaleAnimation, outAlphaAnimation)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,6 +98,14 @@ private fun isUnderImpl(
|
|||||||
val View.isRtl: Boolean
|
val View.isRtl: Boolean
|
||||||
get() = layoutDirection == View.LAYOUT_DIRECTION_RTL
|
get() = layoutDirection == View.LAYOUT_DIRECTION_RTL
|
||||||
|
|
||||||
|
/** A single scale value **assuming that the View is always center-scaled** */
|
||||||
|
var View.scale: Float
|
||||||
|
get() = scaleX
|
||||||
|
set(it) {
|
||||||
|
scaleX = it
|
||||||
|
scaleY = it
|
||||||
|
}
|
||||||
|
|
||||||
/** Get a [Context] from a [ViewBinding]'s root [View]. */
|
/** Get a [Context] from a [ViewBinding]'s root [View]. */
|
||||||
val ViewBinding.context: Context
|
val ViewBinding.context: Context
|
||||||
get() = root.context
|
get() = root.context
|
||||||
|
|||||||
Reference in New Issue
Block a user