mirror of
https://github.com/leaf-wai/StackLayoutManager.git
synced 2026-07-12 19:01:21 +08:00
upgrade Math.pow, Math.min, Math.max api to Kotlin function.
This commit is contained in:
@@ -2,6 +2,7 @@ package com.littlemango.stacklayoutmanager
|
|||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import com.littlemango.stacklayoutmanager.StackLayoutManager.ScrollOrientation
|
import com.littlemango.stacklayoutmanager.StackLayoutManager.ScrollOrientation
|
||||||
|
import kotlin.math.pow
|
||||||
|
|
||||||
class DefaultAnimation(scrollOrientation: ScrollOrientation, visibleCount: Int) : StackAnimation(scrollOrientation, visibleCount) {
|
class DefaultAnimation(scrollOrientation: ScrollOrientation, visibleCount: Int) : StackAnimation(scrollOrientation, visibleCount) {
|
||||||
|
|
||||||
@@ -72,8 +73,8 @@ class DefaultAnimation(scrollOrientation: ScrollOrientation, visibleCount: Int)
|
|||||||
scale = 1 - ((1 - mOutScale) * firstMovePercent)
|
scale = 1 - ((1 - mOutScale) * firstMovePercent)
|
||||||
rotation = mOutRotation * firstMovePercent
|
rotation = mOutRotation * firstMovePercent
|
||||||
} else {
|
} else {
|
||||||
val minScale = (Math.pow(mScale.toDouble(), position.toDouble())).toFloat()
|
val minScale = (mScale.toDouble().pow(position.toDouble())).toFloat()
|
||||||
val maxScale = (Math.pow(mScale.toDouble(), (position - 1).toDouble())).toFloat()
|
val maxScale = (mScale.toDouble().pow((position - 1).toDouble())).toFloat()
|
||||||
scale = minScale + (maxScale - minScale) * firstMovePercent
|
scale = minScale + (maxScale - minScale) * firstMovePercent
|
||||||
//只对最后一个 item 做透明度变化
|
//只对最后一个 item 做透明度变化
|
||||||
if (position == mVisibleCount) {
|
if (position == mVisibleCount) {
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import android.support.v7.widget.RecyclerView.SCROLL_STATE_DRAGGING
|
|||||||
import android.support.v7.widget.RecyclerView.SCROLL_STATE_IDLE
|
import android.support.v7.widget.RecyclerView.SCROLL_STATE_IDLE
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import kotlin.math.max
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
class StackLayoutManager(scrollOrientation: ScrollOrientation,
|
class StackLayoutManager(scrollOrientation: ScrollOrientation,
|
||||||
visibleCount: Int,
|
visibleCount: Int,
|
||||||
@@ -427,8 +429,8 @@ class StackLayoutManager(scrollOrientation: ScrollOrientation,
|
|||||||
|
|
||||||
private fun getValidOffset(expectOffset: Int): Int {
|
private fun getValidOffset(expectOffset: Int): Int {
|
||||||
return when(mScrollOrientation) {
|
return when(mScrollOrientation) {
|
||||||
ScrollOrientation.RIGHT_TO_LEFT, ScrollOrientation.LEFT_TO_RIGHT -> Math.max(Math.min(width * (itemCount - 1), expectOffset), 0)
|
ScrollOrientation.RIGHT_TO_LEFT, ScrollOrientation.LEFT_TO_RIGHT -> max(min(width * (itemCount - 1), expectOffset), 0)
|
||||||
else -> Math.max(Math.min(height * (itemCount - 1), expectOffset), 0)
|
else -> max(min(height * (itemCount - 1), expectOffset), 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user