Skip to content

Commit ae996ae

Browse files
authored
Fix/dialog key (#1607)
* remove orientation key * formatting
1 parent 951d694 commit ae996ae

File tree

1 file changed

+64
-81
lines changed

1 file changed

+64
-81
lines changed

src/components/dialog/index.tsx

Lines changed: 64 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import _ from 'lodash';
22
import React, {Component} from 'react';
33
import {StyleSheet, StyleProp, ViewStyle, ModalPropsIOS, AccessibilityProps} from 'react-native';
44
import {Colors} from '../../style';
5-
import Constants, {orientations} from '../../helpers/Constants';
5+
import Constants from '../../helpers/Constants';
66
import {AlignmentModifiers, extractAlignmentsValues} from '../../commons/modifiers';
77
import {asBaseComponent} from '../../commons/new';
88
import Modal from '../modal';
@@ -23,67 +23,66 @@ interface RNPartialProps
2323
Pick<AccessibilityProps, 'accessibilityLabel'> {}
2424

2525
export interface DialogProps extends AlignmentModifiers, RNPartialProps {
26-
/**
27-
* Control visibility of the dialog
28-
*/
29-
visible?: boolean;
30-
/**
31-
* Dismiss callback for when clicking on the background
32-
*/
33-
onDismiss?: (props?: any) => void;
34-
/**
35-
* Whether or not to ignore background press
36-
*/
37-
ignoreBackgroundPress?: boolean;
38-
/**
39-
* The color of the overlay background
40-
*/
41-
overlayBackgroundColor?: string;
42-
/**
43-
* The dialog width (default: 90%)
44-
*/
45-
width?: string | number;
46-
/**
47-
* The dialog height (default: undefined)
48-
*/
49-
height?: string | number;
50-
/**
51-
* The direction of the allowed pan (default is DOWN).
52-
* Types: UP, DOWN, LEFT and RIGHT (using PanningProvider.Directions.###).
53-
* Pass null to remove pan.
54-
*/
55-
panDirection?: PanningDirections;
56-
/**
57-
* Whether or not to handle SafeArea
58-
*/
59-
useSafeArea?: boolean;
60-
/**
61-
* Called once the dialog has been dismissed completely
62-
*/
63-
onDialogDismissed?: (props: any) => void;
64-
/**
65-
* If this is added only the header will be pannable;
66-
* this allows for scrollable content (the children of the dialog)
67-
* props are transferred to the renderPannableHeader
68-
*/
69-
renderPannableHeader?: (props: any) => JSX.Element;
70-
/**
71-
* The props that will be passed to the pannable header
72-
*/
73-
pannableHeaderProps?: any;
74-
/**
75-
* The Dialog`s container style
76-
*/
77-
containerStyle?: StyleProp<ViewStyle>;
78-
/**
79-
* Used as a testing identifier
80-
*/
81-
testID?: string;
26+
/**
27+
* Control visibility of the dialog
28+
*/
29+
visible?: boolean;
30+
/**
31+
* Dismiss callback for when clicking on the background
32+
*/
33+
onDismiss?: (props?: any) => void;
34+
/**
35+
* Whether or not to ignore background press
36+
*/
37+
ignoreBackgroundPress?: boolean;
38+
/**
39+
* The color of the overlay background
40+
*/
41+
overlayBackgroundColor?: string;
42+
/**
43+
* The dialog width (default: 90%)
44+
*/
45+
width?: string | number;
46+
/**
47+
* The dialog height (default: undefined)
48+
*/
49+
height?: string | number;
50+
/**
51+
* The direction of the allowed pan (default is DOWN).
52+
* Types: UP, DOWN, LEFT and RIGHT (using PanningProvider.Directions.###).
53+
* Pass null to remove pan.
54+
*/
55+
panDirection?: PanningDirections;
56+
/**
57+
* Whether or not to handle SafeArea
58+
*/
59+
useSafeArea?: boolean;
60+
/**
61+
* Called once the dialog has been dismissed completely
62+
*/
63+
onDialogDismissed?: (props: any) => void;
64+
/**
65+
* If this is added only the header will be pannable;
66+
* this allows for scrollable content (the children of the dialog)
67+
* props are transferred to the renderPannableHeader
68+
*/
69+
renderPannableHeader?: (props: any) => JSX.Element;
70+
/**
71+
* The props that will be passed to the pannable header
72+
*/
73+
pannableHeaderProps?: any;
74+
/**
75+
* The Dialog`s container style
76+
*/
77+
containerStyle?: StyleProp<ViewStyle>;
78+
/**
79+
* Used as a testing identifier
80+
*/
81+
testID?: string;
8282
}
8383

8484
interface DialogState {
8585
alignments: AlignmentModifiers;
86-
orientationKey: orientations;
8786
modalVisibility?: boolean;
8887
dialogVisibility?: boolean;
8988
fadeOut?: boolean;
@@ -113,7 +112,6 @@ class Dialog extends Component<DialogProps, DialogState> {
113112

114113
this.state = {
115114
alignments: extractAlignmentsValues(props),
116-
orientationKey: Constants.orientation,
117115
modalVisibility: props.visible,
118116
dialogVisibility: props.visible
119117
};
@@ -122,14 +120,6 @@ class Dialog extends Component<DialogProps, DialogState> {
122120
this.setAlignment();
123121
}
124122

125-
componentDidMount() {
126-
Constants.addDimensionsEventListener(this.onOrientationChange);
127-
}
128-
129-
componentWillUnmount() {
130-
Constants.removeDimensionsEventListener(this.onOrientationChange);
131-
}
132-
133123
UNSAFE_componentWillReceiveProps(nextProps: DialogProps) {
134124
const {visible: nexVisible} = nextProps;
135125
const {visible} = this.props;
@@ -141,13 +131,6 @@ class Dialog extends Component<DialogProps, DialogState> {
141131
}
142132
}
143133

144-
onOrientationChange = () => {
145-
const orientationKey = Constants.orientation;
146-
if (this.state.orientationKey !== orientationKey) {
147-
this.setState({orientationKey});
148-
}
149-
};
150-
151134
setAlignment() {
152135
const {alignments} = this.state;
153136
if (_.isEmpty(alignments)) {
@@ -160,11 +143,12 @@ class Dialog extends Component<DialogProps, DialogState> {
160143
// TODO: revert adding this workaround once RN fixes https://github.com/facebook/react-native/issues/29455
161144
onFadeDone = () => {
162145
if (!this.state.modalVisibility) {
163-
setTimeout(() => { // unfortunately this is needed if a modal needs to open on iOS
146+
setTimeout(() => {
147+
// unfortunately this is needed if a modal needs to open on iOS
164148
this.props.onDialogDismissed?.(this.props);
165149
}, 100);
166150
}
167-
}
151+
};
168152

169153
_onDismiss = () => {
170154
this.setState({modalVisibility: false, fadeOut: false}, () => {
@@ -177,7 +161,7 @@ class Dialog extends Component<DialogProps, DialogState> {
177161
props.onDialogDismissed?.(props);
178162
}
179163
});
180-
}
164+
};
181165

182166
onDismiss = () => {
183167
const fadeOut = Constants.isIOS && this.props.visible;
@@ -206,7 +190,7 @@ class Dialog extends Component<DialogProps, DialogState> {
206190
return View;
207191
}
208192
return PanListenerView;
209-
}
193+
};
210194

211195
renderDialogView = () => {
212196
const {children, panDirection = PanningProvider.Directions.DOWN, containerStyle, testID} = this.props;
@@ -237,7 +221,7 @@ class Dialog extends Component<DialogProps, DialogState> {
237221
renderDialogContainer = () => {
238222
const {modalVisibility, dialogVisibility, fadeOut} = this.state;
239223
const {useSafeArea, bottom, overlayBackgroundColor, testID} = this.props;
240-
const addBottomSafeArea = Constants.isIphoneX && (useSafeArea && bottom);
224+
const addBottomSafeArea = Constants.isIphoneX && useSafeArea && bottom;
241225
const bottomInsets = Constants.getSafeAreaInsets().bottom - 8; // TODO: should this be here or in the input style?
242226
const onFadeDone = Constants.isIOS ? this.onFadeDone : undefined;
243227

@@ -262,13 +246,12 @@ class Dialog extends Component<DialogProps, DialogState> {
262246
};
263247

264248
render = () => {
265-
const {orientationKey, modalVisibility} = this.state;
249+
const {modalVisibility} = this.state;
266250
const {testID, supportedOrientations, accessibilityLabel, ignoreBackgroundPress} = this.props;
267251
const onBackgroundPress = !ignoreBackgroundPress ? this.hideDialogView : undefined;
268252

269253
return (
270254
<Modal
271-
key={orientationKey}
272255
testID={`${testID}.modal`}
273256
transparent
274257
visible={modalVisibility}

0 commit comments

Comments
 (0)