-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Add mouseButton prop
#2676
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
Add mouseButton prop
#2676
Changes from 33 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
cb67ac2
Remove context menu
m-bert bd3b6a9
Add prop
m-bert 441c02c
Change enum order to match web
m-bert f82e08a
Change enum
m-bert 6e1c651
Fix field in TouchEventManager
m-bert 9731777
Implement logic on tap
m-bert edd5c2c
Add example
m-bert 75f94b2
Merge branch 'main' into @mbert/web-right-click
m-bert eeb5ada
Change type
m-bert f414760
Another type change
m-bert fd7e0bb
Yet another type change
m-bert 5373c13
change condition
m-bert 0e2aaf8
Add check to other gestures
m-bert ecfcee2
Update example
m-bert 6284ab3
Change View to ScrollView
m-bert 64ff5d4
remove console.log
m-bert 193e240
Change button names
m-bert 0cbaebd
Change MouseButtons name in App
m-bert f77f453
Add MouseButton.ALL
m-bert 09e11fd
Rename function
m-bert 577724b
Merge branch 'main' into @mbert/web-right-click
m-bert 7501737
Merge branch 'main' into @mbert/web-right-click
m-bert 2d39d22
Merge branch 'main' into @mbert/web-right-click
m-bert ac10025
Merge branch 'main' into @mbert/web-right-click
m-bert 7b660b4
Merge branch 'main' into @mbert/web-right-click
m-bert fbe82e2
Add enableContextMenu to builder
m-bert 8f518b0
Merge branch 'main' into @mbert/web-right-click
m-bert 0a1a18d
False now turns off context menu
m-bert 1107e38
Move enableContextMenu to GestureDetector
m-bert 6bd1c79
Add context menu example
m-bert 19aa15b
Remove listeners on handler drop
m-bert 063889e
Update example
m-bert 5313243
Merge main
m-bert 47e72e1
Merge branch 'main' into @mbert/web-right-click
m-bert 60b8487
Change example
m-bert 9ece9f9
Remove EnableContextMenu alias
m-bert 2327174
Remove bounded listeners
m-bert 1da7bfb
Remove finalize to onDestroy
m-bert 26c4b3c
Restore default context menu blockade in LongPress
m-bert 8279c90
Add destroy to WebDelegate
m-bert 471002e
Restore bounded listeners
m-bert 7432cdd
Revert "Restore bounded listeners"
m-bert c75fdb7
Change binding to this:void
m-bert f357411
Add destroy to delegate interface
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,61 @@ | ||
| import React from 'react'; | ||
| import { StyleSheet, View } from 'react-native'; | ||
| import { | ||
| Gesture, | ||
| GestureDetector, | ||
| MouseButton, | ||
| } from 'react-native-gesture-handler'; | ||
|
|
||
| export default function ContextMenuExample() { | ||
| const p1 = Gesture.Pan().mouseButton(MouseButton.RIGHT); | ||
| const p2 = Gesture.Pan(); | ||
| const p3 = Gesture.Pan(); | ||
|
|
||
| return ( | ||
| <View style={styles.container}> | ||
| <GestureDetector gesture={p1}> | ||
| <View style={[styles.box, styles.grandParent]}> | ||
| <GestureDetector gesture={p2} enableContextMenu={true}> | ||
| <View style={[styles.box, styles.parent]}> | ||
| <GestureDetector gesture={p3} enableContextMenu={false}> | ||
| <View style={[styles.box, styles.child]} /> | ||
| </GestureDetector> | ||
| </View> | ||
| </GestureDetector> | ||
| </View> | ||
| </GestureDetector> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| container: { | ||
| flex: 1, | ||
| justifyContent: 'space-around', | ||
| alignItems: 'center', | ||
| }, | ||
|
|
||
| grandParent: { | ||
| width: 300, | ||
| height: 300, | ||
| backgroundColor: 'lightblue', | ||
| }, | ||
|
|
||
| parent: { | ||
| width: 200, | ||
| height: 200, | ||
| backgroundColor: 'lightgreen', | ||
| }, | ||
|
|
||
| child: { | ||
| width: 100, | ||
| height: 100, | ||
| backgroundColor: 'crimson', | ||
| }, | ||
|
|
||
| box: { | ||
| display: 'flex', | ||
| justifyContent: 'space-around', | ||
| alignItems: 'center', | ||
| }, | ||
| }); | ||
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,206 @@ | ||
| import React from 'react'; | ||
| import { | ||
| Gesture, | ||
| GestureDetector, | ||
| GestureType, | ||
| MouseButton, | ||
| Directions, | ||
| ScrollView, | ||
| } from 'react-native-gesture-handler'; | ||
| import { StyleSheet, View, Text } from 'react-native'; | ||
|
|
||
| type TestProps = { | ||
| name: string; | ||
| gestureHandlers: GestureType[]; | ||
| }; | ||
|
|
||
| function Test({ name, gestureHandlers }: TestProps) { | ||
| return ( | ||
| <View style={[{ height: 300 }, styles.center]}> | ||
| <Text> {name} </Text> | ||
| <View style={{ flexDirection: 'row' }}> | ||
| <GestureDetector gesture={gestureHandlers[0]}> | ||
| <View style={styles.boxLeft} /> | ||
| </GestureDetector> | ||
| <GestureDetector gesture={gestureHandlers[1]}> | ||
| <View style={styles.boxMiddle} /> | ||
| </GestureDetector> | ||
| <GestureDetector gesture={gestureHandlers[2]}> | ||
| <View style={styles.boxRight} /> | ||
| </GestureDetector> | ||
| </View> | ||
| <View style={{ flexDirection: 'row' }}> | ||
| <GestureDetector gesture={gestureHandlers[3]}> | ||
| <View style={styles.boxLeftRight} /> | ||
| </GestureDetector> | ||
| <GestureDetector gesture={gestureHandlers[4]}> | ||
| <View style={styles.boxAll} /> | ||
| </GestureDetector> | ||
| </View> | ||
j-piasecki marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| function TapTests() { | ||
| const leftTap = Gesture.Tap() | ||
| .mouseButton(MouseButton.LEFT) | ||
| .onEnd(() => console.log('Tap with left')); | ||
|
|
||
| const middleTap = Gesture.Tap() | ||
| .mouseButton(MouseButton.MIDDLE) | ||
| .onEnd(() => console.log('Tap with middle')); | ||
|
|
||
| const rightTap = Gesture.Tap() | ||
| .mouseButton(MouseButton.RIGHT) | ||
| .onEnd(() => console.log('Tap with right')); | ||
|
|
||
| const leftRightTap = Gesture.Tap() | ||
| .mouseButton(MouseButton.LEFT | MouseButton.RIGHT) | ||
| .onEnd(() => console.log('Tap with left | right')); | ||
|
|
||
| const allTap = Gesture.Tap() | ||
m-bert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .mouseButton(MouseButton.ALL) | ||
| .onEnd(() => console.log('Tap with any button')); | ||
|
|
||
| const gestureHandlers = [leftTap, middleTap, rightTap, leftRightTap, allTap]; | ||
|
|
||
| return <Test name={'Tap'} gestureHandlers={gestureHandlers} />; | ||
| } | ||
|
|
||
| function PanTests() { | ||
| const leftPan = Gesture.Pan() | ||
| .mouseButton(MouseButton.LEFT) | ||
| .onChange(() => console.log('Panning with left')); | ||
|
|
||
| const middlePan = Gesture.Pan() | ||
| .mouseButton(MouseButton.MIDDLE) | ||
| .onChange(() => console.log('Panning with middle')); | ||
|
|
||
| const rightPan = Gesture.Pan() | ||
| .mouseButton(MouseButton.RIGHT) | ||
| .onChange(() => console.log('Panning with right')); | ||
|
|
||
| const leftRightPan = Gesture.Pan() | ||
| .mouseButton(MouseButton.LEFT | MouseButton.RIGHT) | ||
| .onChange(() => console.log('Panning with left | right')); | ||
|
|
||
| const allPan = Gesture.Pan() | ||
| .mouseButton(MouseButton.ALL) | ||
| .onChange(() => console.log('Panning with any button')); | ||
|
|
||
| const gestureHandlers = [leftPan, middlePan, rightPan, leftRightPan, allPan]; | ||
|
|
||
| return <Test name={'Pan'} gestureHandlers={gestureHandlers} />; | ||
| } | ||
|
|
||
| function LongPressTests() { | ||
| const leftLongPress = Gesture.LongPress() | ||
| .mouseButton(MouseButton.LEFT) | ||
| .onStart(() => console.log('LongPress with left')); | ||
|
|
||
| const middleLongPress = Gesture.LongPress() | ||
| .mouseButton(MouseButton.MIDDLE) | ||
| .onStart(() => console.log('LongPress with middle')); | ||
|
|
||
| const rightLongPress = Gesture.LongPress() | ||
| .mouseButton(MouseButton.RIGHT) | ||
| .onStart(() => console.log('LongPress with right')); | ||
|
|
||
| const leftRightLongPress = Gesture.LongPress() | ||
| .mouseButton(MouseButton.LEFT | MouseButton.RIGHT) | ||
| .onStart(() => console.log('LongPress with left | right')); | ||
|
|
||
| const allLongPress = Gesture.LongPress() | ||
| .mouseButton(MouseButton.ALL) | ||
| .onStart(() => console.log('LongPress with any button')); | ||
|
|
||
| const gestureHandlers = [ | ||
| leftLongPress, | ||
| middleLongPress, | ||
| rightLongPress, | ||
| leftRightLongPress, | ||
| allLongPress, | ||
| ]; | ||
|
|
||
| return <Test name={'LongPress'} gestureHandlers={gestureHandlers} />; | ||
| } | ||
|
|
||
| function FlingTests() { | ||
| const leftFling = Gesture.Fling() | ||
| .direction(Directions.LEFT | Directions.RIGHT) | ||
| .mouseButton(MouseButton.LEFT) | ||
| .onStart(() => console.log('Fling with left')); | ||
|
|
||
| const middleFling = Gesture.Fling() | ||
| .direction(Directions.LEFT | Directions.RIGHT) | ||
| .mouseButton(MouseButton.MIDDLE) | ||
| .onStart(() => console.log('Fling with middle')); | ||
|
|
||
| const rightFling = Gesture.Fling() | ||
| .direction(Directions.LEFT | Directions.RIGHT) | ||
| .mouseButton(MouseButton.RIGHT) | ||
| .onStart(() => console.log('Fling with right')); | ||
|
|
||
| const leftRightFling = Gesture.Fling() | ||
| .direction(Directions.LEFT | Directions.RIGHT) | ||
| .mouseButton(MouseButton.LEFT | MouseButton.RIGHT) | ||
| .onStart(() => console.log('Fling with left | right')); | ||
|
|
||
| const allFling = Gesture.Fling() | ||
| .direction(Directions.LEFT | Directions.RIGHT) | ||
| .mouseButton(MouseButton.ALL) | ||
| .onStart(() => console.log('Fling with any button')); | ||
|
|
||
| const gestureHandlers = [ | ||
| leftFling, | ||
| middleFling, | ||
| rightFling, | ||
| leftRightFling, | ||
| allFling, | ||
| ]; | ||
|
|
||
| return <Test name={'Fling'} gestureHandlers={gestureHandlers} />; | ||
| } | ||
|
|
||
| export default function Buttons() { | ||
| return ( | ||
| <ScrollView style={{ flex: 1 }}> | ||
| <TapTests /> | ||
| <PanTests /> | ||
| <LongPressTests /> | ||
| <FlingTests /> | ||
| </ScrollView> | ||
| ); | ||
| } | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| center: { | ||
| alignItems: 'center', | ||
| justifyContent: 'space-around', | ||
| }, | ||
| boxLeft: { | ||
| width: 100, | ||
| height: 100, | ||
j-piasecki marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| backgroundColor: 'darkmagenta', | ||
| }, | ||
| boxRight: { | ||
| width: 100, | ||
| height: 100, | ||
| backgroundColor: 'darkblue', | ||
| }, | ||
| boxMiddle: { | ||
| width: 100, | ||
| height: 100, | ||
| backgroundColor: 'darkgreen', | ||
| }, | ||
| boxLeftRight: { | ||
| width: 100, | ||
| height: 100, | ||
| backgroundColor: 'crimson', | ||
| }, | ||
| boxAll: { | ||
| width: 100, | ||
| height: 100, | ||
| backgroundColor: 'plum', | ||
| }, | ||
| }); | ||
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
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.