Skip to content

Commit 6d2d981

Browse files
authored
Add useGestureHandler to Modal (#1483)
1 parent 99ab745 commit 6d2d981

File tree

3 files changed

+44
-33
lines changed

3 files changed

+44
-33
lines changed

demo/src/screens/incubatorScreens/PanViewScreen.tsx

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -68,40 +68,37 @@ class PanViewScreen extends Component {
6868
};
6969

7070
renderDialog = () => {
71-
const Container = Constants.isAndroid ? GestureHandlerRootView : React.Fragment;
72-
const containerProps = Constants.isAndroid ? {style: styles.gestureHandler} : {};
7371
return (
7472
<View flex>
7573
<Modal
7674
transparent
7775
onBackgroundPress={this.onDialogDismissed}
7876
overlayBackgroundColor={overlayBackgroundColor}
77+
useGestureHandlerRootView
7978
visible
8079
>
81-
<Container {...containerProps}>
82-
<PanView
83-
directions={[PanView.directions.DOWN]}
84-
dismissible
85-
springBack
86-
// threshold={{y: 10}}
87-
containerStyle={styles.panView}
88-
onDismiss={this.onDialogDismissed}
89-
>
90-
<View style={styles.dialog}>
91-
<Text text60 margin-s2>
92-
Title (swipe here)
93-
</Text>
94-
<View height={1} bg-grey40/>
95-
<FlatList
96-
showsVerticalScrollIndicator={false}
97-
style={styles.verticalScroll}
98-
data={colors}
99-
renderItem={this.renderVerticalItem}
100-
keyExtractor={this.keyExtractor}
101-
/>
102-
</View>
103-
</PanView>
104-
</Container>
80+
<PanView
81+
directions={[PanView.directions.DOWN]}
82+
dismissible
83+
springBack
84+
// threshold={{y: 10}}
85+
containerStyle={styles.panView}
86+
onDismiss={this.onDialogDismissed}
87+
>
88+
<View style={styles.dialog}>
89+
<Text text60 margin-s2>
90+
Title (swipe here)
91+
</Text>
92+
<View height={1} bg-grey40/>
93+
<FlatList
94+
showsVerticalScrollIndicator={false}
95+
style={styles.verticalScroll}
96+
data={colors}
97+
renderItem={this.renderVerticalItem}
98+
keyExtractor={this.keyExtractor}
99+
/>
100+
</View>
101+
</PanView>
105102
</Modal>
106103
</View>
107104
);

generatedTypes/components/modal/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export interface ModalProps extends RNModalProps {
2828
* label is constructed by traversing all the children and accumulating all the Text nodes separated by space.
2929
*/
3030
accessibilityLabel?: string;
31+
/**
32+
* Should add a GestureHandlerRootView (Android only)
33+
*/
34+
useGestureHandlerRootView?: boolean;
3135
}
3236
/**
3337
* @description: Component that present content on top of the invoking screen

src/components/modal/index.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import _ from 'lodash';
22
import React, {Component} from 'react';
3+
import {GestureHandlerRootView} from 'react-native-gesture-handler';
34
import {
45
StyleSheet,
56
Modal as RNModal,
@@ -42,6 +43,10 @@ export interface ModalProps extends RNModalProps {
4243
* label is constructed by traversing all the children and accumulating all the Text nodes separated by space.
4344
*/
4445
accessibilityLabel?: string;
46+
/**
47+
* Should add a GestureHandlerRootView (Android only)
48+
*/
49+
useGestureHandlerRootView?: boolean;
4550
}
4651

4752
/**
@@ -81,24 +86,29 @@ class Modal extends Component<ModalProps> {
8186
{/*
8287
// @ts-ignore */}
8388
<TouchableWithoutFeedback {...accessibilityProps} onPress={onBackgroundPress}>
84-
<View style={isScreenReaderEnabled ? styles.accessibleOverlayView : styles.overlayView}/>
89+
<View style={isScreenReaderEnabled ? styles.accessibleOverlayView : styles.fill}/>
8590
</TouchableWithoutFeedback>
8691
</View>
8792
);
8893
}
8994
}
9095

9196
render() {
92-
const {blurView, enableModalBlur, visible, ...others} = this.props;
97+
const {blurView, enableModalBlur, visible, useGestureHandlerRootView, ...others} = this.props;
9398
const defaultContainer = enableModalBlur && Constants.isIOS && BlurView ? BlurView : View;
99+
const useGestureHandler = useGestureHandlerRootView && Constants.isAndroid;
100+
const GestureContainer = useGestureHandler ? GestureHandlerRootView : React.Fragment;
101+
const gestureContainerProps = useGestureHandler ? {style: styles.fill} : {};
94102
const Container: any = blurView ? blurView : defaultContainer;
95103

96104
return (
97105
<RNModal visible={Boolean(visible)} {...others}>
98-
<Container style={{flex: 1}} blurType="light">
99-
{this.renderTouchableOverlay()}
100-
{this.props.children}
101-
</Container>
106+
<GestureContainer {...gestureContainerProps}>
107+
<Container style={styles.fill} blurType="light">
108+
{this.renderTouchableOverlay()}
109+
{this.props.children}
110+
</Container>
111+
</GestureContainer>
102112
</RNModal>
103113
);
104114
}
@@ -108,7 +118,7 @@ const styles = StyleSheet.create({
108118
touchableOverlay: {
109119
...StyleSheet.absoluteFillObject
110120
},
111-
overlayView: {
121+
fill: {
112122
flex: 1
113123
},
114124
accessibleOverlayView: {

0 commit comments

Comments
 (0)