Skip to content

Commit bd8f3ad

Browse files
chore: support for react-native >= 0.65.x (#16)
* chore: support for react-native >= 0.65.x * chore: removed whitespace on eslint comments
1 parent 890249b commit bd8f3ad

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/index.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable no-unused-vars */
2+
/* eslint-disable no-unused-expressions */
23
import React, { useEffect, useState } from 'react';
34
import { Keyboard } from 'react-native';
45

@@ -22,12 +23,22 @@ export default (config = {}) => {
2223
setVisible(false);
2324
}
2425

25-
Keyboard.addListener(showEvent, onKeyboardShow);
26-
Keyboard.addListener(hideEvent, onKeyboardHide);
26+
if (Keyboard.removeListener) {
27+
Keyboard.addListener(showEvent, onKeyboardShow);
28+
Keyboard.addListener(hideEvent, onKeyboardHide);
29+
30+
return () => {
31+
Keyboard.removeListener(showEvent, onKeyboardShow);
32+
Keyboard.removeListener(hideEvent, onKeyboardHide);
33+
};
34+
}
35+
36+
const showSubscription = Keyboard.addListener(showEvent, onKeyboardShow);
37+
const hideSubscription = Keyboard.addListener(hideEvent, onKeyboardHide);
2738

2839
return () => {
29-
Keyboard.removeListener(showEvent, onKeyboardShow);
30-
Keyboard.removeListener(hideEvent, onKeyboardHide);
40+
showSubscription?.remove();
41+
hideSubscription?.remove();
3142
};
3243
}, [useWillShow, useWillHide]);
3344

0 commit comments

Comments
 (0)