@magmamath/students-features 1.2.0-rc-0000 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commonjs/features/endOfAssignment/components/CorrectAnswer/AnimatedCard.js +22 -19
- package/dist/commonjs/features/endOfAssignment/components/CorrectAnswer/AnimatedCard.js.map +1 -1
- package/dist/commonjs/features/endOfAssignment/components/CorrectAnswer/CorrectAnswerSparks.js +5 -5
- package/dist/commonjs/features/endOfAssignment/components/CorrectAnswer/CorrectAnswerSparks.js.map +1 -1
- package/dist/commonjs/features/endOfAssignment/components/CorrectAnswer/GoodDrawingSparks.js +5 -5
- package/dist/commonjs/features/endOfAssignment/components/CorrectAnswer/GoodDrawingSparks.js.map +1 -1
- package/dist/commonjs/features/endOfAssignment/components/CorrectAnswer/Spark.js +5 -7
- package/dist/commonjs/features/endOfAssignment/components/CorrectAnswer/Spark.js.map +1 -1
- package/dist/commonjs/features/endOfAssignment/constants.js +2 -2
- package/dist/commonjs/features/endOfAssignment/constants.js.map +1 -1
- package/dist/commonjs/features/endOfAssignment/hooks/useSparkAnimation.js +22 -34
- package/dist/commonjs/features/endOfAssignment/hooks/useSparkAnimation.js.map +1 -1
- package/dist/module/features/endOfAssignment/components/CorrectAnswer/AnimatedCard.js +23 -20
- package/dist/module/features/endOfAssignment/components/CorrectAnswer/AnimatedCard.js.map +1 -1
- package/dist/module/features/endOfAssignment/components/CorrectAnswer/CorrectAnswerSparks.js +3 -3
- package/dist/module/features/endOfAssignment/components/CorrectAnswer/CorrectAnswerSparks.js.map +1 -1
- package/dist/module/features/endOfAssignment/components/CorrectAnswer/GoodDrawingSparks.js +3 -3
- package/dist/module/features/endOfAssignment/components/CorrectAnswer/GoodDrawingSparks.js.map +1 -1
- package/dist/module/features/endOfAssignment/components/CorrectAnswer/Spark.js +4 -5
- package/dist/module/features/endOfAssignment/components/CorrectAnswer/Spark.js.map +1 -1
- package/dist/module/features/endOfAssignment/constants.js +2 -2
- package/dist/module/features/endOfAssignment/constants.js.map +1 -1
- package/dist/module/features/endOfAssignment/hooks/useSparkAnimation.js +24 -36
- package/dist/module/features/endOfAssignment/hooks/useSparkAnimation.js.map +1 -1
- package/dist/typescript/commonjs/features/endOfAssignment/components/CorrectAnswer/AnimatedCard.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/endOfAssignment/components/CorrectAnswer/CorrectAnswerSparks.d.ts +1 -1
- package/dist/typescript/commonjs/features/endOfAssignment/components/CorrectAnswer/CorrectAnswerSparks.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/endOfAssignment/components/CorrectAnswer/GoodDrawingSparks.d.ts +1 -1
- package/dist/typescript/commonjs/features/endOfAssignment/components/CorrectAnswer/GoodDrawingSparks.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/endOfAssignment/components/CorrectAnswer/Spark.d.ts +1 -1
- package/dist/typescript/commonjs/features/endOfAssignment/components/CorrectAnswer/Spark.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/endOfAssignment/constants.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/endOfAssignment/hooks/useSparkAnimation.d.ts +2 -4
- package/dist/typescript/commonjs/features/endOfAssignment/hooks/useSparkAnimation.d.ts.map +1 -1
- package/dist/typescript/module/features/endOfAssignment/components/CorrectAnswer/AnimatedCard.d.ts.map +1 -1
- package/dist/typescript/module/features/endOfAssignment/components/CorrectAnswer/CorrectAnswerSparks.d.ts +1 -1
- package/dist/typescript/module/features/endOfAssignment/components/CorrectAnswer/CorrectAnswerSparks.d.ts.map +1 -1
- package/dist/typescript/module/features/endOfAssignment/components/CorrectAnswer/GoodDrawingSparks.d.ts +1 -1
- package/dist/typescript/module/features/endOfAssignment/components/CorrectAnswer/GoodDrawingSparks.d.ts.map +1 -1
- package/dist/typescript/module/features/endOfAssignment/components/CorrectAnswer/Spark.d.ts +1 -1
- package/dist/typescript/module/features/endOfAssignment/components/CorrectAnswer/Spark.d.ts.map +1 -1
- package/dist/typescript/module/features/endOfAssignment/constants.d.ts.map +1 -1
- package/dist/typescript/module/features/endOfAssignment/hooks/useSparkAnimation.d.ts +2 -4
- package/dist/typescript/module/features/endOfAssignment/hooks/useSparkAnimation.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/features/endOfAssignment/components/CorrectAnswer/AnimatedCard.tsx +28 -27
- package/src/features/endOfAssignment/components/CorrectAnswer/CorrectAnswerSparks.tsx +3 -3
- package/src/features/endOfAssignment/components/CorrectAnswer/GoodDrawingSparks.tsx +3 -3
- package/src/features/endOfAssignment/components/CorrectAnswer/Spark.tsx +18 -20
- package/src/features/endOfAssignment/constants.ts +4 -7
- package/src/features/endOfAssignment/hooks/useSparkAnimation.tsx +29 -43
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react'
|
|
2
2
|
import { COLORS } from '@magmamath/react-native-ui'
|
|
3
3
|
import { SparkIcon } from '../../ui/SparkIcon'
|
|
4
4
|
import { useSparkAnimation } from '../../hooks/useSparkAnimation'
|
|
@@ -25,23 +25,21 @@ const SPARKS_SPRING_CONFIG = {
|
|
|
25
25
|
const HOLD_DELAY = 800
|
|
26
26
|
const ROTATION_ANGLE = 90
|
|
27
27
|
|
|
28
|
-
export const Spark =
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
})
|
|
28
|
+
export const Spark = ({ id, x, y, size, initialDelay = 350, color = COLORS.GREEN_3 }: SparkProps) => {
|
|
29
|
+
const { animatedStyle } = useSparkAnimation({
|
|
30
|
+
id,
|
|
31
|
+
initialDelay,
|
|
32
|
+
rotationAngle: ROTATION_ANGLE,
|
|
33
|
+
holdDelay: HOLD_DELAY,
|
|
34
|
+
springConfig: SPARKS_SPRING_CONFIG,
|
|
35
|
+
x,
|
|
36
|
+
y,
|
|
37
|
+
size,
|
|
38
|
+
})
|
|
40
39
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
)
|
|
40
|
+
return (
|
|
41
|
+
<Animated.View style={animatedStyle}>
|
|
42
|
+
<SparkIcon size={size} color={color} />
|
|
43
|
+
</Animated.View>
|
|
44
|
+
)
|
|
45
|
+
}
|
|
@@ -11,10 +11,7 @@ export const MODALS_WITH_BACKGROUND = [
|
|
|
11
11
|
EOAModalVariant.EXAM_FINISHED_HAS_CORRECT_ANSWERS,
|
|
12
12
|
]
|
|
13
13
|
|
|
14
|
-
export const VARIANT_COLORS: Record<
|
|
15
|
-
AnimatedCardVariant,
|
|
16
|
-
{ initial: string; final: string; primary: string }
|
|
17
|
-
> = {
|
|
14
|
+
export const VARIANT_COLORS: Record<AnimatedCardVariant, { initial: string; final: string; primary: string }> = {
|
|
18
15
|
[AnimatedCardVariant.CORRECT_ANSWER]: {
|
|
19
16
|
initial: COLORS.GREEN_2,
|
|
20
17
|
final: COLORS.GREEN_4,
|
|
@@ -29,7 +26,7 @@ export const VARIANT_COLORS: Record<
|
|
|
29
26
|
|
|
30
27
|
export const ANIMATION_DELAYS = {
|
|
31
28
|
step3: 500,
|
|
32
|
-
celebrations: 140
|
|
29
|
+
celebrations: 140
|
|
33
30
|
}
|
|
34
31
|
|
|
35
32
|
export const CARD_DIMENSIONS = {
|
|
@@ -52,5 +49,5 @@ export const BADGE_PARAMS = {
|
|
|
52
49
|
initialScale: 0.5,
|
|
53
50
|
}
|
|
54
51
|
|
|
55
|
-
export const SPRING_CONFIG = { stiffness: 241, damping:
|
|
56
|
-
export const SPRING_CONFIG_STEP_3 = { stiffness: 168.8, damping:
|
|
52
|
+
export const SPRING_CONFIG = { stiffness: 241, damping: 18, mass: 0.75 }
|
|
53
|
+
export const SPRING_CONFIG_STEP_3 = { stiffness: 168.8, damping: 15, mass: 0.75 }
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { useEffect
|
|
1
|
+
import { useEffect } from 'react'
|
|
2
2
|
import {
|
|
3
3
|
useSharedValue,
|
|
4
4
|
withDelay,
|
|
5
5
|
withRepeat,
|
|
6
6
|
withSequence,
|
|
7
7
|
withSpring,
|
|
8
|
+
useAnimatedReaction,
|
|
8
9
|
useAnimatedStyle,
|
|
9
|
-
|
|
10
|
+
interpolate,
|
|
10
11
|
} from 'react-native-reanimated'
|
|
11
12
|
import { SpringConfig } from 'react-native-reanimated/lib/typescript/animation/springUtils'
|
|
12
13
|
|
|
@@ -21,9 +22,6 @@ type UseSparkAnimationProps = {
|
|
|
21
22
|
size: number
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
const FADE_OUT_THRESHOLD = 1
|
|
25
|
-
const CYCLE_RESET_THRESHOLD = 0.1
|
|
26
|
-
|
|
27
25
|
export const useSparkAnimation = ({
|
|
28
26
|
id,
|
|
29
27
|
initialDelay,
|
|
@@ -35,44 +33,20 @@ export const useSparkAnimation = ({
|
|
|
35
33
|
size,
|
|
36
34
|
}: UseSparkAnimationProps) => {
|
|
37
35
|
const progress = useSharedValue(0)
|
|
38
|
-
const
|
|
39
|
-
const isFadingOut = useSharedValue(false)
|
|
40
|
-
|
|
41
|
-
const signedAngle = (id === '2' ? -1 : 1) * rotationAngle
|
|
36
|
+
const rotation = useSharedValue(0)
|
|
42
37
|
|
|
43
|
-
|
|
44
|
-
() =>
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
[
|
|
38
|
+
useAnimatedReaction(
|
|
39
|
+
() => progress.value,
|
|
40
|
+
(current, previous) => {
|
|
41
|
+
if (typeof previous === 'number' && current < previous * 0.95) {
|
|
42
|
+
rotation.value = id === '2' ? -rotationAngle : rotationAngle
|
|
43
|
+
} else {
|
|
44
|
+
rotation.value = current * (id === '2' ? -rotationAngle : rotationAngle)
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
[rotation, progress],
|
|
53
48
|
)
|
|
54
49
|
|
|
55
|
-
const animatedStyle = useAnimatedStyle(() => {
|
|
56
|
-
const p = progress.value
|
|
57
|
-
const passedPeak = prevProgress.value >= FADE_OUT_THRESHOLD && p < FADE_OUT_THRESHOLD
|
|
58
|
-
const newCycleStarted = p < CYCLE_RESET_THRESHOLD
|
|
59
|
-
|
|
60
|
-
if (passedPeak) {
|
|
61
|
-
isFadingOut.value = true
|
|
62
|
-
} else if (newCycleStarted) {
|
|
63
|
-
isFadingOut.value = false
|
|
64
|
-
}
|
|
65
|
-
prevProgress.value = p
|
|
66
|
-
|
|
67
|
-
// When fading out, lock rotation at full angle so the star doesn't spin back
|
|
68
|
-
const rotation = isFadingOut.value ? signedAngle : p * signedAngle
|
|
69
|
-
|
|
70
|
-
return {
|
|
71
|
-
opacity: p,
|
|
72
|
-
transform: [{ rotate: `${rotation}deg` }],
|
|
73
|
-
}
|
|
74
|
-
}, [progress])
|
|
75
|
-
|
|
76
50
|
useEffect(() => {
|
|
77
51
|
progress.value = withDelay(
|
|
78
52
|
initialDelay,
|
|
@@ -84,9 +58,21 @@ export const useSparkAnimation = ({
|
|
|
84
58
|
-1,
|
|
85
59
|
),
|
|
86
60
|
)
|
|
87
|
-
|
|
88
|
-
return () => cancelAnimation(progress)
|
|
89
61
|
}, [])
|
|
90
62
|
|
|
91
|
-
|
|
63
|
+
const animatedStyle = useAnimatedStyle(() => {
|
|
64
|
+
const opacity = interpolate(progress.value, [0, 1], [0, 1])
|
|
65
|
+
return {
|
|
66
|
+
position: 'absolute',
|
|
67
|
+
top: y,
|
|
68
|
+
left: x,
|
|
69
|
+
width: size,
|
|
70
|
+
height: size,
|
|
71
|
+
opacity,
|
|
72
|
+
transform: [{ rotate: `${rotation.value}deg` }],
|
|
73
|
+
zIndex: 10,
|
|
74
|
+
}
|
|
75
|
+
}, [progress, rotation])
|
|
76
|
+
|
|
77
|
+
return { animatedStyle }
|
|
92
78
|
}
|