Skip to content

Add useGestureHandler to Modal #1483

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 1 commit into from
Aug 22, 2021
Merged
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
49 changes: 23 additions & 26 deletions demo/src/screens/incubatorScreens/PanViewScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,40 +68,37 @@ class PanViewScreen extends Component {
};

renderDialog = () => {
const Container = Constants.isAndroid ? GestureHandlerRootView : React.Fragment;
const containerProps = Constants.isAndroid ? {style: styles.gestureHandler} : {};
return (
<View flex>
<Modal
transparent
onBackgroundPress={this.onDialogDismissed}
overlayBackgroundColor={overlayBackgroundColor}
useGestureHandlerRootView
visible
>
<Container {...containerProps}>
<PanView
directions={[PanView.directions.DOWN]}
dismissible
springBack
// threshold={{y: 10}}
containerStyle={styles.panView}
onDismiss={this.onDialogDismissed}
>
<View style={styles.dialog}>
<Text text60 margin-s2>
Title (swipe here)
</Text>
<View height={1} bg-grey40/>
<FlatList
showsVerticalScrollIndicator={false}
style={styles.verticalScroll}
data={colors}
renderItem={this.renderVerticalItem}
keyExtractor={this.keyExtractor}
/>
</View>
</PanView>
</Container>
<PanView
directions={[PanView.directions.DOWN]}
dismissible
springBack
// threshold={{y: 10}}
containerStyle={styles.panView}
onDismiss={this.onDialogDismissed}
>
<View style={styles.dialog}>
<Text text60 margin-s2>
Title (swipe here)
</Text>
<View height={1} bg-grey40/>
<FlatList
showsVerticalScrollIndicator={false}
style={styles.verticalScroll}
data={colors}
renderItem={this.renderVerticalItem}
keyExtractor={this.keyExtractor}
/>
</View>
</PanView>
</Modal>
</View>
);
Expand Down
4 changes: 4 additions & 0 deletions generatedTypes/components/modal/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export interface ModalProps extends RNModalProps {
* label is constructed by traversing all the children and accumulating all the Text nodes separated by space.
*/
accessibilityLabel?: string;
/**
* Should add a GestureHandlerRootView (Android only)
*/
useGestureHandlerRootView?: boolean;
}
/**
* @description: Component that present content on top of the invoking screen
Expand Down
24 changes: 17 additions & 7 deletions src/components/modal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import _ from 'lodash';
import React, {Component} from 'react';
import {GestureHandlerRootView} from 'react-native-gesture-handler';
import {
StyleSheet,
Modal as RNModal,
Expand Down Expand Up @@ -42,6 +43,10 @@ export interface ModalProps extends RNModalProps {
* label is constructed by traversing all the children and accumulating all the Text nodes separated by space.
*/
accessibilityLabel?: string;
/**
* Should add a GestureHandlerRootView (Android only)
*/
useGestureHandlerRootView?: boolean;
}

/**
Expand Down Expand Up @@ -81,24 +86,29 @@ class Modal extends Component<ModalProps> {
{/*
// @ts-ignore */}
<TouchableWithoutFeedback {...accessibilityProps} onPress={onBackgroundPress}>
<View style={isScreenReaderEnabled ? styles.accessibleOverlayView : styles.overlayView}/>
<View style={isScreenReaderEnabled ? styles.accessibleOverlayView : styles.fill}/>
</TouchableWithoutFeedback>
</View>
);
}
}

render() {
const {blurView, enableModalBlur, visible, ...others} = this.props;
const {blurView, enableModalBlur, visible, useGestureHandlerRootView, ...others} = this.props;
const defaultContainer = enableModalBlur && Constants.isIOS && BlurView ? BlurView : View;
const useGestureHandler = useGestureHandlerRootView && Constants.isAndroid;
const GestureContainer = useGestureHandler ? GestureHandlerRootView : React.Fragment;
const gestureContainerProps = useGestureHandler ? {style: styles.fill} : {};
const Container: any = blurView ? blurView : defaultContainer;

return (
<RNModal visible={Boolean(visible)} {...others}>
<Container style={{flex: 1}} blurType="light">
{this.renderTouchableOverlay()}
{this.props.children}
</Container>
<GestureContainer {...gestureContainerProps}>
<Container style={styles.fill} blurType="light">
{this.renderTouchableOverlay()}
{this.props.children}
</Container>
</GestureContainer>
</RNModal>
);
}
Expand All @@ -108,7 +118,7 @@ const styles = StyleSheet.create({
touchableOverlay: {
...StyleSheet.absoluteFillObject
},
overlayView: {
fill: {
flex: 1
},
accessibleOverlayView: {
Expand Down