Skip to content

Commit 1f70169

Browse files
committed
fix: refactor overlay to prevent its default press
1 parent 427b182 commit 1f70169

11 files changed

Lines changed: 348 additions & 74 deletions

File tree

src/components/Dialog/Dialog.styles.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export interface DialogVariables {
66
body: ViewStyle;
77
container: ViewStyle;
88
modalContainer: ViewStyle;
9-
overlay: ViewStyle & { cursor?: string };
109
}
1110

1211
export const getDialogVariables = (theme: Theme): DialogVariables => {
@@ -30,24 +29,12 @@ export const getDialogVariables = (theme: Theme): DialogVariables => {
3029
justifyContent: 'center',
3130
width: '100%',
3231
},
33-
overlay: {
34-
backgroundColor: theme.colors.background.overlay,
35-
bottom: 0,
36-
cursor: 'auto',
37-
height: '100%',
38-
left: 0,
39-
position: 'absolute',
40-
right: 0,
41-
top: 0,
42-
width: '100%',
43-
},
4432
};
4533
};
4634

4735
export interface DialogStyles {
4836
bodyStyle: ViewStyle;
4937
containerStyle: ViewStyle;
50-
overlayStyle: ViewStyle;
5138
modalContainerStyle: ViewStyle;
5239
}
5340
export type GetDialogStyles = (theme: Theme) => DialogStyles;
@@ -59,6 +46,5 @@ export const getDialogStyles: GetDialogStyles = theme => {
5946
bodyStyle: dialogVariables.body,
6047
containerStyle: dialogVariables.container,
6148
modalContainerStyle: dialogVariables.modalContainer,
62-
overlayStyle: dialogVariables.overlay,
6349
};
6450
};

src/components/Dialog/Dialog.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import * as React from 'react';
2-
import { TouchableWithoutFeedback, View } from 'react-native';
2+
import { View } from 'react-native';
33

44
import { Theme, withTheme } from '../../theme';
55
import { Modal } from '../Modal';
6+
import { Overlay } from '../Overlay';
67
import { GetDialogStyles, getDialogStyles } from './Dialog.styles';
78

89
// TODO: Import from react-native when react-native-web implementation is ready
@@ -30,17 +31,12 @@ const DialogBase = (props: DialogProps) => {
3031
footer,
3132
header,
3233
isVisible,
33-
onClose,
34+
onClose = () => null,
3435
theme,
3536
getStyles = getDialogStyles,
3637
} = props;
3738

38-
const {
39-
modalContainerStyle,
40-
overlayStyle,
41-
containerStyle,
42-
bodyStyle,
43-
} = getStyles(theme);
39+
const { modalContainerStyle, containerStyle, bodyStyle } = getStyles(theme);
4440

4541
return (
4642
<Modal visible={isVisible} transparent onRequestClose={onClose}>
@@ -50,9 +46,7 @@ const DialogBase = (props: DialogProps) => {
5046
<View style={bodyStyle}>{children}</View>
5147
{footer}
5248
</View>
53-
<TouchableWithoutFeedback onPress={onClose}>
54-
<View style={overlayStyle} />
55-
</TouchableWithoutFeedback>
49+
<Overlay onPress={onClose} />
5650
</View>
5751
</Modal>
5852
);

src/components/Drawer/Drawer.styles.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { Theme } from '../../theme/ThemeInterface';
55
export interface DrawerVariables {
66
container: ViewStyle;
77
modalContainer: ViewStyle;
8-
overlay: ViewStyle & { cursor?: string };
98
}
109

1110
export const getDrawerVariables = (theme: Theme): DrawerVariables => {
@@ -22,23 +21,11 @@ export const getDrawerVariables = (theme: Theme): DrawerVariables => {
2221
justifyContent: 'center',
2322
width: '100%',
2423
},
25-
overlay: {
26-
backgroundColor: theme.colors.background.overlay,
27-
bottom: 0,
28-
cursor: 'auto',
29-
height: '100%',
30-
left: 0,
31-
position: 'absolute',
32-
right: 0,
33-
top: 0,
34-
width: '100%',
35-
},
3624
};
3725
};
3826

3927
export interface DrawerStyles {
4028
containerStyle: ViewStyle;
41-
overlayStyle: ViewStyle;
4229
modalContainerStyle: ViewStyle;
4330
}
4431
export type GetDrawerStyles = (theme: Theme) => DrawerStyles;
@@ -49,6 +36,5 @@ export const getDrawerStyles: GetDrawerStyles = theme => {
4936
return {
5037
containerStyle: drawerVariables.container,
5138
modalContainerStyle: drawerVariables.modalContainer,
52-
overlayStyle: drawerVariables.overlay,
5339
};
5440
};

src/components/Drawer/Drawer.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import * as React from 'react';
2-
import { Animated, TouchableWithoutFeedback, View } from 'react-native';
2+
import { Animated, View } from 'react-native';
33

44
import { Theme, withTheme } from '../../theme';
55
import { Modal } from '../Modal';
6+
import { Overlay } from '../Overlay';
67
import { GetDrawerStyles, getDrawerStyles } from './Drawer.styles';
78

89
type Position = 'bottom' | 'top' | 'right' | 'left';
@@ -27,17 +28,15 @@ const DrawerBase = (props: DrawerProps) => {
2728
const {
2829
children,
2930
isVisible,
30-
onClose,
31+
onClose = () => null,
3132
position = 'bottom',
3233
offset = 0,
3334
space,
3435
theme,
3536
getStyles = getDrawerStyles,
3637
} = props;
3738

38-
const { modalContainerStyle, overlayStyle, containerStyle } = getStyles(
39-
theme,
40-
);
39+
const { modalContainerStyle, containerStyle } = getStyles(theme);
4140

4241
if (!isVisible) return null;
4342

@@ -70,9 +69,7 @@ const DrawerBase = (props: DrawerProps) => {
7069
>
7170
{children}
7271
</Animated.View>
73-
<TouchableWithoutFeedback onPress={onClose}>
74-
<View style={overlayStyle} />
75-
</TouchableWithoutFeedback>
72+
<Overlay onPress={onClose} />
7673
</View>
7774
</Modal>
7875
);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { ViewStyle } from 'react-native';
2+
3+
import { Theme } from '../../theme/ThemeInterface';
4+
5+
export interface OverlayVariables {
6+
overlay: ViewStyle & { cursor?: string };
7+
}
8+
9+
export const getOverlayVariables = (theme: Theme): OverlayVariables => {
10+
return {
11+
overlay: {
12+
backgroundColor: 'transparent',
13+
bottom: 0,
14+
cursor: 'auto',
15+
height: '100%',
16+
left: 0,
17+
position: 'absolute',
18+
right: 0,
19+
top: 0,
20+
width: '100%',
21+
},
22+
};
23+
};
24+
25+
export interface OverlayStyles {
26+
overlayStyle: ViewStyle;
27+
}
28+
29+
export type GetOverlayStyles = (theme: Theme) => OverlayStyles;
30+
31+
export const getOverlayStyles: GetOverlayStyles = theme => {
32+
const overlayVariables = getOverlayVariables(theme);
33+
34+
return {
35+
overlayStyle: overlayVariables.overlay,
36+
};
37+
};

src/components/Overlay/Overlay.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import * as React from 'react';
2+
import { TouchableWithoutFeedback, View } from 'react-native';
3+
4+
import { Theme, withTheme } from '../../theme';
5+
import { getOverlayStyles } from './Overlay.styles';
6+
7+
interface OverlayProps {
8+
onPress: () => void;
9+
theme: Theme;
10+
}
11+
12+
const OverlayBase = (props: OverlayProps) => {
13+
const { onPress, theme } = props;
14+
15+
const { overlayStyle } = getOverlayStyles(theme);
16+
return (
17+
<TouchableWithoutFeedback
18+
onPress={event => {
19+
// @ts-ignore
20+
event.preventDefault();
21+
onPress();
22+
}}
23+
>
24+
<View style={overlayStyle} />
25+
</TouchableWithoutFeedback>
26+
);
27+
};
28+
29+
export const Overlay = withTheme(OverlayBase);

src/components/Overlay/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './Overlay';

src/components/Positioner/Positioner.styles.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { Theme } from '../../theme/ThemeInterface';
55
export interface PositionerVariables {
66
positioner: ViewStyle;
77
modalContainer: ViewStyle;
8-
overlay: ViewStyle & { cursor?: string };
98
}
109

1110
export const getPositionerVariables = (theme: Theme): PositionerVariables => {
@@ -17,17 +16,6 @@ export const getPositionerVariables = (theme: Theme): PositionerVariables => {
1716
justifyContent: 'center',
1817
width: '100%',
1918
},
20-
overlay: {
21-
backgroundColor: 'transparent',
22-
bottom: 0,
23-
cursor: 'auto',
24-
height: '100%',
25-
left: 0,
26-
position: 'absolute',
27-
right: 0,
28-
top: 0,
29-
width: '100%',
30-
},
3119
positioner: {
3220
position: 'absolute',
3321
zIndex: 1,
@@ -37,7 +25,6 @@ export const getPositionerVariables = (theme: Theme): PositionerVariables => {
3725

3826
export interface PositionerStyles {
3927
positionerStyle: ViewStyle;
40-
overlayStyle: ViewStyle;
4128
modalContainerStyle: ViewStyle;
4229
}
4330

@@ -48,7 +35,6 @@ export const getPositionerStyles: GetPositionerStyles = theme => {
4835

4936
return {
5037
modalContainerStyle: positionerVariables.modalContainer,
51-
overlayStyle: positionerVariables.overlay,
5238
positionerStyle: positionerVariables.positioner,
5339
};
5440
};

src/components/Positioner/Positioner.tsx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import * as React from 'react';
2-
import {
3-
Dimensions,
4-
ScaledSize,
5-
TouchableWithoutFeedback,
6-
View,
7-
} from 'react-native';
2+
import { Dimensions, ScaledSize, View } from 'react-native';
83

94
import { POSITION, Position } from '../../constants';
105
import { Theme, withTheme } from '../../theme';
116
import { Measurements, ViewMeasure } from '../Helpers';
127
import { Modal } from '../Modal';
8+
import { Overlay } from '../Overlay';
139
import { GetPositionerStyles, getPositionerStyles } from './Positioner.styles';
1410

1511
export interface ContentProps {
@@ -393,9 +389,7 @@ class PositionerBase extends React.Component<PositionerProps, PositionerState> {
393389
isAdjustingContent,
394390
} = this.state;
395391

396-
const { positionerStyle, modalContainerStyle, overlayStyle } = getStyles(
397-
theme,
398-
);
392+
const { positionerStyle, modalContainerStyle } = getStyles(theme);
399393

400394
const screenLayout = Dimensions.get('window');
401395

@@ -477,9 +471,7 @@ class PositionerBase extends React.Component<PositionerProps, PositionerState> {
477471
targetMeasurements: finalTargetMeasurements,
478472
})}
479473
</ViewMeasure>
480-
<TouchableWithoutFeedback onPress={onClose}>
481-
<View style={overlayStyle} />
482-
</TouchableWithoutFeedback>
474+
<Overlay onPress={onClose} />
483475
</View>
484476
</Modal>
485477
</>

src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export * from './FormField';
1111
export * from './Layout';
1212
export * from './Loading';
1313
export * from './Modal';
14+
export * from './Overlay';
1415
export * from './Picker';
1516
export * from './Positioner';
1617
export * from './Popover';

0 commit comments

Comments
 (0)