1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = useIsKeyboardShown;
|
7 |
|
8 | var React = _interopRequireWildcard(require("react"));
|
9 |
|
10 | var _reactNative = require("react-native");
|
11 |
|
12 | function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
13 |
|
14 | function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
15 |
|
16 | function useIsKeyboardShown(_ref) {
|
17 | let {
|
18 | onShow,
|
19 | onHide
|
20 | } = _ref;
|
21 | React.useEffect(() => {
|
22 | let willShowSubscription;
|
23 | let willHideSubscription;
|
24 | let didShowSubscription;
|
25 | let didHideSubscription;
|
26 |
|
27 | if (_reactNative.Platform.OS === 'ios') {
|
28 | willShowSubscription = _reactNative.Keyboard.addListener('keyboardWillShow', onShow);
|
29 | willHideSubscription = _reactNative.Keyboard.addListener('keyboardWillHide', onHide);
|
30 | } else {
|
31 | didShowSubscription = _reactNative.Keyboard.addListener('keyboardDidShow', onShow);
|
32 | didHideSubscription = _reactNative.Keyboard.addListener('keyboardDidHide', onHide);
|
33 | }
|
34 |
|
35 | return () => {
|
36 | if (_reactNative.Platform.OS === 'ios') {
|
37 | var _willShowSubscription, _willHideSubscription;
|
38 |
|
39 | if ((_willShowSubscription = willShowSubscription) !== null && _willShowSubscription !== void 0 && _willShowSubscription.remove) {
|
40 | willShowSubscription.remove();
|
41 | } else {
|
42 | _reactNative.Keyboard.removeListener('keyboardWillShow', onShow);
|
43 | }
|
44 |
|
45 | if ((_willHideSubscription = willHideSubscription) !== null && _willHideSubscription !== void 0 && _willHideSubscription.remove) {
|
46 | willHideSubscription.remove();
|
47 | } else {
|
48 | _reactNative.Keyboard.removeListener('keyboardWillHide', onHide);
|
49 | }
|
50 | } else {
|
51 | var _didShowSubscription, _didHideSubscription;
|
52 |
|
53 | if ((_didShowSubscription = didShowSubscription) !== null && _didShowSubscription !== void 0 && _didShowSubscription.remove) {
|
54 | didShowSubscription.remove();
|
55 | } else {
|
56 | _reactNative.Keyboard.removeListener('keyboardDidShow', onShow);
|
57 | }
|
58 |
|
59 | if ((_didHideSubscription = didHideSubscription) !== null && _didHideSubscription !== void 0 && _didHideSubscription.remove) {
|
60 | didHideSubscription.remove();
|
61 | } else {
|
62 | _reactNative.Keyboard.removeListener('keyboardDidHide', onHide);
|
63 | }
|
64 | }
|
65 | };
|
66 | }, [onHide, onShow]);
|
67 | }
|
68 |
|
\ | No newline at end of file |