upgrade Math.pow, Math.min, Math.max api to Kotlin function.

This commit is contained in:
LittleMango
2019-11-13 10:17:52 +08:00
parent e5f7874b45
commit b0528ea102
2 changed files with 7 additions and 4 deletions

View File

@ -2,6 +2,7 @@ package com.littlemango.stacklayoutmanager
import android.view.View
import com.littlemango.stacklayoutmanager.StackLayoutManager.ScrollOrientation
import kotlin.math.pow
class DefaultAnimation(scrollOrientation: ScrollOrientation, visibleCount: Int) : StackAnimation(scrollOrientation, visibleCount) {
@ -72,8 +73,8 @@ class DefaultAnimation(scrollOrientation: ScrollOrientation, visibleCount: Int)
scale = 1 - ((1 - mOutScale) * firstMovePercent)
rotation = mOutRotation * firstMovePercent
} else {
val minScale = (Math.pow(mScale.toDouble(), position.toDouble())).toFloat()
val maxScale = (Math.pow(mScale.toDouble(), (position - 1).toDouble())).toFloat()
val minScale = (mScale.toDouble().pow(position.toDouble())).toFloat()
val maxScale = (mScale.toDouble().pow((position - 1).toDouble())).toFloat()
scale = minScale + (maxScale - minScale) * firstMovePercent
//只对最后一个 item 做透明度变化
if (position == mVisibleCount) {

View File

@ -6,6 +6,8 @@ import android.support.v7.widget.RecyclerView.SCROLL_STATE_DRAGGING
import android.support.v7.widget.RecyclerView.SCROLL_STATE_IDLE
import android.view.View
import android.view.ViewGroup
import kotlin.math.max
import kotlin.math.min
class StackLayoutManager(scrollOrientation: ScrollOrientation,
visibleCount: Int,
@ -427,8 +429,8 @@ class StackLayoutManager(scrollOrientation: ScrollOrientation,
private fun getValidOffset(expectOffset: Int): Int {
return when(mScrollOrientation) {
ScrollOrientation.RIGHT_TO_LEFT, ScrollOrientation.LEFT_TO_RIGHT -> Math.max(Math.min(width * (itemCount - 1), expectOffset), 0)
else -> Math.max(Math.min(height * (itemCount - 1), expectOffset), 0)
ScrollOrientation.RIGHT_TO_LEFT, ScrollOrientation.LEFT_TO_RIGHT -> max(min(width * (itemCount - 1), expectOffset), 0)
else -> max(min(height * (itemCount - 1), expectOffset), 0)
}
}