-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ISSUE-555: add knode class, long/double click actions (#610)
- Loading branch information
Showing
8 changed files
with
90 additions
and
4 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
compose-support/src/main/java/com/kaspersky/components/composesupport/core/KNode.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.kaspersky.components.composesupport.core | ||
|
||
import androidx.compose.ui.test.SemanticsNodeInteractionsProvider | ||
import com.kaspersky.components.composesupport.core.actions.KNodeActions | ||
import io.github.kakaocup.compose.node.builder.NodeMatcher | ||
import io.github.kakaocup.compose.node.builder.ViewBuilder | ||
import io.github.kakaocup.compose.node.core.BaseNode | ||
|
||
class KNode : BaseNode<KNode>, KNodeActions { | ||
constructor( | ||
semanticsProvider: SemanticsNodeInteractionsProvider, | ||
nodeMatcher: NodeMatcher, | ||
parentNode: BaseNode<*>? = null, | ||
) : super(semanticsProvider, nodeMatcher, parentNode) | ||
|
||
constructor( | ||
semanticsProvider: SemanticsNodeInteractionsProvider, | ||
viewBuilderAction: ViewBuilder.() -> Unit, | ||
) : super(semanticsProvider, viewBuilderAction) | ||
|
||
constructor( | ||
semanticsProvider: SemanticsNodeInteractionsProvider, | ||
nodeMatcher: NodeMatcher, | ||
) : super(semanticsProvider, nodeMatcher) | ||
} |
47 changes: 47 additions & 0 deletions
47
...upport/src/main/java/com/kaspersky/components/composesupport/core/actions/KNodeActions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.kaspersky.components.composesupport.core.actions | ||
|
||
import androidx.compose.ui.geometry.Offset | ||
import androidx.compose.ui.test.doubleClick | ||
import androidx.compose.ui.test.longClick | ||
import androidx.compose.ui.test.performTouchInput | ||
import com.kaspersky.components.composesupport.core.actions.options.DoubleClickConfig | ||
import com.kaspersky.components.composesupport.core.actions.options.LongClickConfig | ||
import io.github.kakaocup.compose.intercept.delegate.ComposeDelegate | ||
import io.github.kakaocup.compose.intercept.operation.ComposeOperationType | ||
|
||
interface KNodeActions { | ||
val delegate: ComposeDelegate | ||
|
||
/** | ||
* Performs a double click action on the element represented by the given semantics node. | ||
*/ | ||
fun doubleClick(doubleClickConfig: DoubleClickConfig? = null) { | ||
delegate.perform(ComposeKNodeActionType.PERFORM_DOUBLE_CLICK) { | ||
performTouchInput { | ||
doubleClick( | ||
position = Offset(doubleClickConfig?.xOffset ?: centerX, doubleClickConfig?.yOffset ?: centerY), | ||
delayMillis = doubleClickConfig?.delayMs ?: ((viewConfiguration.doubleTapMinTimeMillis + viewConfiguration.doubleTapTimeoutMillis) / 2) | ||
) | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Performs a long click action on the element represented by the given semantics node. | ||
*/ | ||
fun longClick(longClickConfig: LongClickConfig? = null) { | ||
delegate.perform(ComposeKNodeActionType.PERFORM_LONG_CLICK) { | ||
performTouchInput { | ||
longClick( | ||
position = Offset(longClickConfig?.xOffset ?: centerX, longClickConfig?.yOffset ?: centerY), | ||
durationMillis = longClickConfig?.durationMs ?: ((viewConfiguration.doubleTapMinTimeMillis + viewConfiguration.doubleTapTimeoutMillis) / 2) | ||
) | ||
} | ||
} | ||
} | ||
|
||
enum class ComposeKNodeActionType : ComposeOperationType { | ||
PERFORM_DOUBLE_CLICK, | ||
PERFORM_LONG_CLICK | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...in/java/com/kaspersky/components/composesupport/core/actions/options/DoubleClickConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.kaspersky.components.composesupport.core.actions.options | ||
|
||
data class DoubleClickConfig( | ||
val xOffset: Float = 0F, | ||
val yOffset: Float = 0F, | ||
val delayMs: Long? = null | ||
) |
7 changes: 7 additions & 0 deletions
7
...main/java/com/kaspersky/components/composesupport/core/actions/options/LongClickConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.kaspersky.components.composesupport.core.actions.options | ||
|
||
data class LongClickConfig( | ||
val xOffset: Float = 0F, | ||
val yOffset: Float = 0F, | ||
val durationMs: Long? = null | ||
) |
2 changes: 1 addition & 1 deletion
2
...roidTest/kotlin/com/kaspersky/kaspresso/composesupport/sample/screen/ComposeMainScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...t/kotlin/com/kaspersky/kaspresso/composesupport/sample/screen/ComposeSanityFlakyScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...idTest/kotlin/com/kaspersky/kaspresso/composesupport/sample/screen/ComposeScrollScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...t/kotlin/com/kaspersky/kaspresso/composesupport/sample/screen/ComposeSimpleFlakyScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters