-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from chrisjenx/cj/gh-actions
add checks xml
- Loading branch information
Showing
8 changed files
with
371 additions
and
54 deletions.
There are no files selected for viewing
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,77 @@ | ||
name: Checks | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
permissions: | ||
checks: write | ||
jobs: | ||
Checks-JS: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Setup Java JDK | ||
uses: actions/[email protected] | ||
with: | ||
distribution: 'zulu' | ||
java-version: '21' | ||
cache: 'gradle' | ||
- name: Setup Chrome | ||
uses: browser-actions/[email protected] | ||
- name: Run Js tests | ||
run: ./gradlew jsBrowserTest --warn --continue | ||
- name: Run Wasm tests | ||
run: ./gradlew wasmJsBrowserTest --warn --continue | ||
- name: Publish Test Report | ||
uses: mikepenz/action-junit-report@v4 | ||
if: success() || failure() | ||
with: | ||
report_paths: '**/build/test-results/**/TEST-*.xml' | ||
check_name: 'JS JUnit Test Report' | ||
require_tests: true | ||
Checks-Jvm: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Setup Java JDK | ||
uses: actions/[email protected] | ||
with: | ||
distribution: 'zulu' | ||
java-version: '21' | ||
cache: 'gradle' | ||
- name: Run Android tests | ||
run: ./gradlew :library:testDebugUnitTest --warn --continue | ||
- name: Run Jvm tests | ||
run: ./gradlew :library:jvmTest --warn --continue | ||
- name: Publish Test Report | ||
uses: mikepenz/action-junit-report@v4 | ||
if: success() || failure() # always run even if the previous step fails | ||
with: | ||
report_paths: '**/build/test-results/**/TEST-*.xml' | ||
check_name: 'JVM JUnit Test Report' | ||
require_tests: true | ||
Checks-Apple: | ||
runs-on: macos-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Setup Java JDK | ||
uses: actions/[email protected] | ||
with: | ||
distribution: 'zulu' | ||
java-version: '21' | ||
cache: 'gradle' | ||
- name: Run Apple tests | ||
run: ./gradlew :library:iosSimulatorArm64Test --warn --continue | ||
- name: Publish Test Report | ||
uses: mikepenz/action-junit-report@v4 | ||
if: success() || failure() # always run even if the previous step fails | ||
with: | ||
report_paths: '**/build/test-results/**/TEST-*.xml' | ||
check_name: 'Apple JUnit Test Report' | ||
require_tests: true |
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
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
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
83 changes: 83 additions & 0 deletions
83
library/src/commonMain/kotlin/com/chrisjenx/yakcov/ShakingState.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,83 @@ | ||
package com.chrisjenx.yakcov | ||
|
||
import androidx.compose.animation.core.Animatable | ||
import androidx.compose.animation.core.AnimationSpec | ||
import androidx.compose.animation.core.tween | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.graphicsLayer | ||
|
||
class ShakingState( | ||
private val strength: Strength, | ||
private val direction: Direction | ||
) { | ||
|
||
val xPosition = Animatable(0f) | ||
|
||
suspend fun shake(animationDuration: Int = 50) { | ||
val shakeAnimationSpec: AnimationSpec<Float> = tween(animationDuration) | ||
when (direction) { | ||
Direction.LEFT -> shakeToLeft(shakeAnimationSpec) | ||
Direction.RIGHT -> shakeToRight(shakeAnimationSpec) | ||
Direction.LEFT_THEN_RIGHT -> shakeToLeftThenRight(shakeAnimationSpec) | ||
Direction.RIGHT_THEN_LEFT -> shakeToRightThenLeft(shakeAnimationSpec) | ||
} | ||
} | ||
|
||
private suspend fun shakeToLeft(shakeAnimationSpec: AnimationSpec<Float>) { | ||
repeat(3) { | ||
xPosition.animateTo(-strength.value, shakeAnimationSpec) | ||
xPosition.animateTo(0f, shakeAnimationSpec) | ||
} | ||
} | ||
|
||
private suspend fun shakeToRight(shakeAnimationSpec: AnimationSpec<Float>) { | ||
repeat(3) { | ||
xPosition.animateTo(strength.value, shakeAnimationSpec) | ||
xPosition.animateTo(0f, shakeAnimationSpec) | ||
} | ||
} | ||
|
||
private suspend fun shakeToRightThenLeft(shakeAnimationSpec: AnimationSpec<Float>) { | ||
repeat(3) { | ||
xPosition.animateTo(strength.value, shakeAnimationSpec) | ||
xPosition.animateTo(0f, shakeAnimationSpec) | ||
xPosition.animateTo(-strength.value / 2, shakeAnimationSpec) | ||
xPosition.animateTo(0f, shakeAnimationSpec) | ||
} | ||
} | ||
|
||
private suspend fun shakeToLeftThenRight(shakeAnimationSpec: AnimationSpec<Float>) { | ||
repeat(3) { | ||
xPosition.animateTo(-strength.value, shakeAnimationSpec) | ||
xPosition.animateTo(0f, shakeAnimationSpec) | ||
xPosition.animateTo(strength.value / 2, shakeAnimationSpec) | ||
xPosition.animateTo(0f, shakeAnimationSpec) | ||
} | ||
} | ||
|
||
sealed class Strength(val value: Float) { | ||
data object Normal : Strength(17f) | ||
data object Strong : Strength(40f) | ||
data class Custom(val strength: Float) : Strength(strength) | ||
} | ||
|
||
enum class Direction { | ||
LEFT, RIGHT, LEFT_THEN_RIGHT, RIGHT_THEN_LEFT | ||
} | ||
} | ||
|
||
@Composable | ||
fun rememberShakingState( | ||
strength: ShakingState.Strength = ShakingState.Strength.Normal, | ||
direction: ShakingState.Direction = ShakingState.Direction.LEFT | ||
): ShakingState { | ||
return remember { ShakingState(strength = strength, direction = direction) } | ||
} | ||
|
||
fun Modifier.shakable(state: ShakingState): Modifier { | ||
return graphicsLayer { | ||
translationX = state.xPosition.value | ||
} | ||
} |
Oops, something went wrong.