-
-
Notifications
You must be signed in to change notification settings - Fork 982
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Description After giving it some thought, we decided to add new modifier to our handlers - `mouseButton`. This way users will be able to choose mouse buttons that handler will respond to. For now this prop is available on all handlers, but it is a topic for a short discussion. I think it is also worth to mention, that right now all three mouse buttons work on web, so this prop will allow us to 'disable' all buttons except those provided as arguments. This PR also adds two small examples (one for buttons and one for context menu) that can be used to test given prop on other platforms (when this functionality will be added) ## Test plan Tested on example app.
- Loading branch information
Showing
19 changed files
with
393 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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 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 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,181 @@ | ||
import React from 'react'; | ||
import { | ||
Gesture, | ||
GestureDetector, | ||
GestureType, | ||
MouseButton, | ||
Directions, | ||
ScrollView, | ||
} from 'react-native-gesture-handler'; | ||
import { StyleSheet, View, Text } from 'react-native'; | ||
|
||
const COLORS = ['darkmagenta', 'darkgreen', 'darkblue', 'crimson', 'pink']; | ||
|
||
type TestProps = { | ||
name: string; | ||
gestureHandlers: GestureType[]; | ||
}; | ||
|
||
function Test({ name, gestureHandlers }: TestProps) { | ||
return ( | ||
<View style={styles.center}> | ||
<Text>{name}</Text> | ||
<View | ||
style={[ | ||
{ margin: 10, width: '100%', flexDirection: 'row' }, | ||
styles.center, | ||
]}> | ||
{gestureHandlers.map((handler, index) => { | ||
return ( | ||
<GestureDetector gesture={handler} key={index}> | ||
<View style={[styles.box, { backgroundColor: COLORS[index] }]} /> | ||
</GestureDetector> | ||
); | ||
})} | ||
</View> | ||
</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() | ||
.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', | ||
}, | ||
box: { | ||
width: 75, | ||
height: 75, | ||
}, | ||
}); |
This file contains 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 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 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 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 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 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.