{"ast":null,"code":"import * as React from 'react';\nimport Keyboard from \"react-native-web/dist/exports/Keyboard\";\nimport TextInput from \"react-native-web/dist/exports/TextInput\";\nexport default function useKeyboardManager(isEnabled) {\n var previouslyFocusedTextInputRef = React.useRef(undefined);\n var startTimestampRef = React.useRef(0);\n var keyboardTimeoutRef = React.useRef();\n var clearKeyboardTimeout = React.useCallback(function () {\n if (keyboardTimeoutRef.current !== undefined) {\n clearTimeout(keyboardTimeoutRef.current);\n keyboardTimeoutRef.current = undefined;\n }\n }, []);\n var onPageChangeStart = React.useCallback(function () {\n if (!isEnabled()) {\n return;\n }\n clearKeyboardTimeout();\n var input = TextInput.State.currentlyFocusedInput();\n input === null || input === void 0 ? void 0 : input.blur();\n previouslyFocusedTextInputRef.current = input;\n startTimestampRef.current = Date.now();\n }, [clearKeyboardTimeout, isEnabled]);\n var onPageChangeConfirm = React.useCallback(function (force) {\n if (!isEnabled()) {\n return;\n }\n clearKeyboardTimeout();\n if (force) {\n Keyboard.dismiss();\n } else {\n var input = previouslyFocusedTextInputRef.current;\n input === null || input === void 0 ? void 0 : input.blur();\n }\n previouslyFocusedTextInputRef.current = undefined;\n }, [clearKeyboardTimeout, isEnabled]);\n var onPageChangeCancel = React.useCallback(function () {\n if (!isEnabled()) {\n return;\n }\n clearKeyboardTimeout();\n var input = previouslyFocusedTextInputRef.current;\n if (input) {\n if (Date.now() - startTimestampRef.current < 100) {\n keyboardTimeoutRef.current = setTimeout(function () {\n input === null || input === void 0 ? void 0 : input.focus();\n previouslyFocusedTextInputRef.current = undefined;\n }, 100);\n } else {\n input === null || input === void 0 ? void 0 : input.focus();\n previouslyFocusedTextInputRef.current = undefined;\n }\n }\n }, [clearKeyboardTimeout, isEnabled]);\n React.useEffect(function () {\n return function () {\n return clearKeyboardTimeout();\n };\n }, [clearKeyboardTimeout]);\n return {\n onPageChangeStart: onPageChangeStart,\n onPageChangeConfirm: onPageChangeConfirm,\n onPageChangeCancel: onPageChangeCancel\n };\n}","map":{"version":3,"sources":["useKeyboardManager.tsx"],"names":["React","useKeyboardManager","isEnabled","previouslyFocusedTextInputRef","useRef","undefined","startTimestampRef","keyboardTimeoutRef","clearKeyboardTimeout","useCallback","current","clearTimeout","onPageChangeStart","input","TextInput","State","currentlyFocusedInput","blur","Date","now","onPageChangeConfirm","force","Keyboard","dismiss","onPageChangeCancel","setTimeout","focus","useEffect"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAAA;AAAA;AAK9B,eAAe,SAASC,kBAAkB,CAACC,SAAwB,EAAE;EAGnE,IAAMC,6BAA6B,GAAGH,KAAK,CAACI,MAAM,CAAWC,SAAS,CAAC;EACvE,IAAMC,iBAAiB,GAAGN,KAAK,CAACI,MAAM,CAAS,CAAC,CAAC;EACjD,IAAMG,kBAAkB,GAAGP,KAAK,CAACI,MAAM,EAAO;EAE9C,IAAMI,oBAAoB,GAAGR,KAAK,CAACS,WAAW,CAAC,YAAM;IACnD,IAAIF,kBAAkB,CAACG,OAAO,KAAKL,SAAS,EAAE;MAC5CM,YAAY,CAACJ,kBAAkB,CAACG,OAAO,CAAC;MACxCH,kBAAkB,CAACG,OAAO,GAAGL,SAAS;IACxC;EACF,CAAC,EAAE,EAAE,CAAC;EAEN,IAAMO,iBAAiB,GAAGZ,KAAK,CAACS,WAAW,CAAC,YAAM;IAChD,IAAI,CAACP,SAAS,EAAE,EAAE;MAChB;IACF;IAEAM,oBAAoB,EAAE;IAEtB,IAAMK,KAAe,GAAGC,SAAS,CAACC,KAAK,CAACC,qBAAqB,EAAE;IAG/DH,KAAK,KAAA,IAAA,IAALA,KAAK,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAALA,KAAK,CAAEI,IAAI,EAAE;IAGbd,6BAA6B,CAACO,OAAO,GAAGG,KAAK;IAG7CP,iBAAiB,CAACI,OAAO,GAAGQ,IAAI,CAACC,GAAG,EAAE;EACxC,CAAC,EAAE,CAACX,oBAAoB,EAAEN,SAAS,CAAC,CAAC;EAErC,IA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2B,SAAS,CAAC,YAAM;IACpB,OAAO;MAAA,OAAMnB,oBAAoB,EAAE;IAAA;EACrC,CAAC,EAAE,CAACA,oBAAoB,CAAC,CAAC;EAE1B,OAAO;IACLI,iBAAiB,EAAjBA,iBAAiB;IACjBQ,mBAAmB,EAAnBA,mBAAmB;IACnBI,kBAAAA,EAAAA;EACF,CAAC;AACH","sourceRoot":"../../src","sourcesContent":["import * as React from 'react';\nimport { Keyboard, TextInput } from 'react-native';\nexport default function useKeyboardManager(isEnabled) {\n // Numeric id of the previously focused text input\n // When a gesture didn't change the tab, we can restore the focused input with this\n const previouslyFocusedTextInputRef = React.useRef(undefined);\n const startTimestampRef = React.useRef(0);\n const keyboardTimeoutRef = React.useRef();\n const clearKeyboardTimeout = React.useCallback(() => {\n if (keyboardTimeoutRef.current !== undefined) {\n clearTimeout(keyboardTimeoutRef.current);\n keyboardTimeoutRef.current = undefined;\n }\n }, []);\n const onPageChangeStart = React.useCallback(() => {\n if (!isEnabled()) {\n return;\n }\n clearKeyboardTimeout();\n const input = TextInput.State.currentlyFocusedInput();\n\n // When a page change begins, blur the currently focused input\n input === null || input === void 0 ? void 0 : input.blur();\n\n // Store the id of this input so we can refocus it if change was cancelled\n previouslyFocusedTextInputRef.current = input;\n\n // Store timestamp for touch start\n startTimestampRef.current = Date.now();\n }, [clearKeyboardTimeout, isEnabled]);\n const onPageChangeConfirm = React.useCallback(force => {\n if (!isEnabled()) {\n return;\n }\n clearKeyboardTimeout();\n if (force) {\n // Always dismiss input, even if we don't have a ref to it\n // We might not have the ref if onPageChangeStart was never called\n // This can happen if page change was not from a gesture\n Keyboard.dismiss();\n } else {\n const input = previouslyFocusedTextInputRef.current;\n\n // Dismiss the keyboard only if an input was a focused before\n // This makes sure we don't dismiss input on going back and focusing an input\n input === null || input === void 0 ? void 0 : input.blur();\n }\n\n // Cleanup the ID on successful page change\n previouslyFocusedTextInputRef.current = undefined;\n }, [clearKeyboardTimeout, isEnabled]);\n const onPageChangeCancel = React.useCallback(() => {\n if (!isEnabled()) {\n return;\n }\n clearKeyboardTimeout();\n\n // The page didn't change, we should restore the focus of text input\n const input = previouslyFocusedTextInputRef.current;\n if (input) {\n // If the interaction was super short we should make sure keyboard won't hide again.\n\n // Too fast input refocus will result only in keyboard flashing on screen and hiding right away.\n // During first ~100ms keyboard will be dismissed no matter what,\n // so we have to make sure it won't interrupt input refocus logic.\n // That's why when the interaction is shorter than 100ms we add delay so it won't hide once again.\n // Subtracting timestamps makes us sure the delay is executed only when needed.\n if (Date.now() - startTimestampRef.current < 100) {\n keyboardTimeoutRef.current = setTimeout(() => {\n input === null || input === void 0 ? void 0 : input.focus();\n previouslyFocusedTextInputRef.current = undefined;\n }, 100);\n } else {\n input === null || input === void 0 ? void 0 : input.focus();\n previouslyFocusedTextInputRef.current = undefined;\n }\n }\n }, [clearKeyboardTimeout, isEnabled]);\n React.useEffect(() => {\n return () => clearKeyboardTimeout();\n }, [clearKeyboardTimeout]);\n return {\n onPageChangeStart,\n onPageChangeConfirm,\n onPageChangeCancel\n };\n}\n//# sourceMappingURL=useKeyboardManager.js.map"]},"metadata":{},"sourceType":"module"}