Skip to content

Commit

Permalink
remove: Removed GestureType.NONE and ContinuousTransformType.NONE pro…
Browse files Browse the repository at this point in the history
…perties
  • Loading branch information
panpf committed Jul 23, 2024
1 parent e044476 commit a211f5d
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 57 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ zoom:
pausedContinuousTransformTypesState
* change: ZoomableState 的 disabledGestureType 属性名称改为 disabledGestureTypes,ZoomableEngine 的
disabledGestureTypeState 属性名称改为 disabledGestureTypesState
* remove: 移除 GestureType.NONE 和 ContinuousTransformType.NONE 属性

## 1.1.0-alpha02

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
Expand Down Expand Up @@ -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) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -866,7 +866,7 @@ class ZoomableState(val logger: Logger) : RememberObserver {
} catch (e: CancellationException) {
throw e
} finally {
continuousTransformType = ContinuousTransformType.NONE
continuousTransformType = 0
}
}
targetScale != null
Expand Down Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -1049,7 +1049,7 @@ class ZoomableState(val logger: Logger) : RememberObserver {
throw e
} finally {
if (newContinuousTransformType != null) {
continuousTransformType = ContinuousTransformType.NONE
continuousTransformType = 0
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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
Expand All @@ -64,7 +63,6 @@ annotation class ContinuousTransformType {

fun name(@ContinuousTransformType type: Int): String {
return when (type) {
NONE -> "NONE"
SCALE -> "SCALE"
OFFSET -> "OFFSET"
LOCATE -> "LOCATE"
Expand All @@ -73,5 +71,11 @@ annotation class ContinuousTransformType {
else -> "UNKNOWN"
}
}

val values = listOf(SCALE, OFFSET, LOCATE, GESTURE, FLING)

fun parse(continuousTransformTypes: Int): List<Int> {
return values.asSequence().filter { continuousTransformTypes and it != 0 }.toList()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -30,15 +27,20 @@ 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"
DOUBLE_TAP_SCALE -> "DOUBLE_TAP_SCALE"
else -> "UNKNOWN"
}
}

val values = listOf(DRAG, TWO_FINGER_SCALE, ONE_FINGER_SCALE, DOUBLE_TAP_SCALE)

fun parse(gestureTypes: Int): List<Int> {
return values.asSequence().filter { gestureTypes and it != 0 }.toList()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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))
}
)
Expand Down Expand Up @@ -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))
}
)
Expand Down Expand Up @@ -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))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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
}
}
}
Expand Down

0 comments on commit a211f5d

Please sign in to comment.