Skip to content

Conversation

@Areyana
Copy link

@Areyana Areyana commented Dec 18, 2023

Extend base actions

Copy link
Member

@Vacxe Vacxe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution. Could you please fix lint issues (empty lines in the end of files). As well provide new test cases implementation for the new functionality.

data class LongClickConfig(
val xOffset: Float = 0F,
val yOffset: Float = 0F,
val durationMs: Long? = null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

durationMs can be a first argument in performLongClick with default value. In most cases devs will prefer to override this parameter.

data class DoubleClickConfig(
val xOffset: Float = 0F,
val yOffset: Float = 0F,
val delayMs: Long? = null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delayMs can be a first argument in performDoubleClick with default value.

Comment on lines +3 to +7
enum class Offsets {
CENTER, CENTER_LEFT, CENTER_RIGHT,
TOP_CENTER, TOP_LEFT, TOP_RIGHT,
BOTTOM_CENTER, BOTTOM_LEFT, BOTTOM_RIGHT
} No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think will be better to use sealed class with objects for default offsets + data class for custom offsets to avoid duplication in LongClickConfig DoubleClickConfig and ClickConfig. As well it will be more straight forward.

Comment on lines +7 to +24
internal fun TouchInjectionScope.createOffset(
offset: Offsets,
offsetX: Float? = null,
offsetY: Float? = null
): Offset {
return when (offset) {
Offsets.CENTER -> center
Offsets.CENTER_LEFT -> centerLeft.copy(x = 1f)
Offsets.CENTER_RIGHT -> centerRight
Offsets.TOP_CENTER -> topCenter.copy(y = 1f)
Offsets.TOP_LEFT -> topLeft.copy(x = 1f, y = 1f)
Offsets.TOP_RIGHT -> topRight.copy(y = 1f)
Offsets.BOTTOM_CENTER -> bottomCenter
Offsets.BOTTOM_LEFT -> bottomLeft.copy(x = 1f)
Offsets.BOTTOM_RIGHT -> bottomRight
}.run {
copy(x = x + (offsetX ?: 0F), y = y + (offsetY ?: 0F))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applying offsetX offsetY to existing offset looks misleading to me. sealed class with default objects + data class will be more clear IMO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants