Updated on 2026-08-14
This commit is contained in:
parent
8ed876086d
commit
0330285106
2 changed files with 49 additions and 4 deletions
|
|
@ -23,11 +23,14 @@ class LeapView(
|
|||
init {
|
||||
val initialProperties = createInitialProperty(position)
|
||||
currentProperties = AnimationProperties.from(initialProperties, initialProperties)
|
||||
initView(initialProperties)
|
||||
}
|
||||
|
||||
view.elevation = initialProperties.elevation
|
||||
view.translationY = initialProperties.yTranslation
|
||||
view.scaleX = initialProperties.scale
|
||||
view.scaleY = initialProperties.scale
|
||||
private fun initView(properties: Properties) {
|
||||
view.elevation = properties.elevation
|
||||
view.translationY = properties.yTranslation
|
||||
view.scaleX = properties.scale
|
||||
view.scaleY = properties.scale
|
||||
// initialProperties.hasForeground
|
||||
}
|
||||
|
||||
|
|
@ -67,6 +70,17 @@ class LeapView(
|
|||
updateProperties(currentProperties.toUnfold(calculator))
|
||||
}
|
||||
|
||||
fun getState(): LeapViewState {
|
||||
return LeapViewState(index, currentPosition, previousPosition, currentProperties)
|
||||
}
|
||||
|
||||
fun applyState(state: LeapViewState) {
|
||||
previousPosition = state.previousPosition
|
||||
currentPosition = state.currentPosition
|
||||
updateProperties(state.properties)
|
||||
initView(state.properties.endProperties())
|
||||
}
|
||||
|
||||
private fun updateProperties(properties: AnimationProperties) {
|
||||
currentProperties = properties
|
||||
}
|
||||
|
|
@ -112,6 +126,13 @@ class LeapView(
|
|||
|
||||
}
|
||||
|
||||
data class LeapViewState(
|
||||
val index: Int,
|
||||
val currentPosition: Int,
|
||||
val previousPosition: Int,
|
||||
val properties: AnimationProperties
|
||||
)
|
||||
|
||||
enum class LeapFrogAnimation {
|
||||
LEAP, PULL
|
||||
}
|
||||
|
|
@ -137,6 +158,16 @@ data class AnimationProperties(
|
|||
val hasForegroundEnd: Boolean,
|
||||
) {
|
||||
|
||||
fun endProperties(): Properties {
|
||||
return Properties(
|
||||
positionEnd,
|
||||
scaleEnd,
|
||||
elevationEnd,
|
||||
yTranslationEnd,
|
||||
hasForegroundEnd,
|
||||
)
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return """
|
||||
scaleStart: $scaleStart, scaleEnd: $scaleEnd,
|
||||
|
|
|
|||
|
|
@ -127,6 +127,15 @@ class LeapfrogWidget(
|
|||
return leapViews.firstOrNull { it.currentPosition == position }?.view
|
||||
}
|
||||
|
||||
fun getState(): LeapfrogWidgetState = LeapfrogWidgetState(isFolded, leapViews.map { it.getState() })
|
||||
|
||||
fun applyState(state: LeapfrogWidgetState) {
|
||||
isFolded = state.isFolded
|
||||
state.leapViewStates.forEach { state ->
|
||||
leapViews.firstOrNull { it.index == state.index }?.applyState(state)
|
||||
}
|
||||
}
|
||||
|
||||
private fun viewIsFullFledged(): Boolean = parentContainer.childCount > 1
|
||||
|
||||
private fun canFoldUnfold(): Boolean {
|
||||
|
|
@ -163,6 +172,11 @@ class LeapfrogWidget(
|
|||
private fun leapBackInProgress(): Boolean = leapBackProgress != 100
|
||||
}
|
||||
|
||||
data class LeapfrogWidgetState(
|
||||
val isFolded: Boolean,
|
||||
val leapViewStates: List<LeapViewState>
|
||||
)
|
||||
|
||||
class PropertyCalculator(
|
||||
val elevationFactor: Float = 1f,
|
||||
val decreaseScaleFactor: Float = 0.1f,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue