Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement - Add more click options #73

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

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
}
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.

None yet

2 participants