-
-
Notifications
You must be signed in to change notification settings - Fork 1k
[macOS] Add LongPressGestureHandler
#3014
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 18 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
4431e01
It works
m-bert 45ff492
Add example
m-bert ec9abe2
Minor changes
m-bert 152b8f1
Another changes
m-bert 79537f5
Fail or cancel on mouseUp and mouseDrag
m-bert 0180943
Remove EmptyExample
m-bert 3aaf040
Merge Gesture Handler implementations
m-bert 20ffc3c
Merge recognizer implementation
m-bert 75e0f8e
Extract logic from if condition to separate function
m-bert b39f8fc
Change logs
m-bert 4e1a166
Refactor shouldCancelGesture
m-bert 5eb5751
Merge branch 'main' into @mbert/add-longpress-macos
m-bert 55a7b22
Merge branch 'main' into @mbert/add-longpress-macos
m-bert d3ae413
Merge branch 'main' into @mbert/add-longpress-macos
m-bert 85fa302
Do not end immediately
m-bert 9cfd459
Update example
m-bert bab5b11
Fix wrong state changes
m-bert bd4adf5
Merge branch 'main' into @mbert/add-longpress-macos
m-bert 855c5ca
Change to ternary
m-bert a3b33e4
Mergele main
m-bert 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
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,103 @@ | ||
| import { StyleSheet, View } from 'react-native'; | ||
| import { Gesture, GestureDetector } from 'react-native-gesture-handler'; | ||
| import Animated, { | ||
| interpolateColor, | ||
| useAnimatedStyle, | ||
| useSharedValue, | ||
| withTiming, | ||
| } from 'react-native-reanimated'; | ||
|
|
||
| const Durations = { | ||
| LongPress: 750, | ||
| Reset: 350, | ||
| Scale: 120, | ||
| }; | ||
|
|
||
| const Colors = { | ||
| Initial: '#0a2688', | ||
| Loading: '#6fcef5', | ||
| Success: '#32a852', | ||
| Fail: '#b02525', | ||
| }; | ||
|
|
||
| export default function LongPressExample() { | ||
| const isPressed = useSharedValue(false); | ||
| const colorProgress = useSharedValue(0); | ||
| const color1 = useSharedValue(Colors.Initial); | ||
| const color2 = useSharedValue(Colors.Loading); | ||
|
|
||
| const animatedStyles = useAnimatedStyle(() => { | ||
| const backgroundColor = interpolateColor( | ||
| colorProgress.value, | ||
| [0, 1], | ||
| [color1.value, color2.value] | ||
| ); | ||
|
|
||
| return { | ||
| transform: [ | ||
| { | ||
| scale: withTiming(isPressed.value ? 1.2 : 1, { | ||
| duration: Durations.Scale, | ||
| }), | ||
| }, | ||
| ], | ||
| backgroundColor, | ||
| }; | ||
| }); | ||
|
|
||
| const g = Gesture.LongPress() | ||
| .onBegin(() => { | ||
| console.log('onBegin'); | ||
|
|
||
| isPressed.value = true; | ||
| colorProgress.value = withTiming(1, { | ||
| duration: Durations.LongPress, | ||
| }); | ||
| }) | ||
| .onStart(() => console.log('onStart')) | ||
| .onEnd(() => console.log('onEnd')) | ||
| .onFinalize((_, success) => { | ||
| console.log('onFinalize', success); | ||
|
|
||
| isPressed.value = false; | ||
|
|
||
| color1.value = Colors.Initial; | ||
| color2.value = success ? Colors.Success : Colors.Fail; | ||
|
|
||
| colorProgress.value = withTiming( | ||
| 0, | ||
| { | ||
| duration: Durations.Reset, | ||
| }, | ||
| () => { | ||
| color2.value = Colors.Loading; | ||
| } | ||
| ); | ||
| }) | ||
| .onTouchesDown(() => console.log('onTouchesDown')) | ||
| .onTouchesMove(() => console.log('onTouchesMove')) | ||
| .onTouchesUp(() => console.log('onTouchesUp')) | ||
| .minDuration(Durations.LongPress); | ||
|
|
||
| return ( | ||
| <View style={styles.container}> | ||
| <GestureDetector gesture={g}> | ||
| <Animated.View style={[styles.pressBox, animatedStyles]} /> | ||
| </GestureDetector> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| container: { | ||
| flex: 1, | ||
| justifyContent: 'space-around', | ||
| alignItems: 'center', | ||
| }, | ||
|
|
||
| pressBox: { | ||
| width: 100, | ||
| height: 100, | ||
| borderRadius: 20, | ||
| }, | ||
| }); | ||
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
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.