Skip to content
This repository has been archived by the owner on Sep 13, 2020. It is now read-only.

customize elements you don't want to respond on swipe #207

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion examples/Basic/Basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ module.exports = class Basic extends Component {
isOpen: false,
selectedItem: 'About',
};
skippedElements = [];

toggle() {
this.setState({
Expand All @@ -88,7 +89,8 @@ module.exports = class Basic extends Component {
<SideMenu
menu={menu}
isOpen={this.state.isOpen}
onChange={(isOpen) => this.updateMenuState(isOpen)}>
onChange={(isOpen) => this.updateMenuState(isOpen)}
ref={(ref)=> {if (ref !== null) ref.skippedElements = this.skippedElements;}}>
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
Expand All @@ -103,6 +105,14 @@ module.exports = class Basic extends Component {
<Text style={styles.instructions}>
Current selected menu item is: {this.state.selectedItem}
</Text>
<Text
ref={(ref)=> { if (ref && this.skippedElements && this.skippedElements.indexOf(ref._reactInternalInstance._rootNodeID) == -1) this.skippedElements.push(ref._reactInternalInstance._rootNodeID);}}
style={[styles.instructions, {borderWidth: 1, marginTop: 30}]}>
And this is an example of element (TEXT element to be honest), which
will not respond to any swipes to show the menu back. It should, because
`props.edgeHitWidth` is set to `deviceScreen.width`, but it won't :) Sometimes
it may be really usefull, for example, in horizontal scroll views.
</Text>
</View>
<Button style={styles.button} onPress={() => this.toggle()}>
<Image
Expand Down
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ class SideMenu extends Component {
*/
handleMoveShouldSetPanResponder(e: Object, gestureState: Object) {
if (this.gesturesAreEnabled()) {
var rootId = e['dispatchMarker'];
var elemsToSkip = 0;
this.skippedElements.forEach((elem, index, arr)=> {
if (rootId.indexOf(elem) > -1) elemsToSkip++;
});
if (elemsToSkip) return false;

const x = Math.round(Math.abs(gestureState.dx));
const y = Math.round(Math.abs(gestureState.dy));

Expand Down Expand Up @@ -240,7 +247,7 @@ SideMenu.propTypes = {
SideMenu.defaultProps = {
toleranceY: 10,
toleranceX: 10,
edgeHitWidth: 60,
edgeHitWidth: deviceScreen.width,
openMenuOffset: deviceScreen.width * 2 / 3,
hiddenMenuOffset: 0,
onStartShouldSetResponderCapture: () => true,
Expand Down