-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add tests of "withSequence" and clean up imports #6050
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d0fe6f3
All test files
Latropos f9fff6d
Merge
Latropos 0419e77
More tests
Latropos f3e96e2
Merge branch 'main' into acynk/test-with-sequence
Latropos 0d1aae0
Add more tests
Latropos 0818b62
Merge branch 'main' into acynk/test-with-sequence
Latropos f300447
Code review
Latropos efcae8c
Merge branch 'main' into acynk/test-with-sequence
Latropos 83d7dd5
Code review
Latropos 89fe646
Include transparency
Latropos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
25 changes: 25 additions & 0 deletions
25
apps/common-app/src/examples/RuntimeTests/tests/animations/index.tsx
This file contains hidden or 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 @@ | ||
| import { describe } from '../../ReanimatedRuntimeTestsRunner/RuntimeTestsApi'; | ||
|
|
||
| describe('*****ANIMATIONS*****', () => { | ||
| describe('****withTiming**** ⏰', () => { | ||
| require('./withTiming/arrays.test'); | ||
| require('./withTiming/basic.test'); | ||
| require('./withTiming/objects.test'); | ||
| require('./withTiming/colors.test'); | ||
| require('./withTiming/easing.test'); | ||
| require('./withTiming/transformMatrices.test'); | ||
| }); | ||
| describe('****withSpring****', () => { | ||
| require('./withSpring/variousConfig.test'); | ||
| }); | ||
| describe('****withDecay****', () => { | ||
| require('./withDecay/basic.test'); | ||
| }); | ||
| describe('****withSequence****', () => { | ||
| require('./withSequence/callbackCascade.test'); | ||
| require('./withSequence/cancelAnimation.test'); | ||
| require('./withSequence/numbers.test'); | ||
| require('./withSequence/arrays.test'); | ||
| require('./withSequence/colors.test'); | ||
| }); | ||
| }); | ||
This file contains hidden or 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
142 changes: 142 additions & 0 deletions
142
apps/common-app/src/examples/RuntimeTests/tests/animations/withSequence/arrays.test.tsx
This file contains hidden or 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,142 @@ | ||
| import React, { useEffect } from 'react'; | ||
| import Animated, { | ||
| useSharedValue, | ||
| useAnimatedStyle, | ||
| withTiming, | ||
| withSequence, | ||
| withSpring, | ||
| Easing, | ||
| withDelay, | ||
| } from 'react-native-reanimated'; | ||
| import { | ||
| describe, | ||
| test, | ||
| render, | ||
| wait, | ||
| useTestRef, | ||
| getTestComponent, | ||
| expect, | ||
| } from '../../../ReanimatedRuntimeTestsRunner/RuntimeTestsApi'; | ||
| import { View, StyleSheet } from 'react-native'; | ||
| import { ComparisonMode } from '../../../ReanimatedRuntimeTestsRunner/types'; | ||
|
|
||
| type TestCase = { | ||
| startValues: [number, number, number]; | ||
| middleValues: [number, number, number]; | ||
| finalValues: [number, number, number]; | ||
| animationNumber: number; | ||
| }; | ||
|
|
||
| describe('withSequence animation of number', () => { | ||
| const COMPONENT_REF = { | ||
| first: 'firstComponent', | ||
| second: 'secondComponent', | ||
| third: 'thirdComponent', | ||
| }; | ||
|
|
||
| const DELAY = 50; | ||
| const WidthComponent = ({ startValues, middleValues, finalValues, animationNumber }: TestCase) => { | ||
| const lefts = useSharedValue<[number, number, number]>(startValues); | ||
| const ref0 = useTestRef(COMPONENT_REF.first); | ||
| const ref1 = useTestRef(COMPONENT_REF.second); | ||
| const ref2 = useTestRef(COMPONENT_REF.third); | ||
|
|
||
| function animateValue(finalValues: [number, number, number]) { | ||
| 'worklet'; | ||
| const finalValuesPlus20 = finalValues.map(val => val + 20); | ||
| switch (animationNumber) { | ||
| case 0: | ||
| return withSequence( | ||
| withTiming(finalValues, { duration: 200 }), | ||
| withDelay(DELAY, withTiming(middleValues, { duration: 300, easing: Easing.exp })), | ||
| withDelay(DELAY, withTiming(finalValuesPlus20, { duration: 200 })), | ||
| ); | ||
| case 1: | ||
| return withSequence( | ||
| withSpring(finalValues, { duration: 200, dampingRatio: 1 }), | ||
| withDelay(DELAY, withSpring(middleValues, { duration: 300, dampingRatio: 1.5 })), | ||
| withDelay(DELAY, withSpring(finalValuesPlus20, { duration: 200, dampingRatio: 0.9 })), | ||
| ); | ||
| case 2: | ||
| return withSequence( | ||
| withSpring(finalValues, { duration: 200, dampingRatio: 1 }), | ||
| withDelay(DELAY, withTiming(middleValues, { duration: 300 })), | ||
| withDelay(DELAY, withSpring(finalValuesPlus20, { duration: 200, dampingRatio: 1 })), | ||
| ); | ||
| } | ||
| return [0, 0, 0]; | ||
| } | ||
|
|
||
| const style0 = useAnimatedStyle(() => { | ||
| return { left: lefts.value[0] }; | ||
| }); | ||
| const style1 = useAnimatedStyle(() => { | ||
| return { left: lefts.value[1] }; | ||
| }); | ||
| const style2 = useAnimatedStyle(() => { | ||
| return { left: lefts.value[2] }; | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| lefts.value = animateValue(finalValues) as [number, number, number]; | ||
| }); | ||
| return ( | ||
| <View style={styles.container}> | ||
| <Animated.View ref={ref0} style={[styles.animatedBox, style0]} /> | ||
| <Animated.View ref={ref1} style={[styles.animatedBox, style1]} /> | ||
| <Animated.View ref={ref2} style={[styles.animatedBox, style2]} /> | ||
| </View> | ||
| ); | ||
| }; | ||
|
|
||
| test.each([ | ||
| { startValues: [0, 10, 20], middleValues: [0, 100, 210], finalValues: [20, 10, 30], animationNumber: 0 }, | ||
| { startValues: [0, 10, 20], middleValues: [0, 150, 160], finalValues: [40, 10, 30], animationNumber: 1 }, | ||
| { startValues: [0, 10, 20], middleValues: [0, 150, 160], finalValues: [40, 10, 30], animationNumber: 2 }, | ||
| { startValues: [30, 10, 55], middleValues: [0, -10, 60], finalValues: [40, 10, 30], animationNumber: 0 }, | ||
| { startValues: [30, 10, 55], middleValues: [0, -10, 60], finalValues: [40, 10, 30], animationNumber: 1 }, | ||
piaskowyk marked this conversation as resolved.
Show resolved
Hide resolved
Latropos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { startValues: [30, 10, 55], middleValues: [0, -10, 60], finalValues: [40, 10, 30], animationNumber: 2 }, | ||
| ] as Array<TestCase>)( | ||
| 'Animate ${startValues} → ${finalValues} → ${middleValues} → ${finalValues}, animation nr ${animationNumber}', | ||
| async ({ startValues, middleValues, finalValues, animationNumber }) => { | ||
| await render( | ||
| <WidthComponent | ||
| startValues={startValues} | ||
| middleValues={middleValues} | ||
| finalValues={finalValues} | ||
| animationNumber={animationNumber} | ||
| />, | ||
| ); | ||
| const componentOne = getTestComponent(COMPONENT_REF.first); | ||
| const componentTwo = getTestComponent(COMPONENT_REF.second); | ||
| const componentThree = getTestComponent(COMPONENT_REF.third); | ||
| const margin = 30; | ||
|
|
||
| await wait(200 + DELAY / 2); | ||
| expect(await componentOne.getAnimatedStyle('left')).toBe(finalValues[0] + margin, ComparisonMode.DISTANCE); | ||
| expect(await componentTwo.getAnimatedStyle('left')).toBe(finalValues[1] + margin, ComparisonMode.DISTANCE); | ||
| expect(await componentThree.getAnimatedStyle('left')).toBe(finalValues[2] + margin, ComparisonMode.DISTANCE); | ||
| await wait(300 + DELAY / 2); | ||
| expect(await componentOne.getAnimatedStyle('left')).toBe(middleValues[0] + margin, ComparisonMode.DISTANCE); | ||
| expect(await componentTwo.getAnimatedStyle('left')).toBe(middleValues[1] + margin, ComparisonMode.DISTANCE); | ||
| expect(await componentThree.getAnimatedStyle('left')).toBe(middleValues[2] + margin, ComparisonMode.DISTANCE); | ||
| await wait(200 + DELAY); | ||
| expect(await componentOne.getAnimatedStyle('left')).toBe(finalValues[0] + 20 + margin, ComparisonMode.DISTANCE); | ||
| expect(await componentTwo.getAnimatedStyle('left')).toBe(finalValues[1] + 20 + margin, ComparisonMode.DISTANCE); | ||
| expect(await componentThree.getAnimatedStyle('left')).toBe(finalValues[2] + 20 + margin, ComparisonMode.DISTANCE); | ||
| }, | ||
| ); | ||
| }); | ||
| const styles = StyleSheet.create({ | ||
| container: { | ||
| flex: 1, | ||
| flexDirection: 'column', | ||
| }, | ||
| animatedBox: { | ||
| width: 80, | ||
| height: 80, | ||
| borderRadius: 10, | ||
| margin: 30, | ||
| backgroundColor: 'steelblue', | ||
| }, | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.