|
4 | 4 | BackHandler,
|
5 | 5 | Easing,
|
6 | 6 | Modal,
|
| 7 | + NativeEventSubscription, |
7 | 8 | Platform,
|
8 | 9 | StyleSheet,
|
9 | 10 | TouchableWithoutFeedback,
|
@@ -38,6 +39,7 @@ const ESCAPE_KEY = 'Escape';
|
38 | 39 | // Has same API as https://facebook.github.io/react-native/docs/actionsheetios.html
|
39 | 40 | export default class CustomActionSheet extends React.Component<Props, State> {
|
40 | 41 | _actionSheetHeight = 360;
|
| 42 | + _backHandlerListener: NativeEventSubscription | undefined; |
41 | 43 |
|
42 | 44 | state: State = {
|
43 | 45 | isVisible: false,
|
@@ -227,8 +229,12 @@ export default class CustomActionSheet extends React.Component<Props, State> {
|
227 | 229 | this._deferAfterAnimation = undefined;
|
228 | 230 | }
|
229 | 231 | });
|
230 |
| - // @ts-ignore: Argument of type '"actionSheetHardwareBackPress"' is not assignable to parameter of type '"hardwareBackPress"' |
231 |
| - BackHandler.addEventListener('actionSheetHardwareBackPress', this._selectCancelButton); |
| 232 | + |
| 233 | + this._backHandlerListener = BackHandler.addEventListener( |
| 234 | + // @ts-ignore: Argument of type '"actionSheetHardwareBackPress"' is not assignable to parameter of type '"hardwareBackPress"' |
| 235 | + 'actionSheetHardwareBackPress', |
| 236 | + this._selectCancelButton |
| 237 | + ); |
232 | 238 | };
|
233 | 239 |
|
234 | 240 | _selectCancelButton = () => {
|
@@ -269,8 +275,9 @@ export default class CustomActionSheet extends React.Component<Props, State> {
|
269 | 275 | return false;
|
270 | 276 | }
|
271 | 277 |
|
272 |
| - // @ts-ignore: Argument of type '"actionSheetHardwareBackPress"' is not assignable to parameter of type '"hardwareBackPress"' |
273 |
| - BackHandler.removeEventListener('actionSheetHardwareBackPress', this._selectCancelButton); |
| 278 | + if (this._backHandlerListener) { |
| 279 | + this._backHandlerListener.remove(); |
| 280 | + } |
274 | 281 | this.setState({
|
275 | 282 | isAnimating: true,
|
276 | 283 | });
|
|
0 commit comments