diff --git a/src/Popover.tsx b/src/Popover.tsx index 87a449c..efe6f45 100644 --- a/src/Popover.tsx +++ b/src/Popover.tsx @@ -14,6 +14,7 @@ import { StyleProp, I18nManager, StatusBar, + EmitterSubscription, } from 'react-native'; import { computeGeometry, @@ -94,6 +95,7 @@ export interface PopoverProps { useNativeDriver?: boolean; supportedOrientations?: Orientation[]; calculateStatusBar?: boolean; + children?: React.ReactNode; } export interface PopoverState extends Geometry { @@ -155,6 +157,7 @@ export class Popover extends React.PureComponent { static displayName = 'Popover'; private defaultDisplayArea!: Rect; + private dimensionsSub?: EmitterSubscription; constructor(props: PopoverProps) { super(props); @@ -171,11 +174,14 @@ export class Popover extends React.PureComponent { } componentDidMount() { - Dimensions.addEventListener('change', this.onOrientationChange); + this.dimensionsSub = Dimensions.addEventListener( + 'change', + this.onOrientationChange, + ); } componentWillUnmount() { - Dimensions.removeEventListener('change', this.onOrientationChange); + this.dimensionsSub?.remove(); } private computeGeometry = ( diff --git a/src/PopoverController.tsx b/src/PopoverController.tsx index a5e6e32..8cdc204 100644 --- a/src/PopoverController.tsx +++ b/src/PopoverController.tsx @@ -7,6 +7,7 @@ import { NativeModules, I18nManager, StatusBar, + EmitterSubscription, } from 'react-native'; import { Rect } from './PopoverGeometry'; @@ -38,12 +39,17 @@ export class PopoverController extends React.PureComponent { popoverAnchor: { x: 0, y: 0, width: 0, height: 0 }, }; + private dimensionsSub?: EmitterSubscription; + componentDidMount() { - Dimensions.addEventListener('change', this.onOrientationChange); + this.dimensionsSub = Dimensions.addEventListener( + 'change', + this.onOrientationChange, + ); } componentWillUnmount() { - Dimensions.removeEventListener('change', this.onOrientationChange); + this.dimensionsSub?.remove(); } private onOrientationChange = () => { diff --git a/src/PopoverTouchable.tsx b/src/PopoverTouchable.tsx index cbb7526..7d7790a 100644 --- a/src/PopoverTouchable.tsx +++ b/src/PopoverTouchable.tsx @@ -5,11 +5,13 @@ import { findNodeHandle, MeasureOnSuccessCallback, NativeModules, + EmitterSubscription, } from 'react-native'; import { Rect } from './PopoverGeometry'; export interface Props { - onPopoverDisplayed?: () => any; + onPopoverDisplayed?: () => unknown; + children?: React.ReactNode; } export interface State { @@ -22,22 +24,28 @@ export class PopoverTouchable extends React.PureComponent { onPopoverDisplayed: PropTypes.func, }; + private dimensionsSub?: EmitterSubscription; + constructor(props: Props) { super(props); this.state = { showPopover: false, popoverAnchor: { x: 0, y: 0, width: 0, height: 0 }, }; - // Not yet - // console.warn('PopoverTouchable is deprecated, please use PopoverController instead'); + console.warn( + 'PopoverTouchable is deprecated, please use PopoverController instead', + ); } componentDidMount() { - Dimensions.addEventListener('change', this.onOrientationChange); + this.dimensionsSub = Dimensions.addEventListener( + 'change', + this.onOrientationChange, + ); } componentWillUnmount() { - Dimensions.removeEventListener('change', this.onOrientationChange); + this.dimensionsSub?.remove(); } private onOrientationChange = () => {