From a211f5dafa40e5629b99f27e2e03f4ebf66d36fa Mon Sep 17 00:00:00 2001 From: panpf Date: Tue, 23 Jul 2024 18:26:20 +0800 Subject: [PATCH] remove: Removed GestureType.NONE and ContinuousTransformType.NONE properties --- CHANGELOG.md | 1 + CHANGELOG_zh.md | 1 + .../sample/ui/ZoomImageSettingsViewModel.kt | 15 ++------------- .../ui/gallery/ZoomImageSettingsDialog.kt | 19 ++----------------- .../panpf/zoomimage/compose/zoom/Zoomable.kt | 4 ++-- .../zoomimage/compose/zoom/ZoomableState.kt | 14 +++++++------- .../zoomimage/zoom/ContinuousTransformType.kt | 14 +++++++++----- .../panpf/zoomimage/zoom/GestureType.kt | 12 +++++++----- .../zoomimage/view/zoom/ZoomableEngine.kt | 12 ++++++------ .../view/zoom/internal/TouchHelper.kt | 4 ++-- 10 files changed, 39 insertions(+), 57 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5de713c7d..60d3c3c64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ zoom: * change: The disabledGestureType property name of ZoomableState is changed to disabledGestureTypes, and the disabledGestureTypeState property name of ZoomableEngine is changed to disabledGestureTypesState +* remove: Removed GestureType.NONE and ContinuousTransformType.NONE properties ## 1.1.0-alpha02 diff --git a/CHANGELOG_zh.md b/CHANGELOG_zh.md index f1068f12c..521a7c9c7 100644 --- a/CHANGELOG_zh.md +++ b/CHANGELOG_zh.md @@ -20,6 +20,7 @@ zoom: pausedContinuousTransformTypesState * change: ZoomableState 的 disabledGestureType 属性名称改为 disabledGestureTypes,ZoomableEngine 的 disabledGestureTypeState 属性名称改为 disabledGestureTypesState +* remove: 移除 GestureType.NONE 和 ContinuousTransformType.NONE 属性 ## 1.1.0-alpha02 diff --git a/sample/src/androidMain/kotlin/com/github/panpf/zoomimage/sample/ui/ZoomImageSettingsViewModel.kt b/sample/src/androidMain/kotlin/com/github/panpf/zoomimage/sample/ui/ZoomImageSettingsViewModel.kt index a55939ea3..6609c829b 100644 --- a/sample/src/androidMain/kotlin/com/github/panpf/zoomimage/sample/ui/ZoomImageSettingsViewModel.kt +++ b/sample/src/androidMain/kotlin/com/github/panpf/zoomimage/sample/ui/ZoomImageSettingsViewModel.kt @@ -152,12 +152,7 @@ class ZoomImageSettingsViewModel( ) ) - val gestureTypes = listOf( - GestureType.DRAG, - GestureType.TWO_FINGER_SCALE, - GestureType.ONE_FINGER_SCALE, - GestureType.DOUBLE_TAP_SCALE, - ) + val gestureTypes = GestureType.values add( MultiChooseMenu( title = "Disabled Gesture Type", @@ -205,13 +200,7 @@ class ZoomImageSettingsViewModel( add(MenuDivider()) - val continuousTransformTypes = listOf( - ContinuousTransformType.SCALE, - ContinuousTransformType.OFFSET, - ContinuousTransformType.LOCATE, - ContinuousTransformType.GESTURE, - ContinuousTransformType.FLING, - ) + val continuousTransformTypes = ContinuousTransformType.values add( MultiChooseMenu( title = "Paused Continuous Transform Type", diff --git a/sample/src/commonMain/kotlin/com/github/panpf/zoomimage/sample/ui/gallery/ZoomImageSettingsDialog.kt b/sample/src/commonMain/kotlin/com/github/panpf/zoomimage/sample/ui/gallery/ZoomImageSettingsDialog.kt index b88dbd6ef..f4b13179b 100644 --- a/sample/src/commonMain/kotlin/com/github/panpf/zoomimage/sample/ui/gallery/ZoomImageSettingsDialog.kt +++ b/sample/src/commonMain/kotlin/com/github/panpf/zoomimage/sample/ui/gallery/ZoomImageSettingsDialog.kt @@ -154,14 +154,7 @@ fun ZoomImageSettingsDialog(onDismissRequest: () -> Unit) { state = appSettings.scalesMultiple, ) - val gestureTypes = remember { - listOf( - GestureType.DRAG, - GestureType.TWO_FINGER_SCALE, - GestureType.ONE_FINGER_SCALE, - GestureType.DOUBLE_TAP_SCALE, - ) - } + val gestureTypes = remember { GestureType.values } val gestureTypeStrings = remember { gestureTypes.map { GestureType.name(it) } } @@ -209,15 +202,7 @@ fun ZoomImageSettingsDialog(onDismissRequest: () -> Unit) { DividerSettingItem() - val continuousTransformTypes = remember { - listOf( - ContinuousTransformType.SCALE, - ContinuousTransformType.OFFSET, - ContinuousTransformType.LOCATE, - ContinuousTransformType.GESTURE, - ContinuousTransformType.FLING, - ) - } + val continuousTransformTypes = remember { ContinuousTransformType.values } val continuousTransformTypeStrings = remember { continuousTransformTypes.map { ContinuousTransformType.name(it) } } diff --git a/zoomimage-compose/src/commonMain/kotlin/com/github/panpf/zoomimage/compose/zoom/Zoomable.kt b/zoomimage-compose/src/commonMain/kotlin/com/github/panpf/zoomimage/compose/zoom/Zoomable.kt index bca8996ce..c67d85718 100644 --- a/zoomimage-compose/src/commonMain/kotlin/com/github/panpf/zoomimage/compose/zoom/Zoomable.kt +++ b/zoomimage-compose/src/commonMain/kotlin/com/github/panpf/zoomimage/compose/zoom/Zoomable.kt @@ -252,7 +252,7 @@ internal class ZoomableNode( if (longPressExecuted) return@launch if (supportOneFingerScale && oneFingerScaleExecuted && doubleTapPressPoint != null) { if (!zoomable.rollbackScale(doubleTapPressPoint)) { - zoomable.continuousTransformType = GestureType.NONE + zoomable.continuousTransformType = 0 } } else { val rollbackScaleExecuted = @@ -263,7 +263,7 @@ internal class ZoomableNode( flingExecuted = supportDrag && zoomable.fling(velocity, density) } if ((supportTwoFingerScale || supportDrag) && (!rollbackScaleExecuted && !flingExecuted)) { - zoomable.continuousTransformType = GestureType.NONE + zoomable.continuousTransformType = 0 } } } diff --git a/zoomimage-compose/src/commonMain/kotlin/com/github/panpf/zoomimage/compose/zoom/ZoomableState.kt b/zoomimage-compose/src/commonMain/kotlin/com/github/panpf/zoomimage/compose/zoom/ZoomableState.kt index 75ea93d24..d62db4875 100644 --- a/zoomimage-compose/src/commonMain/kotlin/com/github/panpf/zoomimage/compose/zoom/ZoomableState.kt +++ b/zoomimage-compose/src/commonMain/kotlin/com/github/panpf/zoomimage/compose/zoom/ZoomableState.kt @@ -240,7 +240,7 @@ class ZoomableState(val logger: Logger) : RememberObserver { * * @see ContinuousTransformType */ - var continuousTransformType: Int by mutableIntStateOf(ContinuousTransformType.NONE) + var continuousTransformType: Int by mutableIntStateOf(0) internal set /** @@ -807,8 +807,8 @@ class ZoomableState(val logger: Logger) : RememberObserver { } val lastContinuousTransformType = continuousTransformType - if (lastContinuousTransformType != ContinuousTransformType.NONE) { - continuousTransformType = ContinuousTransformType.NONE + if (lastContinuousTransformType != 0) { + continuousTransformType = 0 } } @@ -866,7 +866,7 @@ class ZoomableState(val logger: Logger) : RememberObserver { } catch (e: CancellationException) { throw e } finally { - continuousTransformType = ContinuousTransformType.NONE + continuousTransformType = 0 } } targetScale != null @@ -966,13 +966,13 @@ class ZoomableState(val logger: Logger) : RememberObserver { // SubsamplingState(line 87) relies on the fling state to refresh tiles, // so you need to end the fling animation as soon as possible job?.cancel("reachBounds") - continuousTransformType = ContinuousTransformType.NONE + continuousTransformType = 0 } } } catch (e: CancellationException) { throw e } finally { - continuousTransformType = ContinuousTransformType.NONE + continuousTransformType = 0 } } } @@ -1049,7 +1049,7 @@ class ZoomableState(val logger: Logger) : RememberObserver { throw e } finally { if (newContinuousTransformType != null) { - continuousTransformType = ContinuousTransformType.NONE + continuousTransformType = 0 } } } diff --git a/zoomimage-core/src/commonMain/kotlin/com/github/panpf/zoomimage/zoom/ContinuousTransformType.kt b/zoomimage-core/src/commonMain/kotlin/com/github/panpf/zoomimage/zoom/ContinuousTransformType.kt index 4d6ec39ac..216ca8c08 100644 --- a/zoomimage-core/src/commonMain/kotlin/com/github/panpf/zoomimage/zoom/ContinuousTransformType.kt +++ b/zoomimage-core/src/commonMain/kotlin/com/github/panpf/zoomimage/zoom/ContinuousTransformType.kt @@ -20,12 +20,11 @@ import com.github.panpf.zoomimage.annotation.IntDef import com.github.panpf.zoomimage.zoom.ContinuousTransformType.Companion.FLING import com.github.panpf.zoomimage.zoom.ContinuousTransformType.Companion.GESTURE import com.github.panpf.zoomimage.zoom.ContinuousTransformType.Companion.LOCATE -import com.github.panpf.zoomimage.zoom.ContinuousTransformType.Companion.NONE import com.github.panpf.zoomimage.zoom.ContinuousTransformType.Companion.OFFSET import com.github.panpf.zoomimage.zoom.ContinuousTransformType.Companion.SCALE @Retention(AnnotationRetention.SOURCE) -@IntDef(NONE, SCALE, OFFSET, LOCATE, GESTURE, FLING) +@IntDef(SCALE, OFFSET, LOCATE, GESTURE, FLING) @Target( AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FIELD, @@ -35,7 +34,6 @@ import com.github.panpf.zoomimage.zoom.ContinuousTransformType.Companion.SCALE ) annotation class ContinuousTransformType { companion object { - const val NONE = 0 /** * scale(), switchScale(), rollbackScale() functions @@ -55,7 +53,8 @@ annotation class ContinuousTransformType { /** * User gestures dragging and zooming */ - const val GESTURE = 8 + const val GESTURE = + 8 // TODO Split GESTURE_DRAG、GESTURE_ONE_FINGER_SCALE、GESTURE_TWO_FINGER_SCALE /** * User gesture fling @@ -64,7 +63,6 @@ annotation class ContinuousTransformType { fun name(@ContinuousTransformType type: Int): String { return when (type) { - NONE -> "NONE" SCALE -> "SCALE" OFFSET -> "OFFSET" LOCATE -> "LOCATE" @@ -73,5 +71,11 @@ annotation class ContinuousTransformType { else -> "UNKNOWN" } } + + val values = listOf(SCALE, OFFSET, LOCATE, GESTURE, FLING) + + fun parse(continuousTransformTypes: Int): List { + return values.asSequence().filter { continuousTransformTypes and it != 0 }.toList() + } } } \ No newline at end of file diff --git a/zoomimage-core/src/commonMain/kotlin/com/github/panpf/zoomimage/zoom/GestureType.kt b/zoomimage-core/src/commonMain/kotlin/com/github/panpf/zoomimage/zoom/GestureType.kt index 0035dfed9..524c03677 100644 --- a/zoomimage-core/src/commonMain/kotlin/com/github/panpf/zoomimage/zoom/GestureType.kt +++ b/zoomimage-core/src/commonMain/kotlin/com/github/panpf/zoomimage/zoom/GestureType.kt @@ -4,7 +4,6 @@ import com.github.panpf.zoomimage.annotation.IntDef @Retention(AnnotationRetention.SOURCE) @IntDef( - GestureType.NONE, GestureType.DRAG, GestureType.TWO_FINGER_SCALE, GestureType.ONE_FINGER_SCALE, @@ -20,8 +19,6 @@ import com.github.panpf.zoomimage.annotation.IntDef annotation class GestureType { companion object { - const val NONE = 0 - const val DRAG = 1 const val TWO_FINGER_SCALE = 2 @@ -30,9 +27,8 @@ annotation class GestureType { const val DOUBLE_TAP_SCALE = 8 - fun name(@ContinuousTransformType type: Int): String { + fun name(@GestureType type: Int): String { return when (type) { - NONE -> "NONE" DRAG -> "DRAG" TWO_FINGER_SCALE -> "TWO_FINGER_SCALE" ONE_FINGER_SCALE -> "ONE_FINGER_SCALE" @@ -40,5 +36,11 @@ annotation class GestureType { else -> "UNKNOWN" } } + + val values = listOf(DRAG, TWO_FINGER_SCALE, ONE_FINGER_SCALE, DOUBLE_TAP_SCALE) + + fun parse(gestureTypes: Int): List { + return values.asSequence().filter { gestureTypes and it != 0 }.toList() + } } } diff --git a/zoomimage-view/src/main/kotlin/com/github/panpf/zoomimage/view/zoom/ZoomableEngine.kt b/zoomimage-view/src/main/kotlin/com/github/panpf/zoomimage/view/zoom/ZoomableEngine.kt index 0ceb569af..74b4c2e6a 100644 --- a/zoomimage-view/src/main/kotlin/com/github/panpf/zoomimage/view/zoom/ZoomableEngine.kt +++ b/zoomimage-view/src/main/kotlin/com/github/panpf/zoomimage/view/zoom/ZoomableEngine.kt @@ -187,7 +187,7 @@ class ZoomableEngine constructor(val logger: Logger, val view: View) { private val _minScaleState = MutableStateFlow(1.0f) private val _mediumScaleState = MutableStateFlow(1.0f) private val _maxScaleState = MutableStateFlow(1.0f) - internal val _continuousTransformTypeState = MutableStateFlow(ContinuousTransformType.NONE) + internal val _continuousTransformTypeState = MutableStateFlow(0) private val _contentBaseDisplayRectState = MutableStateFlow(IntRectCompat.Zero) private val _contentBaseVisibleRectState = MutableStateFlow(IntRectCompat.Zero) private val _contentDisplayRectState = MutableStateFlow(IntRectCompat.Zero) @@ -789,8 +789,8 @@ class ZoomableEngine constructor(val logger: Logger, val view: View) { } val lastContinuousTransformType = _continuousTransformTypeState.value - if (lastContinuousTransformType != ContinuousTransformType.NONE) { - _continuousTransformTypeState.value = ContinuousTransformType.NONE + if (lastContinuousTransformType != 0) { + _continuousTransformTypeState.value = 0 } } @@ -846,7 +846,7 @@ class ZoomableEngine constructor(val logger: Logger, val view: View) { } }, onEnd = { - _continuousTransformTypeState.value = ContinuousTransformType.NONE + _continuousTransformTypeState.value = 0 continuation.resumeWith(Result.success(0)) } ) @@ -968,7 +968,7 @@ class ZoomableEngine constructor(val logger: Logger, val view: View) { updateUserTransform(newUserOffset) }, onEnd = { - _continuousTransformTypeState.value = ContinuousTransformType.NONE + _continuousTransformTypeState.value = 0 continuation.resumeWith(Result.success(0)) } ) @@ -1046,7 +1046,7 @@ class ZoomableEngine constructor(val logger: Logger, val view: View) { }, onEnd = { if (newContinuousTransformType != null) { - _continuousTransformTypeState.value = ContinuousTransformType.NONE + _continuousTransformTypeState.value = 0 } continuation.resumeWith(Result.success(0)) } diff --git a/zoomimage-view/src/main/kotlin/com/github/panpf/zoomimage/view/zoom/internal/TouchHelper.kt b/zoomimage-view/src/main/kotlin/com/github/panpf/zoomimage/view/zoom/internal/TouchHelper.kt index 293d47350..d9bd9c4d3 100644 --- a/zoomimage-view/src/main/kotlin/com/github/panpf/zoomimage/view/zoom/internal/TouchHelper.kt +++ b/zoomimage-view/src/main/kotlin/com/github/panpf/zoomimage/view/zoom/internal/TouchHelper.kt @@ -180,7 +180,7 @@ internal class TouchHelper(view: View, zoomable: ZoomableEngine) { if (longPressExecuted) return@launch if (supportOneFingerScale && oneFingerScaleExecuted && doubleTapPressPoint != null) { if (!zoomable.rollbackScale(doubleTapPressPoint)) { - zoomable._continuousTransformTypeState.value = GestureType.NONE + zoomable._continuousTransformTypeState.value = 0 } } else { val rollbackScaleExecuted = @@ -190,7 +190,7 @@ internal class TouchHelper(view: View, zoomable: ZoomableEngine) { flingExecuted = supportDrag && zoomable.fling(velocity) } if ((supportTwoFingerScale || supportDrag) && (!rollbackScaleExecuted && !flingExecuted)) { - zoomable._continuousTransformTypeState.value = GestureType.NONE + zoomable._continuousTransformTypeState.value = 0 } } }