Skip to content

Commit

Permalink
Fix ScrollView not scrollable in Overlay (#4561)
Browse files Browse the repository at this point in the history
Fixes an issue with ScrollView inside an Overlay. While down events were propagated to the view, move events were consumed by the overlay preventing scroll components from functioning correctly.
  • Loading branch information
guyca authored Jan 10, 2019
1 parent 7a26ea9 commit d3ab1ac
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@ public boolean handleDown(MotionEvent event) {
TouchLocation location = getTouchLocation(event);
if (location == TouchLocation.Inside) {
reactView.dispatchTouchEventToJs(event);
return false;
}
if (interceptTouchOutside.isTrue()) {
return location == TouchLocation.Inside;
}
return location == TouchLocation.Outside;
return interceptTouchOutside.isFalseOrUndefined();
}

private TouchLocation getTouchLocation(MotionEvent ev) {
Expand Down
3 changes: 3 additions & 0 deletions playground/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ if (Platform.OS === 'android') {
title
},
options: {
layout: {
componentBackgroundColor: 'transparent'
},
overlay: {
interceptTouchOutside: true
}
Expand Down
17 changes: 17 additions & 0 deletions playground/src/screens/ComplexLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ComplexLayout extends Component {
<Button title={'External component in stack'} testID={testIDs.EXTERNAL_COMPONENT_IN_STACK} onPress={this.onExternalComponentInStackPressed} />
<Button title={'External component in deep stack'} testID={testIDs.EXTERNAL_COMPONENT_IN_DEEP_STACK} onPress={this.onExternalComponentInDeepStackPressed} />
<Button title={'SideMenu layout inside a bottomTab'} testID={testIDs.SIDE_MENU_LAYOUT_INSIDE_BOTTOM_TAB} onPress={this.onSideMenuLayoutInsideBottomTabPressed} />
<Button title='Show touch through overlay with scroll' testID={testIDs.SHOW_TOUCH_THROUGH_OVERLAY_SCROLLER} onPress={() => this.onClickShowOverlayWithScroll(true)} />
</View>
);
}
Expand Down Expand Up @@ -151,6 +152,22 @@ class ComplexLayout extends Component {
}
});
}

onClickShowOverlayWithScroll = async (interceptTouchOutside) => {
await Navigation.showOverlay({
component: {
name: 'navigation.playground.CustomDialogWithScroll',
options: {
layout: {
componentBackgroundColor: 'transparent'
},
overlay: {
interceptTouchOutside
}
}
}
});
}
}

module.exports = ComplexLayout;
Expand Down
20 changes: 4 additions & 16 deletions playground/src/screens/OptionsScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ class OptionsScreen extends Component {
<Button title='Custom Transition' testID={testIDs.CUSTOM_TRANSITION_BUTTON} onPress={this.onClickCustomTransition} />
{Platform.OS === 'android' && <Button title='Hide fab' testID={testIDs.HIDE_FAB} onPress={this.onClickFab} />}
<Button title='Show overlay' testID={testIDs.SHOW_OVERLAY_BUTTON} onPress={() => this.onClickShowOverlay(true)} />
<Button title='Show touch through overlay with scroll' testID={testIDs.SHOW_TOUCH_THROUGH_OVERLAY_SCROLLER} onPress={() => this.onClickShowOverlayWithScroll(true)} />
<Button title='Show touch through overlay' testID={testIDs.SHOW_TOUCH_THROUGH_OVERLAY_BUTTON} onPress={() => this.onClickShowOverlay(false)} />
<Button title='Push Default Options Screen' testID={testIDs.PUSH_DEFAULT_OPTIONS_BUTTON} onPress={this.onClickPushDefaultOptionsScreen} />
<Button title='Show TopBar react view' testID={testIDs.SHOW_TOPBAR_REACT_VIEW} onPress={this.onShowTopBarReactView} />
Expand Down Expand Up @@ -270,28 +269,17 @@ class OptionsScreen extends Component {
component: {
name: 'navigation.playground.CustomDialog',
options: {
layout: {
componentBackgroundColor: 'transparent'
},
overlay: {
interceptTouchOutside
}
}
}
});
}

onClickShowOverlayWithScroll = async (interceptTouchOutside) => {
await Navigation.showOverlay({
component: {
name: 'navigation.playground.CustomDialogWithScroll',
options: {
overlay: {
interceptTouchOutside
interceptTouchOutside: false
}
}
}
});
}


onClickPushDefaultOptionsScreen = () => {
Navigation.setDefaultOptions({
topBar: {
Expand Down
108 changes: 54 additions & 54 deletions playground/src/screens/complexlayouts/CustomDialogWithScroll.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
const React = require('react');
const { PureComponent } = require('react');

const { Text, Button, View, Alert, Platform ,ScrollView} = require('react-native');
const { Text, Button, View, Alert, Platform, ScrollView, StyleSheet } = require('react-native');
const { Navigation } = require('react-native-navigation');

const testIDs = require('../../testIDs');

class CustomDialogWithScroll extends PureComponent {
static options() {
return {
statusBarBackgroundColor: 'green'
};
}
static options() {
return {
statusBarBackgroundColor: 'green'
};
}

render() {
return (
<View style={styles.container}>
<ScrollView style={styles.root}>
<View style={{height: 60, backgroundColor: 'red'}}/>
<View style={{height: 60, backgroundColor: 'green'}}/>
<View style={{height: 60, backgroundColor: 'red'}}/>
<View style={{height: 60, backgroundColor: 'green'}}/>
<View style={{height: 60, backgroundColor: 'red'}}/>
<View style={{height: 60, backgroundColor: 'green'}}/>
</ScrollView>
</View>
);
}
render() {
return (
<View style={styles.root}>
<View style={{ height: 200, width: '80%', alignSelf: 'center', flexDirection: 'row' }}>
<ScrollView style={styles.scrollView} contentContainerStyle={styles.content}>
<View style={{ height: 60, backgroundColor: 'red' }} />
<View style={{ height: 60, backgroundColor: 'green' }} />
<View style={{ height: 60, backgroundColor: 'red' }} />
<View style={{ height: 60, backgroundColor: 'green' }} />
<View style={{ height: 60, backgroundColor: 'red' }} />
<View style={{ height: 60, backgroundColor: 'green' }} />
</ScrollView>
</View>
</View>
);
}

didDisappear() {
if (Platform.OS === 'android') {
Alert.alert('Overlay disappeared');
}
didDisappear() {
if (Platform.OS === 'android') {
Alert.alert('Overlay disappeared');
}
}
}

const styles = {
root: {
width: 400,
height: 200,
},
container: {

width: 400,
height: 200,
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
alignSelf: 'center'
},
h1: {
fontSize: 24,
textAlign: 'center',
margin: 10
},
h2: {
fontSize: 12,
textAlign: 'center',
margin: 10
},
footer: {
fontSize: 10,
color: '#888',
marginTop: 10
}
};
const styles = StyleSheet.create({
scrollView: {
backgroundColor: 'blue'
},
root: {
flex: 1,
flexDirection: 'column',
justifyContent: 'flex-end'
},
content: {
backgroundColor: 'blue'
},
h1: {
fontSize: 24,
textAlign: 'center',
margin: 10
},
h2: {
fontSize: 12,
textAlign: 'center',
margin: 10
},
footer: {
fontSize: 10,
color: '#888',
marginTop: 10
}
});

module.exports = CustomDialogWithScroll;

0 comments on commit d3ab1ac

Please sign in to comment.