Skip to content

Commit 378f367

Browse files
authored
feat: Remove usage of deprecated function removeListener (#594)
BREAKING CHANGE: From now on, we require `react-native>=0.65` in order to work correctly (because `react-native@0.65` deprecates the `removeListener` API that `react-native-modal` was using before this change).
1 parent 9f085c8 commit 378f367

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
},
8080
"peerDependencies": {
8181
"react": "*",
82-
"react-native": "*"
82+
"react-native": ">=0.65.0"
8383
},
8484
"jest": {
8585
"preset": "react-native"

src/modal.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
Animated,
44
DeviceEventEmitter,
55
Dimensions,
6+
EmitterSubscription,
67
InteractionManager,
78
KeyboardAvoidingView,
89
Modal,
@@ -202,6 +203,7 @@ export class ReactNativeModal extends React.Component<ModalProps, State> {
202203
backdropRef: any;
203204
contentRef: any;
204205
panResponder: OrNull<PanResponderInstance> = null;
206+
didUpdateDimensionsEmitter: OrNull<EmitterSubscription> = null;
205207

206208
interactionHandle: OrNull<number> = null;
207209

@@ -243,7 +245,7 @@ export class ReactNativeModal extends React.Component<ModalProps, State> {
243245
'`<Modal onSwipe="..." />` is deprecated and will be removed starting from 13.0.0. Use `<Modal onSwipeComplete="..." />` instead.',
244246
);
245247
}
246-
DeviceEventEmitter.addListener(
248+
this.didUpdateDimensionsEmitter = DeviceEventEmitter.addListener(
247249
'didUpdateDimensions',
248250
this.handleDimensionsUpdate,
249251
);
@@ -258,10 +260,9 @@ export class ReactNativeModal extends React.Component<ModalProps, State> {
258260
'hardwareBackPress',
259261
this.onBackButtonPress,
260262
);
261-
DeviceEventEmitter.removeListener(
262-
'didUpdateDimensions',
263-
this.handleDimensionsUpdate,
264-
);
263+
if (this.didUpdateDimensionsEmitter) {
264+
this.didUpdateDimensionsEmitter.remove();
265+
}
265266
if (this.interactionHandle) {
266267
InteractionManager.clearInteractionHandle(this.interactionHandle);
267268
this.interactionHandle = null;

0 commit comments

Comments
 (0)