-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: Add max value refresher for transfer redesigned confirmations
#15074
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
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b825519
Add max value refresher for transfer confirmation
OGPoyraz 8830dd3
Remove comment
OGPoyraz 73511e7
Fix tests
OGPoyraz 8fa1af9
fix lint
OGPoyraz 2a452a7
fix lint
OGPoyraz 44df696
Add suggestions
OGPoyraz 7439885
Fix more suggestion
OGPoyraz dc08bc9
Add prevent pulse for non max selection
OGPoyraz b4414ef
fix lint
OGPoyraz 0e6fbda
Merge branch 'main' into ogp/4797
OGPoyraz a244d6d
Set minCycle as 0 for prev instances
OGPoyraz 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
2 changes: 1 addition & 1 deletion
2
...ts/animated-pulse/animated-pulse.test.tsx → ...UI/animated-pulse/animated-pulse.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
135 changes: 135 additions & 0 deletions
135
app/components/Views/confirmations/components/UI/animated-pulse/animated-pulse.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,135 @@ | ||
| import React, { useCallback, useEffect, useRef } from 'react'; | ||
| import { Animated, View, ViewProps } from 'react-native'; | ||
|
|
||
| interface AnimatedPulseProps extends ViewProps { | ||
| children: React.ReactNode; | ||
| isPulsing?: boolean; | ||
| minCycles?: number; | ||
| preventPulse?: boolean; | ||
| } | ||
|
|
||
| const DURATION = { | ||
| fadeIn: 750, | ||
| fadeOut: 750, | ||
| fadeInFinal: 750, | ||
| } as const; | ||
|
|
||
| const AnimatedPulse = ({ | ||
| children, | ||
| isPulsing = true, | ||
| minCycles = 2, // Default to 2 cycles minimum for a better visual effect | ||
digiwand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| preventPulse = false, | ||
| ...props | ||
| }: AnimatedPulseProps) => { | ||
| const opacity = useRef(new Animated.Value(0.3)).current; | ||
| const currentAnimationRef = useRef<Animated.CompositeAnimation | null>(null); | ||
| const isCurrentlyPulsingRef = useRef(isPulsing); | ||
| const cyclesNeededRef = useRef(isPulsing ? minCycles : 0); | ||
| const cyclesCompletedRef = useRef(0); | ||
|
|
||
| const cleanup = useCallback(() => { | ||
| if (currentAnimationRef.current) { | ||
| currentAnimationRef.current.stop(); | ||
| currentAnimationRef.current = null; | ||
| } | ||
| }, []); | ||
|
|
||
| useEffect(() => { | ||
| if (isCurrentlyPulsingRef.current && !isPulsing) { | ||
| // Set the number of cycles we need to complete | ||
| cyclesNeededRef.current = Math.max( | ||
| minCycles, | ||
| cyclesCompletedRef.current + 1, | ||
| ); | ||
| } else if (!isCurrentlyPulsingRef.current && isPulsing) { | ||
| // Reset cycle count when starting to pulse again | ||
| cyclesCompletedRef.current = 0; | ||
| } | ||
| isCurrentlyPulsingRef.current = isPulsing; | ||
| }, [isPulsing, minCycles]); | ||
|
|
||
| // Start a single pulse cycle and decide what to do next | ||
| const runSinglePulseCycle = useCallback(() => { | ||
| // Create and store the new animation | ||
| const sequence = Animated.sequence([ | ||
| Animated.timing(opacity, { | ||
| toValue: 1, | ||
| duration: DURATION.fadeIn, | ||
| useNativeDriver: true, | ||
| }), | ||
| Animated.timing(opacity, { | ||
| toValue: 0.3, | ||
| duration: DURATION.fadeOut, | ||
| useNativeDriver: true, | ||
| }), | ||
| ]); | ||
|
|
||
| currentAnimationRef.current = sequence; | ||
|
|
||
| // Start the animation | ||
| sequence.start(({ finished }) => { | ||
| if (finished) { | ||
| // Increment completed cycles | ||
| cyclesCompletedRef.current += 1; | ||
|
|
||
| // Continue pulsing if: | ||
| // 1. isPulsing is true, OR | ||
| // 2. We haven't completed the minimum required cycles | ||
| if ( | ||
| isCurrentlyPulsingRef.current || | ||
| cyclesCompletedRef.current < cyclesNeededRef.current | ||
| ) { | ||
| // Schedule the next cycle | ||
| runSinglePulseCycle(); | ||
| } else { | ||
| // We're done pulsing and have completed required cycles | ||
| // Fade to full opacity | ||
| Animated.timing(opacity, { | ||
| toValue: 1, | ||
| duration: DURATION.fadeInFinal, | ||
| useNativeDriver: true, | ||
| }).start(); | ||
|
|
||
| // Clear animation ref | ||
| currentAnimationRef.current = null; | ||
| } | ||
| } | ||
| }); | ||
| }, [opacity]); | ||
|
|
||
| // Handle animation lifecycle | ||
| useEffect(() => { | ||
| // Only start animation if: | ||
| // 1. We should be pulsing, OR | ||
| // 2. We just stopped pulsing but need to complete cycles | ||
| const shouldAnimate = | ||
| isPulsing || | ||
| (!isPulsing && cyclesCompletedRef.current < cyclesNeededRef.current); | ||
|
|
||
| if (shouldAnimate && !currentAnimationRef.current) { | ||
| runSinglePulseCycle(); | ||
| } else if (!shouldAnimate && !currentAnimationRef.current) { | ||
| // No animation needed, just ensure full opacity | ||
| Animated.timing(opacity, { | ||
| toValue: 1, | ||
| duration: DURATION.fadeInFinal, | ||
| useNativeDriver: true, | ||
| }).start(); | ||
| } | ||
|
|
||
| // Cleanup | ||
| return cleanup; | ||
| }, [cleanup, isPulsing, opacity, runSinglePulseCycle]); | ||
|
|
||
| if (preventPulse) { | ||
| return <View>{children}</View>; | ||
| } | ||
|
|
||
| return ( | ||
| <Animated.View style={{ opacity }} {...props}> | ||
| {children} | ||
| </Animated.View> | ||
| ); | ||
| }; | ||
|
|
||
digiwand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| export default AnimatedPulse; | ||
digiwand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
File renamed without changes.
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
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
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
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
61 changes: 0 additions & 61 deletions
61
...s/components/info/typed-sign-v3v4/simulation/components/animated-pulse/animated-pulse.tsx
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.
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.