Skip to content

Commit b41c92f

Browse files
authored
Feat/add IgnoreBackgroundPress prop (#1267)
* Feat/add IgnoreBackgroundPress prop * ignoreBackgroundPress
1 parent cfec109 commit b41c92f

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

demo/src/screens/componentScreens/DialogScreen.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ export default class DialogScreen extends Component {
5555
scroll: this.SCROLL_TYPE.NONE,
5656
showHeader: true,
5757
isRounded: true,
58-
showDialog: false
58+
showDialog: false,
59+
ignoreBackgroundPress: false
5960
};
6061
}
6162

@@ -93,6 +94,12 @@ export default class DialogScreen extends Component {
9394
});
9495
};
9596

97+
toggleIgnoreBackgroundPress = () => {
98+
this.setState({
99+
ignoreBackgroundPress: !this.state.ignoreBackgroundPress
100+
});
101+
};
102+
96103
showDialog = () => {
97104
this.setState({showDialog: true});
98105
};
@@ -222,7 +229,7 @@ Scroll: ${scroll}`;
222229
};
223230

224231
renderDialog = () => {
225-
const {showDialog, panDirection, position, scroll, showHeader, isRounded} = this.state;
232+
const {showDialog, panDirection, position, scroll, showHeader, isRounded, ignoreBackgroundPress} = this.state;
226233
const renderPannableHeader = showHeader ? this.renderPannableHeader : undefined;
227234
const height = scroll !== this.SCROLL_TYPE.NONE ? '70%' : undefined;
228235

@@ -241,14 +248,15 @@ Scroll: ${scroll}`;
241248
renderPannableHeader={renderPannableHeader}
242249
pannableHeaderProps={this.pannableTitle}
243250
supportedOrientations={this.supportedOrientations}
251+
ignoreBackgroundPress={ignoreBackgroundPress}
244252
>
245253
{this.renderContent()}
246254
</Dialog>
247255
);
248256
};
249257

250258
render() {
251-
const {panDirection, position, scroll, showHeader, isRounded} = this.state;
259+
const {panDirection, position, scroll, showHeader, isRounded, ignoreBackgroundPress} = this.state;
252260

253261
return (
254262
<ScrollView>
@@ -296,6 +304,11 @@ Scroll: ${scroll}`;
296304
<Switch value={isRounded} onValueChange={this.toggleIsRounded} marginL-10/>
297305
</View>
298306

307+
<View row marginT-20 centerV>
308+
<Text>Ignore Background Press:</Text>
309+
<Switch value={ignoreBackgroundPress} onValueChange={this.toggleIgnoreBackgroundPress} marginL-10/>
310+
</View>
311+
299312
<Button marginT-50 label={'Show dialog'} onPress={this.showDialog}/>
300313

301314
{this.renderDialog()}

generatedTypes/components/dialog/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export interface DialogProps extends AlignmentModifiers, RNPartialProps {
1313
* Dismiss callback for when clicking on the background
1414
*/
1515
onDismiss?: (props: any) => void;
16+
/**
17+
* Whether or not to ignore background press
18+
*/
19+
ignoreBackgroundPress?: boolean;
1620
/**
1721
* The color of the overlay background
1822
*/

src/components/dialog/index.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ export interface DialogProps extends AlignmentModifiers, RNPartialProps {
3232
* Dismiss callback for when clicking on the background
3333
*/
3434
onDismiss?: (props: any) => void;
35+
/**
36+
* Whether or not to ignore background press
37+
*/
38+
ignoreBackgroundPress?: boolean;
3539
/**
3640
* The color of the overlay background
3741
*/
@@ -274,7 +278,8 @@ class Dialog extends Component<DialogProps, DialogState> {
274278

275279
render = () => {
276280
const {orientationKey, modalVisibility} = this.state;
277-
const {testID, supportedOrientations, accessibilityLabel} = this.props;
281+
const {testID, supportedOrientations, accessibilityLabel, ignoreBackgroundPress} = this.props;
282+
const onBackgroundPress = !ignoreBackgroundPress ? this.hideDialogView : undefined;
278283

279284
return (
280285
<Modal
@@ -283,8 +288,8 @@ class Dialog extends Component<DialogProps, DialogState> {
283288
transparent
284289
visible={modalVisibility}
285290
animationType={'none'}
286-
onBackgroundPress={this.hideDialogView}
287-
onRequestClose={this.hideDialogView}
291+
onBackgroundPress={onBackgroundPress}
292+
onRequestClose={onBackgroundPress}
288293
// onDismiss={this.onModalDismissed}
289294
supportedOrientations={supportedOrientations}
290295
accessibilityLabel={accessibilityLabel}

0 commit comments

Comments
 (0)