@tamagui/use-keyboard-visible 3.0.0-beta.924.1 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,20 +28,21 @@ var useKeyboardVisible_exports = {};
28
28
  __export(useKeyboardVisible_exports, { useKeyboardVisible: () => useKeyboardVisible });
29
29
  module.exports = __toCommonJS(useKeyboardVisible_exports);
30
30
  var import_react = __toESM(require("react"), 1);
31
- var import_react_native = require("react-native-web");
31
+ const KEYBOARD_MIN_HEIGHT = 150;
32
+ const isKeyboardOpen = () => {
33
+ const viewport = window.visualViewport;
34
+ if (!viewport) return false;
35
+ return document.documentElement.clientHeight - viewport.height > KEYBOARD_MIN_HEIGHT;
36
+ };
32
37
  const useKeyboardVisible = () => {
33
38
  const [isKeyboardVisible, setKeyboardVisible] = import_react.default.useState(false);
34
39
  import_react.default.useEffect(() => {
35
- const keyboardDidShowListener = import_react_native.Keyboard.addListener("keyboardDidShow", () => {
36
- setKeyboardVisible(true);
37
- });
38
- const keyboardDidHideListener = import_react_native.Keyboard.addListener("keyboardDidHide", () => {
39
- setKeyboardVisible(false);
40
- });
41
- return () => {
42
- keyboardDidHideListener.remove();
43
- keyboardDidShowListener.remove();
44
- };
40
+ const viewport = window.visualViewport;
41
+ if (!viewport) return;
42
+ const update = () => setKeyboardVisible(isKeyboardOpen());
43
+ update();
44
+ viewport.addEventListener("resize", update);
45
+ return () => viewport.removeEventListener("resize", update);
45
46
  }, []);
46
47
  return isKeyboardVisible;
47
48
  };
@@ -26,9 +26,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  enumerable: true
27
27
  }) : target, mod));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var useKeyboardVisible_exports = {};
30
- __export(useKeyboardVisible_exports, { useKeyboardVisible: () => useKeyboardVisible });
31
- module.exports = __toCommonJS(useKeyboardVisible_exports);
29
+ var useKeyboardVisible_native_exports = {};
30
+ __export(useKeyboardVisible_native_exports, { useKeyboardVisible: () => useKeyboardVisible });
31
+ module.exports = __toCommonJS(useKeyboardVisible_native_exports);
32
32
  var import_react = __toESM(require("react"), 1);
33
33
  var import_react_native = require("react-native");
34
34
  var useKeyboardVisible = function() {
@@ -26,9 +26,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  enumerable: true
27
27
  }) : target, mod));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var useKeyboardVisible_exports = {};
30
- __export(useKeyboardVisible_exports, { useKeyboardVisible: () => useKeyboardVisible });
31
- module.exports = __toCommonJS(useKeyboardVisible_exports);
29
+ var useKeyboardVisible_native_exports = {};
30
+ __export(useKeyboardVisible_native_exports, { useKeyboardVisible: () => useKeyboardVisible });
31
+ module.exports = __toCommonJS(useKeyboardVisible_native_exports);
32
32
  var import_react = __toESM(require("react"), 1);
33
33
  var import_react_native = require("react-native");
34
34
  var useKeyboardVisible = function() {
@@ -1 +1 @@
1
- {"version":3,"file":"useKeyboardVisible.native.js","names":[],"sources":["cjs/useKeyboardVisible.native.js"],"sourcesContent":["\"use strict\";\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar useKeyboardVisible_exports = {};\n__export(useKeyboardVisible_exports, {\n useKeyboardVisible: () => useKeyboardVisible\n});\nmodule.exports = __toCommonJS(useKeyboardVisible_exports);\nvar import_react = __toESM(require(\"react\"), 1);\nvar import_react_native = require(\"react-native\");\nvar useKeyboardVisible = function() {\n var [isKeyboardVisible, setKeyboardVisible] = import_react.default.useState(false);\n import_react.default.useEffect(function() {\n var keyboardDidShowListener = import_react_native.Keyboard.addListener(\"keyboardDidShow\", function() {\n setKeyboardVisible(true);\n });\n var keyboardDidHideListener = import_react_native.Keyboard.addListener(\"keyboardDidHide\", function() {\n setKeyboardVisible(false);\n });\n return function() {\n keyboardDidHideListener.remove();\n keyboardDidShowListener.remove();\n };\n }, []);\n return isKeyboardVisible;\n};\n//# sourceMappingURL=useKeyboardVisible.js.map\n"],"mappings":";;;AACA,IAAI,WAAW,OAAO;AACtB,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO;AAC1B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YAAY,QAAQ,QAAQ;CAC9B,KAAK,IAAI,QAAQ,KACf,UAAU,QAAQ,MAAM;EAAE,KAAK,IAAI;EAAO,YAAY;CAAK,CAAC;AAChE;AACA,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC5C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;EAClE,KAAK,IAAI,OAAO,kBAAkB,IAAI,GACpC,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QACzC,UAAU,IAAI,KAAK;GAAE,WAAW,KAAK;GAAM,YAAY,EAAE,OAAO,iBAAiB,MAAM,GAAG,MAAM,KAAK;EAAW,CAAC;CACvH;CACA,OAAO;AACT;AACA,IAAI,WAAW,KAAK,YAAY,YAAY,SAAS,OAAO,OAAO,SAAS,aAAa,GAAG,CAAC,IAAI,CAAC,GAAG,YAKnG,cAAc,CAAC,OAAO,CAAC,IAAI,aAAa,UAAU,QAAQ,WAAW;CAAE,OAAO;CAAK,YAAY;AAAK,CAAC,IAAI,QACzG,GACF;AACA,IAAI,gBAAgB,QAAQ,YAAY,UAAU,CAAC,GAAG,cAAc,EAAE,OAAO,KAAK,CAAC,GAAG,GAAG;AACzF,IAAI,6BAA6B,CAAC;AAClC,SAAS,4BAA4B,EACnC,0BAA0B,mBAC5B,CAAC;AACD,OAAO,UAAU,aAAa,0BAA0B;AACxD,IAAI,eAAe,QAAQ,QAAQ,OAAO,GAAG,CAAC;AAC9C,IAAI,sBAAsB,QAAQ,cAAc;AAChD,IAAI,qBAAqB,WAAW;CAClC,IAAI,CAAC,mBAAmB,sBAAsB,aAAa,QAAQ,SAAS,KAAK;CACjF,aAAa,QAAQ,UAAU,WAAW;EACxC,IAAI,0BAA0B,oBAAoB,SAAS,YAAY,mBAAmB,WAAW;GACnG,mBAAmB,IAAI;EACzB,CAAC;EACD,IAAI,0BAA0B,oBAAoB,SAAS,YAAY,mBAAmB,WAAW;GACnG,mBAAmB,KAAK;EAC1B,CAAC;EACD,OAAO,WAAW;GAChB,wBAAwB,OAAO;GAC/B,wBAAwB,OAAO;EACjC;CACF,GAAG,CAAC,CAAC;CACL,OAAO;AACT"}
1
+ {"version":3,"file":"useKeyboardVisible.native.js","names":[],"sources":["cjs/useKeyboardVisible.native.js"],"sourcesContent":["\"use strict\";\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar useKeyboardVisible_native_exports = {};\n__export(useKeyboardVisible_native_exports, {\n useKeyboardVisible: () => useKeyboardVisible\n});\nmodule.exports = __toCommonJS(useKeyboardVisible_native_exports);\nvar import_react = __toESM(require(\"react\"), 1);\nvar import_react_native = require(\"react-native\");\nvar useKeyboardVisible = function() {\n var [isKeyboardVisible, setKeyboardVisible] = import_react.default.useState(false);\n import_react.default.useEffect(function() {\n var keyboardDidShowListener = import_react_native.Keyboard.addListener(\"keyboardDidShow\", function() {\n setKeyboardVisible(true);\n });\n var keyboardDidHideListener = import_react_native.Keyboard.addListener(\"keyboardDidHide\", function() {\n setKeyboardVisible(false);\n });\n return function() {\n keyboardDidHideListener.remove();\n keyboardDidShowListener.remove();\n };\n }, []);\n return isKeyboardVisible;\n};\n//# sourceMappingURL=useKeyboardVisible.native.js.map\n"],"mappings":";;;AACA,IAAI,WAAW,OAAO;AACtB,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO;AAC1B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YAAY,QAAQ,QAAQ;CAC9B,KAAK,IAAI,QAAQ,KACf,UAAU,QAAQ,MAAM;EAAE,KAAK,IAAI;EAAO,YAAY;CAAK,CAAC;AAChE;AACA,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC5C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;EAClE,KAAK,IAAI,OAAO,kBAAkB,IAAI,GACpC,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QACzC,UAAU,IAAI,KAAK;GAAE,WAAW,KAAK;GAAM,YAAY,EAAE,OAAO,iBAAiB,MAAM,GAAG,MAAM,KAAK;EAAW,CAAC;CACvH;CACA,OAAO;AACT;AACA,IAAI,WAAW,KAAK,YAAY,YAAY,SAAS,OAAO,OAAO,SAAS,aAAa,GAAG,CAAC,IAAI,CAAC,GAAG,YAKnG,cAAc,CAAC,OAAO,CAAC,IAAI,aAAa,UAAU,QAAQ,WAAW;CAAE,OAAO;CAAK,YAAY;AAAK,CAAC,IAAI,QACzG,GACF;AACA,IAAI,gBAAgB,QAAQ,YAAY,UAAU,CAAC,GAAG,cAAc,EAAE,OAAO,KAAK,CAAC,GAAG,GAAG;AACzF,IAAI,oCAAoC,CAAC;AACzC,SAAS,mCAAmC,EAC1C,0BAA0B,mBAC5B,CAAC;AACD,OAAO,UAAU,aAAa,iCAAiC;AAC/D,IAAI,eAAe,QAAQ,QAAQ,OAAO,GAAG,CAAC;AAC9C,IAAI,sBAAsB,QAAQ,cAAc;AAChD,IAAI,qBAAqB,WAAW;CAClC,IAAI,CAAC,mBAAmB,sBAAsB,aAAa,QAAQ,SAAS,KAAK;CACjF,aAAa,QAAQ,UAAU,WAAW;EACxC,IAAI,0BAA0B,oBAAoB,SAAS,YAAY,mBAAmB,WAAW;GACnG,mBAAmB,IAAI;EACzB,CAAC;EACD,IAAI,0BAA0B,oBAAoB,SAAS,YAAY,mBAAmB,WAAW;GACnG,mBAAmB,KAAK;EAC1B,CAAC;EACD,OAAO,WAAW;GAChB,wBAAwB,OAAO;GAC/B,wBAAwB,OAAO;EACjC;CACF,GAAG,CAAC,CAAC;CACL,OAAO;AACT"}
@@ -1,19 +1,20 @@
1
1
  import React from "react";
2
- import { Keyboard } from "react-native-web";
3
2
 
3
+ const KEYBOARD_MIN_HEIGHT = 150;
4
+ const isKeyboardOpen = () => {
5
+ const viewport = window.visualViewport;
6
+ if (!viewport) return false;
7
+ return document.documentElement.clientHeight - viewport.height > KEYBOARD_MIN_HEIGHT;
8
+ };
4
9
  const useKeyboardVisible = () => {
5
10
  const [isKeyboardVisible, setKeyboardVisible] = React.useState(false);
6
11
  React.useEffect(() => {
7
- const keyboardDidShowListener = Keyboard.addListener("keyboardDidShow", () => {
8
- setKeyboardVisible(true);
9
- });
10
- const keyboardDidHideListener = Keyboard.addListener("keyboardDidHide", () => {
11
- setKeyboardVisible(false);
12
- });
13
- return () => {
14
- keyboardDidHideListener.remove();
15
- keyboardDidShowListener.remove();
16
- };
12
+ const viewport = window.visualViewport;
13
+ if (!viewport) return;
14
+ const update = () => setKeyboardVisible(isKeyboardOpen());
15
+ update();
16
+ viewport.addEventListener("resize", update);
17
+ return () => viewport.removeEventListener("resize", update);
17
18
  }, []);
18
19
  return isKeyboardVisible;
19
20
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useKeyboardVisible.js","names":[],"sources":["esm/useKeyboardVisible.js"],"sourcesContent":["import React from \"react\";\nimport { Keyboard } from \"react-native-web\";\nconst useKeyboardVisible = () => {\n const [isKeyboardVisible, setKeyboardVisible] = React.useState(false);\n React.useEffect(() => {\n const keyboardDidShowListener = Keyboard.addListener(\"keyboardDidShow\", () => {\n setKeyboardVisible(true);\n });\n const keyboardDidHideListener = Keyboard.addListener(\"keyboardDidHide\", () => {\n setKeyboardVisible(false);\n });\n return () => {\n keyboardDidHideListener.remove();\n keyboardDidShowListener.remove();\n };\n }, []);\n return isKeyboardVisible;\n};\nexport {\n useKeyboardVisible\n};\n//# sourceMappingURL=useKeyboardVisible.js.map\n"],"mappings":";;;;AAEA,MAAM,2BAA2B;CAC/B,MAAM,CAAC,mBAAmB,sBAAsB,MAAM,SAAS,KAAK;CACpE,MAAM,gBAAgB;EACpB,MAAM,0BAA0B,SAAS,YAAY,yBAAyB;GAC5E,mBAAmB,IAAI;EACzB,CAAC;EACD,MAAM,0BAA0B,SAAS,YAAY,yBAAyB;GAC5E,mBAAmB,KAAK;EAC1B,CAAC;EACD,aAAa;GACX,wBAAwB,OAAO;GAC/B,wBAAwB,OAAO;EACjC;CACF,GAAG,CAAC,CAAC;CACL,OAAO;AACT"}
1
+ {"version":3,"file":"useKeyboardVisible.js","names":[],"sources":["esm/useKeyboardVisible.js"],"sourcesContent":["import React from \"react\";\nconst KEYBOARD_MIN_HEIGHT = 150;\nconst isKeyboardOpen = () => {\n const viewport = window.visualViewport;\n if (!viewport) return false;\n return document.documentElement.clientHeight - viewport.height > KEYBOARD_MIN_HEIGHT;\n};\nconst useKeyboardVisible = () => {\n const [isKeyboardVisible, setKeyboardVisible] = React.useState(false);\n React.useEffect(() => {\n const viewport = window.visualViewport;\n if (!viewport) return;\n const update = () => setKeyboardVisible(isKeyboardOpen());\n update();\n viewport.addEventListener(\"resize\", update);\n return () => viewport.removeEventListener(\"resize\", update);\n }, []);\n return isKeyboardVisible;\n};\nexport {\n useKeyboardVisible\n};\n//# sourceMappingURL=useKeyboardVisible.js.map\n"],"mappings":";;;AACA,MAAM,sBAAsB;AAC5B,MAAM,uBAAuB;CAC3B,MAAM,WAAW,OAAO;CACxB,IAAI,CAAC,UAAU,OAAO;CACtB,OAAO,SAAS,gBAAgB,eAAe,SAAS,SAAS;AACnE;AACA,MAAM,2BAA2B;CAC/B,MAAM,CAAC,mBAAmB,sBAAsB,MAAM,SAAS,KAAK;CACpE,MAAM,gBAAgB;EACpB,MAAM,WAAW,OAAO;EACxB,IAAI,CAAC,UAAU;EACf,MAAM,eAAe,mBAAmB,eAAe,CAAC;EACxD,OAAO;EACP,SAAS,iBAAiB,UAAU,MAAM;EAC1C,aAAa,SAAS,oBAAoB,UAAU,MAAM;CAC5D,GAAG,CAAC,CAAC;CACL,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"useKeyboardVisible.native.js","names":[],"sources":["esm/useKeyboardVisible.native.js"],"sourcesContent":["import React from \"react\";\nimport { Keyboard } from \"react-native\";\nvar useKeyboardVisible = function() {\n var [isKeyboardVisible, setKeyboardVisible] = React.useState(false);\n React.useEffect(function() {\n var keyboardDidShowListener = Keyboard.addListener(\"keyboardDidShow\", function() {\n setKeyboardVisible(true);\n });\n var keyboardDidHideListener = Keyboard.addListener(\"keyboardDidHide\", function() {\n setKeyboardVisible(false);\n });\n return function() {\n keyboardDidHideListener.remove();\n keyboardDidShowListener.remove();\n };\n }, []);\n return isKeyboardVisible;\n};\nexport {\n useKeyboardVisible\n};\n//# sourceMappingURL=useKeyboardVisible.js.map\n"],"mappings":";;;;AAEA,IAAI,qBAAqB,WAAW;CAClC,IAAI,CAAC,mBAAmB,sBAAsB,MAAM,SAAS,KAAK;CAClE,MAAM,UAAU,WAAW;EACzB,IAAI,0BAA0B,SAAS,YAAY,mBAAmB,WAAW;GAC/E,mBAAmB,IAAI;EACzB,CAAC;EACD,IAAI,0BAA0B,SAAS,YAAY,mBAAmB,WAAW;GAC/E,mBAAmB,KAAK;EAC1B,CAAC;EACD,OAAO,WAAW;GAChB,wBAAwB,OAAO;GAC/B,wBAAwB,OAAO;EACjC;CACF,GAAG,CAAC,CAAC;CACL,OAAO;AACT"}
1
+ {"version":3,"file":"useKeyboardVisible.native.js","names":[],"sources":["esm/useKeyboardVisible.native.js"],"sourcesContent":["import React from \"react\";\nimport { Keyboard } from \"react-native\";\nvar useKeyboardVisible = function() {\n var [isKeyboardVisible, setKeyboardVisible] = React.useState(false);\n React.useEffect(function() {\n var keyboardDidShowListener = Keyboard.addListener(\"keyboardDidShow\", function() {\n setKeyboardVisible(true);\n });\n var keyboardDidHideListener = Keyboard.addListener(\"keyboardDidHide\", function() {\n setKeyboardVisible(false);\n });\n return function() {\n keyboardDidHideListener.remove();\n keyboardDidShowListener.remove();\n };\n }, []);\n return isKeyboardVisible;\n};\nexport {\n useKeyboardVisible\n};\n//# sourceMappingURL=useKeyboardVisible.native.js.map\n"],"mappings":";;;;AAEA,IAAI,qBAAqB,WAAW;CAClC,IAAI,CAAC,mBAAmB,sBAAsB,MAAM,SAAS,KAAK;CAClE,MAAM,UAAU,WAAW;EACzB,IAAI,0BAA0B,SAAS,YAAY,mBAAmB,WAAW;GAC/E,mBAAmB,IAAI;EACzB,CAAC;EACD,IAAI,0BAA0B,SAAS,YAAY,mBAAmB,WAAW;GAC/E,mBAAmB,KAAK;EAC1B,CAAC;EACD,OAAO,WAAW;GAChB,wBAAwB,OAAO;GAC/B,wBAAwB,OAAO;EACjC;CACF,GAAG,CAAC,CAAC;CACL,OAAO;AACT"}
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@tamagui/use-keyboard-visible",
3
- "version": "3.0.0-beta.924.1",
3
+ "version": "3.0.1",
4
+ "license": "MIT",
4
5
  "gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14",
5
6
  "files": [
6
7
  "src",
@@ -34,9 +35,9 @@
34
35
  "clean:build": "tamagui-build clean:build"
35
36
  },
36
37
  "devDependencies": {
37
- "@tamagui/build": "3.0.0-beta.924.1",
38
+ "@tamagui/build": "3.0.1",
38
39
  "react": "19.2.3",
39
- "react-native": "0.86.2"
40
+ "react-native": "0.87.1"
40
41
  },
41
42
  "peerDependencies": {
42
43
  "react": ">=19",
@@ -46,5 +47,6 @@
46
47
  "type": "git",
47
48
  "url": "git+https://github.com/tamagui/tamagui.git",
48
49
  "directory": "code/core/use-keyboard-visible"
49
- }
50
+ },
51
+ "releaseSourceCommit": "c156b7cc55e5a6cc5883ebc8189720850ac32dbd"
50
52
  }
@@ -0,0 +1,22 @@
1
+ import React from 'react'
2
+ import { Keyboard } from 'react-native'
3
+
4
+ export const useKeyboardVisible = (): boolean => {
5
+ const [isKeyboardVisible, setKeyboardVisible] = React.useState(false)
6
+
7
+ React.useEffect(() => {
8
+ const keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', () => {
9
+ setKeyboardVisible(true)
10
+ })
11
+ const keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', () => {
12
+ setKeyboardVisible(false)
13
+ })
14
+
15
+ return () => {
16
+ keyboardDidHideListener.remove()
17
+ keyboardDidShowListener.remove()
18
+ }
19
+ }, [])
20
+
21
+ return isKeyboardVisible
22
+ }
@@ -1,21 +1,34 @@
1
1
  import React from 'react'
2
- import { Keyboard } from 'react-native'
2
+
3
+ /**
4
+ * On mobile web the soft keyboard is not an event, it is a shrunken visual
5
+ * viewport: the layout viewport stays put and `visualViewport.height` drops by
6
+ * the height of the keyboard. Anything smaller than that is a scroll or a
7
+ * pinch, hence the threshold.
8
+ *
9
+ * Desktop browsers never shrink it, so this stays false there, which is what
10
+ * the react-native version reported on web before this file existed.
11
+ */
12
+ const KEYBOARD_MIN_HEIGHT = 150
13
+
14
+ const isKeyboardOpen = () => {
15
+ const viewport = window.visualViewport
16
+ if (!viewport) return false
17
+ return document.documentElement.clientHeight - viewport.height > KEYBOARD_MIN_HEIGHT
18
+ }
3
19
 
4
20
  export const useKeyboardVisible = (): boolean => {
5
21
  const [isKeyboardVisible, setKeyboardVisible] = React.useState(false)
6
22
 
7
23
  React.useEffect(() => {
8
- const keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', () => {
9
- setKeyboardVisible(true)
10
- })
11
- const keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', () => {
12
- setKeyboardVisible(false)
13
- })
24
+ const viewport = window.visualViewport
25
+ if (!viewport) return
26
+
27
+ const update = () => setKeyboardVisible(isKeyboardOpen())
28
+ update()
14
29
 
15
- return () => {
16
- keyboardDidHideListener.remove()
17
- keyboardDidShowListener.remove()
18
- }
30
+ viewport.addEventListener('resize', update)
31
+ return () => viewport.removeEventListener('resize', update)
19
32
  }, [])
20
33
 
21
34
  return isKeyboardVisible
@@ -1,11 +1,11 @@
1
1
  {
2
- "mappings": "AAGA,OAAO,cAAM",
2
+ "mappings": "AAmBA,OAAO,cAAM",
3
3
  "names": [],
4
4
  "sources": [
5
5
  "src/useKeyboardVisible.ts"
6
6
  ],
7
7
  "version": 3,
8
8
  "sourcesContent": [
9
- "import React from 'react'\nimport { Keyboard } from 'react-native'\n\nexport const useKeyboardVisible = (): boolean => {\n const [isKeyboardVisible, setKeyboardVisible] = React.useState(false)\n\n React.useEffect(() => {\n const keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', () => {\n setKeyboardVisible(true)\n })\n const keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', () => {\n setKeyboardVisible(false)\n })\n\n return () => {\n keyboardDidHideListener.remove()\n keyboardDidShowListener.remove()\n }\n }, [])\n\n return isKeyboardVisible\n}\n"
9
+ "import React from 'react'\n\n/**\n * On mobile web the soft keyboard is not an event, it is a shrunken visual\n * viewport: the layout viewport stays put and `visualViewport.height` drops by\n * the height of the keyboard. Anything smaller than that is a scroll or a\n * pinch, hence the threshold.\n *\n * Desktop browsers never shrink it, so this stays false there, which is what\n * the react-native version reported on web before this file existed.\n */\nconst KEYBOARD_MIN_HEIGHT = 150\n\nconst isKeyboardOpen = () => {\n const viewport = window.visualViewport\n if (!viewport) return false\n return document.documentElement.clientHeight - viewport.height > KEYBOARD_MIN_HEIGHT\n}\n\nexport const useKeyboardVisible = (): boolean => {\n const [isKeyboardVisible, setKeyboardVisible] = React.useState(false)\n\n React.useEffect(() => {\n const viewport = window.visualViewport\n if (!viewport) return\n\n const update = () => setKeyboardVisible(isKeyboardOpen())\n update()\n\n viewport.addEventListener('resize', update)\n return () => viewport.removeEventListener('resize', update)\n }, [])\n\n return isKeyboardVisible\n}\n"
10
10
  ]
11
11
  }
@@ -0,0 +1,3 @@
1
+ export declare const useKeyboardVisible: () => boolean;
2
+
3
+ //# sourceMappingURL=useKeyboardVisible.native.d.ts.map
@@ -0,0 +1,11 @@
1
+ {
2
+ "mappings": "AAGA,OAAO,cAAM",
3
+ "names": [],
4
+ "sources": [
5
+ "src/useKeyboardVisible.native.ts"
6
+ ],
7
+ "version": 3,
8
+ "sourcesContent": [
9
+ "import React from 'react'\nimport { Keyboard } from 'react-native'\n\nexport const useKeyboardVisible = (): boolean => {\n const [isKeyboardVisible, setKeyboardVisible] = React.useState(false)\n\n React.useEffect(() => {\n const keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', () => {\n setKeyboardVisible(true)\n })\n const keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', () => {\n setKeyboardVisible(false)\n })\n\n return () => {\n keyboardDidHideListener.remove()\n keyboardDidShowListener.remove()\n }\n }, [])\n\n return isKeyboardVisible\n}\n"
10
+ ]
11
+ }