react-native-keyboard-controller 1.13.2 → 1.13.4

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.
Files changed (60) hide show
  1. package/android/src/main/java/com/reactnativekeyboardcontroller/extensions/EditText.kt +7 -7
  2. package/android/src/main/java/com/reactnativekeyboardcontroller/extensions/ThemedReactContext.kt +2 -2
  3. package/android/src/main/java/com/reactnativekeyboardcontroller/extensions/View.kt +2 -2
  4. package/android/src/main/java/com/reactnativekeyboardcontroller/listeners/KeyboardAnimationCallback.kt +5 -5
  5. package/android/src/main/java/com/reactnativekeyboardcontroller/log/Logger.kt +20 -0
  6. package/android/src/main/java/com/reactnativekeyboardcontroller/modal/ModalAttachedWatcher.kt +2 -2
  7. package/android/src/main/java/com/reactnativekeyboardcontroller/modules/StatusBarManagerCompatModuleImpl.kt +3 -3
  8. package/android/src/main/java/com/reactnativekeyboardcontroller/views/EdgeToEdgeReactViewGroup.kt +2 -2
  9. package/ios/extensions/UIResponder.swift +3 -2
  10. package/ios/extensions/UIView.swift +10 -2
  11. package/ios/observers/KeyboardMovementObserver.swift +11 -8
  12. package/ios/views/KeyboardControllerView.mm +6 -0
  13. package/lib/commonjs/components/KeyboardAvoidingView/hooks.js +4 -3
  14. package/lib/commonjs/components/KeyboardAvoidingView/hooks.js.map +1 -1
  15. package/lib/commonjs/components/KeyboardAvoidingView/index.js +4 -4
  16. package/lib/commonjs/components/KeyboardAvoidingView/index.js.map +1 -1
  17. package/lib/commonjs/components/KeyboardAwareScrollView/index.js +4 -4
  18. package/lib/commonjs/components/KeyboardAwareScrollView/index.js.map +1 -1
  19. package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +2 -2
  20. package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -1
  21. package/lib/commonjs/components/KeyboardStickyView/index.js +2 -2
  22. package/lib/commonjs/components/KeyboardStickyView/index.js.map +1 -1
  23. package/lib/commonjs/components/KeyboardToolbar/index.js +3 -3
  24. package/lib/commonjs/components/KeyboardToolbar/index.js.map +1 -1
  25. package/lib/commonjs/hooks/index.js +2 -4
  26. package/lib/commonjs/hooks/index.js.map +1 -1
  27. package/lib/commonjs/internal.js +24 -12
  28. package/lib/commonjs/internal.js.map +1 -1
  29. package/lib/module/components/KeyboardAvoidingView/hooks.js +2 -1
  30. package/lib/module/components/KeyboardAvoidingView/hooks.js.map +1 -1
  31. package/lib/module/components/KeyboardAvoidingView/index.js +1 -1
  32. package/lib/module/components/KeyboardAvoidingView/index.js.map +1 -1
  33. package/lib/module/components/KeyboardAwareScrollView/index.js +1 -1
  34. package/lib/module/components/KeyboardAwareScrollView/index.js.map +1 -1
  35. package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +1 -1
  36. package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -1
  37. package/lib/module/components/KeyboardStickyView/index.js +1 -1
  38. package/lib/module/components/KeyboardStickyView/index.js.map +1 -1
  39. package/lib/module/components/KeyboardToolbar/index.js +2 -2
  40. package/lib/module/components/KeyboardToolbar/index.js.map +1 -1
  41. package/lib/module/hooks/index.js +3 -4
  42. package/lib/module/hooks/index.js.map +1 -1
  43. package/lib/module/internal.js +24 -12
  44. package/lib/module/internal.js.map +1 -1
  45. package/lib/typescript/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.d.ts +1 -1
  46. package/package.json +1 -1
  47. package/src/components/KeyboardAvoidingView/hooks.ts +2 -4
  48. package/src/components/KeyboardAvoidingView/index.tsx +1 -1
  49. package/src/components/KeyboardAwareScrollView/index.tsx +1 -1
  50. package/src/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.ts +1 -1
  51. package/src/components/KeyboardStickyView/index.tsx +1 -1
  52. package/src/components/KeyboardToolbar/index.tsx +2 -6
  53. package/src/hooks/index.ts +3 -5
  54. package/src/internal.ts +34 -15
  55. package/lib/commonjs/hooks/useSyncEffect/index.js +0 -37
  56. package/lib/commonjs/hooks/useSyncEffect/index.js.map +0 -1
  57. package/lib/module/hooks/useSyncEffect/index.js +0 -31
  58. package/lib/module/hooks/useSyncEffect/index.js.map +0 -1
  59. package/lib/typescript/hooks/useSyncEffect/index.d.ts +0 -14
  60. package/src/hooks/useSyncEffect/index.ts +0 -36
@@ -1,7 +1,7 @@
1
1
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
2
  import React, { forwardRef, useMemo } from "react";
3
3
  import Reanimated, { interpolate, useAnimatedStyle } from "react-native-reanimated";
4
- import { useReanimatedKeyboardAnimation } from "react-native-keyboard-controller";
4
+ import { useReanimatedKeyboardAnimation } from "../../hooks";
5
5
  const KeyboardStickyView = /*#__PURE__*/forwardRef(({
6
6
  children,
7
7
  offset: {
@@ -1 +1 @@
1
- {"version":3,"names":["React","forwardRef","useMemo","Reanimated","interpolate","useAnimatedStyle","useReanimatedKeyboardAnimation","KeyboardStickyView","children","offset","closed","opened","style","props","ref","height","progress","stickyViewStyle","value","transform","translateY","styles","createElement","View","_extends"],"sources":["index.tsx"],"sourcesContent":["import React, { forwardRef, useMemo } from \"react\";\nimport Reanimated, {\n interpolate,\n useAnimatedStyle,\n} from \"react-native-reanimated\";\n\nimport { useReanimatedKeyboardAnimation } from \"react-native-keyboard-controller\";\n\nimport type { View, ViewProps } from \"react-native\";\n\nexport type KeyboardStickyViewProps = {\n /**\n * Specify additional offset to the view for given keyboard state.\n */\n offset?: {\n /**\n * Adds additional `translateY` when keyboard is close. By default `0`.\n */\n closed?: number;\n /**\n * Adds additional `translateY` when keyboard is open. By default `0`.\n */\n opened?: number;\n };\n} & ViewProps;\n\nconst KeyboardStickyView = forwardRef<\n View,\n React.PropsWithChildren<KeyboardStickyViewProps>\n>(\n (\n { children, offset: { closed = 0, opened = 0 } = {}, style, ...props },\n ref,\n ) => {\n const { height, progress } = useReanimatedKeyboardAnimation();\n\n const stickyViewStyle = useAnimatedStyle(() => {\n const offset = interpolate(progress.value, [0, 1], [closed, opened]);\n\n return {\n transform: [{ translateY: height.value + offset }],\n };\n }, [closed, opened]);\n\n const styles = useMemo(\n () => [style, stickyViewStyle],\n [style, stickyViewStyle],\n );\n\n return (\n <Reanimated.View ref={ref} style={styles} {...props}>\n {children}\n </Reanimated.View>\n );\n },\n);\n\nexport default KeyboardStickyView;\n"],"mappings":";AAAA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,OAAO,QAAQ,OAAO;AAClD,OAAOC,UAAU,IACfC,WAAW,EACXC,gBAAgB,QACX,yBAAyB;AAEhC,SAASC,8BAA8B,QAAQ,kCAAkC;AAoBjF,MAAMC,kBAAkB,gBAAGN,UAAU,CAInC,CACE;EAAEO,QAAQ;EAAEC,MAAM,EAAE;IAAEC,MAAM,GAAG,CAAC;IAAEC,MAAM,GAAG;EAAE,CAAC,GAAG,CAAC,CAAC;EAAEC,KAAK;EAAE,GAAGC;AAAM,CAAC,EACtEC,GAAG,KACA;EACH,MAAM;IAAEC,MAAM;IAAEC;EAAS,CAAC,GAAGV,8BAA8B,CAAC,CAAC;EAE7D,MAAMW,eAAe,GAAGZ,gBAAgB,CAAC,MAAM;IAC7C,MAAMI,MAAM,GAAGL,WAAW,CAACY,QAAQ,CAACE,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAACR,MAAM,EAAEC,MAAM,CAAC,CAAC;IAEpE,OAAO;MACLQ,SAAS,EAAE,CAAC;QAAEC,UAAU,EAAEL,MAAM,CAACG,KAAK,GAAGT;MAAO,CAAC;IACnD,CAAC;EACH,CAAC,EAAE,CAACC,MAAM,EAAEC,MAAM,CAAC,CAAC;EAEpB,MAAMU,MAAM,GAAGnB,OAAO,CACpB,MAAM,CAACU,KAAK,EAAEK,eAAe,CAAC,EAC9B,CAACL,KAAK,EAAEK,eAAe,CACzB,CAAC;EAED,oBACEjB,KAAA,CAAAsB,aAAA,CAACnB,UAAU,CAACoB,IAAI,EAAAC,QAAA;IAACV,GAAG,EAAEA,GAAI;IAACF,KAAK,EAAES;EAAO,GAAKR,KAAK,GAChDL,QACc,CAAC;AAEtB,CACF,CAAC;AAED,eAAeD,kBAAkB","ignoreList":[]}
1
+ {"version":3,"names":["React","forwardRef","useMemo","Reanimated","interpolate","useAnimatedStyle","useReanimatedKeyboardAnimation","KeyboardStickyView","children","offset","closed","opened","style","props","ref","height","progress","stickyViewStyle","value","transform","translateY","styles","createElement","View","_extends"],"sources":["index.tsx"],"sourcesContent":["import React, { forwardRef, useMemo } from \"react\";\nimport Reanimated, {\n interpolate,\n useAnimatedStyle,\n} from \"react-native-reanimated\";\n\nimport { useReanimatedKeyboardAnimation } from \"../../hooks\";\n\nimport type { View, ViewProps } from \"react-native\";\n\nexport type KeyboardStickyViewProps = {\n /**\n * Specify additional offset to the view for given keyboard state.\n */\n offset?: {\n /**\n * Adds additional `translateY` when keyboard is close. By default `0`.\n */\n closed?: number;\n /**\n * Adds additional `translateY` when keyboard is open. By default `0`.\n */\n opened?: number;\n };\n} & ViewProps;\n\nconst KeyboardStickyView = forwardRef<\n View,\n React.PropsWithChildren<KeyboardStickyViewProps>\n>(\n (\n { children, offset: { closed = 0, opened = 0 } = {}, style, ...props },\n ref,\n ) => {\n const { height, progress } = useReanimatedKeyboardAnimation();\n\n const stickyViewStyle = useAnimatedStyle(() => {\n const offset = interpolate(progress.value, [0, 1], [closed, opened]);\n\n return {\n transform: [{ translateY: height.value + offset }],\n };\n }, [closed, opened]);\n\n const styles = useMemo(\n () => [style, stickyViewStyle],\n [style, stickyViewStyle],\n );\n\n return (\n <Reanimated.View ref={ref} style={styles} {...props}>\n {children}\n </Reanimated.View>\n );\n },\n);\n\nexport default KeyboardStickyView;\n"],"mappings":";AAAA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,OAAO,QAAQ,OAAO;AAClD,OAAOC,UAAU,IACfC,WAAW,EACXC,gBAAgB,QACX,yBAAyB;AAEhC,SAASC,8BAA8B,QAAQ,aAAa;AAoB5D,MAAMC,kBAAkB,gBAAGN,UAAU,CAInC,CACE;EAAEO,QAAQ;EAAEC,MAAM,EAAE;IAAEC,MAAM,GAAG,CAAC;IAAEC,MAAM,GAAG;EAAE,CAAC,GAAG,CAAC,CAAC;EAAEC,KAAK;EAAE,GAAGC;AAAM,CAAC,EACtEC,GAAG,KACA;EACH,MAAM;IAAEC,MAAM;IAAEC;EAAS,CAAC,GAAGV,8BAA8B,CAAC,CAAC;EAE7D,MAAMW,eAAe,GAAGZ,gBAAgB,CAAC,MAAM;IAC7C,MAAMI,MAAM,GAAGL,WAAW,CAACY,QAAQ,CAACE,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAACR,MAAM,EAAEC,MAAM,CAAC,CAAC;IAEpE,OAAO;MACLQ,SAAS,EAAE,CAAC;QAAEC,UAAU,EAAEL,MAAM,CAACG,KAAK,GAAGT;MAAO,CAAC;IACnD,CAAC;EACH,CAAC,EAAE,CAACC,MAAM,EAAEC,MAAM,CAAC,CAAC;EAEpB,MAAMU,MAAM,GAAGnB,OAAO,CACpB,MAAM,CAACU,KAAK,EAAEK,eAAe,CAAC,EAC9B,CAACL,KAAK,EAAEK,eAAe,CACzB,CAAC;EAED,oBACEjB,KAAA,CAAAsB,aAAA,CAACnB,UAAU,CAACoB,IAAI,EAAAC,QAAA;IAACV,GAAG,EAAEA,GAAI;IAACF,KAAK,EAAES;EAAO,GAAKR,KAAK,GAChDL,QACc,CAAC;AAEtB,CACF,CAAC;AAED,eAAeD,kBAAkB","ignoreList":[]}
@@ -1,8 +1,8 @@
1
1
  import React, { useCallback, useEffect, useMemo, useState } from "react";
2
2
  import { StyleSheet, Text, View } from "react-native";
3
- import { FocusedInputEvents, KeyboardStickyView } from "react-native-keyboard-controller";
4
- import { KeyboardController } from "../../bindings";
3
+ import { FocusedInputEvents, KeyboardController } from "../../bindings";
5
4
  import useColorScheme from "../hooks/useColorScheme";
5
+ import KeyboardStickyView from "../KeyboardStickyView";
6
6
  import Arrow from "./Arrow";
7
7
  import Button from "./Button";
8
8
  import { colors } from "./colors";
@@ -1 +1 @@
1
- {"version":3,"names":["React","useCallback","useEffect","useMemo","useState","StyleSheet","Text","View","FocusedInputEvents","KeyboardStickyView","KeyboardController","useColorScheme","Arrow","Button","colors","TEST_ID_KEYBOARD_TOOLBAR","TEST_ID_KEYBOARD_TOOLBAR_PREVIOUS","TEST_ID_KEYBOARD_TOOLBAR_NEXT","TEST_ID_KEYBOARD_TOOLBAR_CONTENT","TEST_ID_KEYBOARD_TOOLBAR_DONE","KEYBOARD_TOOLBAR_HEIGHT","DEFAULT_OPACITY","offset","closed","dismissKeyboard","dismiss","goToNextField","setFocusTo","goToPrevField","KeyboardToolbar","content","theme","doneText","button","icon","showArrows","onNextCallback","onPrevCallback","onDoneCallback","blur","opacity","colorScheme","inputs","setInputs","current","count","isPrevDisabled","isNextDisabled","subscription","addListener","e","remove","doneStyle","styles","doneButton","color","primary","toolbarStyle","toolbar","backgroundColor","background","ButtonContainer","IconContainer","onPressNext","event","isDefaultPrevented","onPressPrev","onPressDone","createElement","style","testID","Fragment","accessibilityHint","accessibilityLabel","disabled","onPress","type","flex","rippleRadius","doneButtonContainer","maxFontSizeMultiplier","create","position","bottom","alignItems","width","flexDirection","height","paddingHorizontal","fontWeight","fontSize","marginRight","DefaultKeyboardToolbarTheme"],"sources":["index.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useMemo, useState } from \"react\";\nimport { StyleSheet, Text, View } from \"react-native\";\n\nimport {\n FocusedInputEvents,\n KeyboardStickyView,\n} from \"react-native-keyboard-controller\";\n\nimport { KeyboardController } from \"../../bindings\";\nimport useColorScheme from \"../hooks/useColorScheme\";\n\nimport Arrow from \"./Arrow\";\nimport Button from \"./Button\";\nimport { colors } from \"./colors\";\n\nimport type { HEX, KeyboardToolbarTheme } from \"./types\";\nimport type { ReactNode } from \"react\";\nimport type { GestureResponderEvent } from \"react-native\";\n\nexport type KeyboardToolbarProps = {\n /** An element that is shown in the middle of the toolbar. */\n content?: JSX.Element | null;\n /** A set of dark/light colors consumed by toolbar component. */\n theme?: KeyboardToolbarTheme;\n /** Custom text for done button. */\n doneText?: ReactNode;\n /** Custom touchable component for toolbar (used for prev/next/done buttons). */\n button?: typeof Button;\n /** Custom icon component used to display next/prev buttons. */\n icon?: typeof Arrow;\n /**\n * Whether to show next and previous buttons. Can be useful to set it to `false` if you have only one input\n * and want to show only `Done` button. Default to `true`.\n */\n showArrows?: boolean;\n /**\n * A callback that is called when the user presses the next button along with the default action.\n */\n onNextCallback?: (event: GestureResponderEvent) => void;\n /**\n * A callback that is called when the user presses the previous button along with the default action.\n */\n onPrevCallback?: (event: GestureResponderEvent) => void;\n /**\n * A callback that is called when the user presses the done button along with the default action.\n */\n onDoneCallback?: (event: GestureResponderEvent) => void;\n /**\n * A component that applies blur effect to the toolbar.\n */\n blur?: JSX.Element | null;\n /**\n * A value for container opacity in hexadecimal format (e.g. `ff`). Default value is `ff`.\n */\n opacity?: HEX;\n};\n\nconst TEST_ID_KEYBOARD_TOOLBAR = \"keyboard.toolbar\";\nconst TEST_ID_KEYBOARD_TOOLBAR_PREVIOUS = `${TEST_ID_KEYBOARD_TOOLBAR}.previous`;\nconst TEST_ID_KEYBOARD_TOOLBAR_NEXT = `${TEST_ID_KEYBOARD_TOOLBAR}.next`;\nconst TEST_ID_KEYBOARD_TOOLBAR_CONTENT = `${TEST_ID_KEYBOARD_TOOLBAR}.content`;\nconst TEST_ID_KEYBOARD_TOOLBAR_DONE = `${TEST_ID_KEYBOARD_TOOLBAR}.done`;\n\nconst KEYBOARD_TOOLBAR_HEIGHT = 42;\nconst DEFAULT_OPACITY: HEX = \"FF\";\nconst offset = { closed: KEYBOARD_TOOLBAR_HEIGHT };\n\nconst dismissKeyboard = () => KeyboardController.dismiss();\nconst goToNextField = () => KeyboardController.setFocusTo(\"next\");\nconst goToPrevField = () => KeyboardController.setFocusTo(\"prev\");\n\n/**\n * `KeyboardToolbar` is a component that is shown above the keyboard with `Prev`/`Next` and\n * `Done` buttons.\n */\nconst KeyboardToolbar: React.FC<KeyboardToolbarProps> = ({\n content,\n theme = colors,\n doneText,\n button,\n icon,\n showArrows = true,\n onNextCallback,\n onPrevCallback,\n onDoneCallback,\n blur = null,\n opacity = DEFAULT_OPACITY,\n}) => {\n const colorScheme = useColorScheme();\n const [inputs, setInputs] = useState({\n current: 0,\n count: 0,\n });\n const isPrevDisabled = inputs.current === 0;\n const isNextDisabled = inputs.current === inputs.count - 1;\n\n useEffect(() => {\n const subscription = FocusedInputEvents.addListener(\"focusDidSet\", (e) => {\n setInputs(e);\n });\n\n return subscription.remove;\n }, []);\n const doneStyle = useMemo(\n () => [styles.doneButton, { color: theme[colorScheme].primary }],\n [colorScheme, theme],\n );\n const toolbarStyle = useMemo(\n () => [\n styles.toolbar,\n {\n backgroundColor: `${theme[colorScheme].background}${opacity}`,\n },\n ],\n [colorScheme, opacity, theme],\n );\n const ButtonContainer = button || Button;\n const IconContainer = icon || Arrow;\n\n const onPressNext = useCallback(\n (event: GestureResponderEvent) => {\n onNextCallback?.(event);\n\n if (!event.isDefaultPrevented()) {\n goToNextField();\n }\n },\n [onNextCallback],\n );\n const onPressPrev = useCallback(\n (event: GestureResponderEvent) => {\n onPrevCallback?.(event);\n\n if (!event.isDefaultPrevented()) {\n goToPrevField();\n }\n },\n [onPrevCallback],\n );\n const onPressDone = useCallback(\n (event: GestureResponderEvent) => {\n onDoneCallback?.(event);\n\n if (!event.isDefaultPrevented()) {\n dismissKeyboard();\n }\n },\n [onDoneCallback],\n );\n\n return (\n <KeyboardStickyView offset={offset}>\n <View style={toolbarStyle} testID={TEST_ID_KEYBOARD_TOOLBAR}>\n {blur}\n {showArrows && (\n <>\n <ButtonContainer\n accessibilityHint=\"Moves focus to the previous field\"\n accessibilityLabel=\"Previous\"\n disabled={isPrevDisabled}\n testID={TEST_ID_KEYBOARD_TOOLBAR_PREVIOUS}\n theme={theme}\n onPress={onPressPrev}\n >\n <IconContainer\n disabled={isPrevDisabled}\n theme={theme}\n type=\"prev\"\n />\n </ButtonContainer>\n <ButtonContainer\n accessibilityHint=\"Moves focus to the next field\"\n accessibilityLabel=\"Next\"\n disabled={isNextDisabled}\n testID={TEST_ID_KEYBOARD_TOOLBAR_NEXT}\n theme={theme}\n onPress={onPressNext}\n >\n <IconContainer\n disabled={isNextDisabled}\n theme={theme}\n type=\"next\"\n />\n </ButtonContainer>\n </>\n )}\n\n <View style={styles.flex} testID={TEST_ID_KEYBOARD_TOOLBAR_CONTENT}>\n {content}\n </View>\n <ButtonContainer\n accessibilityHint=\"Closes the keyboard\"\n accessibilityLabel=\"Done\"\n rippleRadius={28}\n style={styles.doneButtonContainer}\n testID={TEST_ID_KEYBOARD_TOOLBAR_DONE}\n theme={theme}\n onPress={onPressDone}\n >\n <Text maxFontSizeMultiplier={1.3} style={doneStyle}>\n {doneText || \"Done\"}\n </Text>\n </ButtonContainer>\n </View>\n </KeyboardStickyView>\n );\n};\n\nconst styles = StyleSheet.create({\n flex: {\n flex: 1,\n },\n toolbar: {\n position: \"absolute\",\n bottom: 0,\n alignItems: \"center\",\n width: \"100%\",\n flexDirection: \"row\",\n height: KEYBOARD_TOOLBAR_HEIGHT,\n paddingHorizontal: 8,\n },\n doneButton: {\n fontWeight: \"600\",\n fontSize: 15,\n },\n doneButtonContainer: {\n marginRight: 8,\n },\n});\n\nexport { colors as DefaultKeyboardToolbarTheme };\nexport default KeyboardToolbar;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AACxE,SAASC,UAAU,EAAEC,IAAI,EAAEC,IAAI,QAAQ,cAAc;AAErD,SACEC,kBAAkB,EAClBC,kBAAkB,QACb,kCAAkC;AAEzC,SAASC,kBAAkB,QAAQ,gBAAgB;AACnD,OAAOC,cAAc,M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AC;EAAM,CACZ,CACc,CACjB,CACH,eAED5E,KAAA,CAAAoE,aAAA,CAAC7D,IAAI;IAAC8D,KAAK,EAAEhB,MAAM,CAACwB,IAAK;IAACP,MAAM,EAAEpD;EAAiC,GAChEY,OACG,CAAC,eACP9B,KAAA,CAAAoE,aAAA,CAACP,eAAe;IACdW,iBAAiB,EAAC,qBAAqB;IACvCC,kBAAkB,EAAC,MAAM;IACzBK,YAAY,EAAE,EAAG;IACjBT,KAAK,EAAEhB,MAAM,CAAC0B,mBAAoB;IAClCT,MAAM,EAAEnD,6BAA8B;IACtCY,KAAK,EAAEA,KAAM;IACb4C,OAAO,EAAER;EAAY,gBAErBnE,KAAA,CAAAoE,aAAA,CAAC9D,IAAI;IAAC0E,qBAAqB,EAAE,GAAI;IAACX,KAAK,EAAEjB;EAAU,GAChDpB,QAAQ,IAAI,MACT,CACS,CACb,CACY,CAAC;AAEzB,CAAC;AAED,MAAMqB,MAAM,GAAGhD,UAAU,CAAC4E,MAAM,CAAC;EAC/BJ,IAAI,EAAE;IACJA,IAAI,EAAE;EACR,CAAC;EACDnB,OAAO,EAAE;IACPwB,QAAQ,EAAE,UAAU;IACpBC,MAAM,EAAE,CAAC;IACTC,UAAU,EAAE,QAAQ;IACpBC,KAAK,EAAE,MAAM;IACbC,aAAa,EAAE,KAAK;IACpBC,MAAM,EAAEnE,uBAAuB;IAC/BoE,iBAAiB,EAAE;EACrB,CAAC;EACDlC,UAAU,EAAE;IACVmC,UAAU,EAAE,KAAK;IACjBC,QAAQ,EAAE;EACZ,CAAC;EACDX,mBAAmB,EAAE;IACnBY,WAAW,EAAE;EACf;AACF,CAAC,CAAC;AAEF,SAAS7E,MAAM,IAAI8E,2BAA2B;AAC9C,eAAe/D,eAAe","ignoreList":[]}
1
+ {"version":3,"names":["React","useCallback","useEffect","useMemo","useState","StyleSheet","Text","View","FocusedInputEvents","KeyboardController","useColorScheme","KeyboardStickyView","Arrow","Button","colors","TEST_ID_KEYBOARD_TOOLBAR","TEST_ID_KEYBOARD_TOOLBAR_PREVIOUS","TEST_ID_KEYBOARD_TOOLBAR_NEXT","TEST_ID_KEYBOARD_TOOLBAR_CONTENT","TEST_ID_KEYBOARD_TOOLBAR_DONE","KEYBOARD_TOOLBAR_HEIGHT","DEFAULT_OPACITY","offset","closed","dismissKeyboard","dismiss","goToNextField","setFocusTo","goToPrevField","KeyboardToolbar","content","theme","doneText","button","icon","showArrows","onNextCallback","onPrevCallback","onDoneCallback","blur","opacity","colorScheme","inputs","setInputs","current","count","isPrevDisabled","isNextDisabled","subscription","addListener","e","remove","doneStyle","styles","doneButton","color","primary","toolbarStyle","toolbar","backgroundColor","background","ButtonContainer","IconContainer","onPressNext","event","isDefaultPrevented","onPressPrev","onPressDone","createElement","style","testID","Fragment","accessibilityHint","accessibilityLabel","disabled","onPress","type","flex","rippleRadius","doneButtonContainer","maxFontSizeMultiplier","create","position","bottom","alignItems","width","flexDirection","height","paddingHorizontal","fontWeight","fontSize","marginRight","DefaultKeyboardToolbarTheme"],"sources":["index.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useMemo, useState } from \"react\";\nimport { StyleSheet, Text, View } from \"react-native\";\n\nimport { FocusedInputEvents, KeyboardController } from \"../../bindings\";\nimport useColorScheme from \"../hooks/useColorScheme\";\nimport KeyboardStickyView from \"../KeyboardStickyView\";\n\nimport Arrow from \"./Arrow\";\nimport Button from \"./Button\";\nimport { colors } from \"./colors\";\n\nimport type { HEX, KeyboardToolbarTheme } from \"./types\";\nimport type { ReactNode } from \"react\";\nimport type { GestureResponderEvent } from \"react-native\";\n\nexport type KeyboardToolbarProps = {\n /** An element that is shown in the middle of the toolbar. */\n content?: JSX.Element | null;\n /** A set of dark/light colors consumed by toolbar component. */\n theme?: KeyboardToolbarTheme;\n /** Custom text for done button. */\n doneText?: ReactNode;\n /** Custom touchable component for toolbar (used for prev/next/done buttons). */\n button?: typeof Button;\n /** Custom icon component used to display next/prev buttons. */\n icon?: typeof Arrow;\n /**\n * Whether to show next and previous buttons. Can be useful to set it to `false` if you have only one input\n * and want to show only `Done` button. Default to `true`.\n */\n showArrows?: boolean;\n /**\n * A callback that is called when the user presses the next button along with the default action.\n */\n onNextCallback?: (event: GestureResponderEvent) => void;\n /**\n * A callback that is called when the user presses the previous button along with the default action.\n */\n onPrevCallback?: (event: GestureResponderEvent) => void;\n /**\n * A callback that is called when the user presses the done button along with the default action.\n */\n onDoneCallback?: (event: GestureResponderEvent) => void;\n /**\n * A component that applies blur effect to the toolbar.\n */\n blur?: JSX.Element | null;\n /**\n * A value for container opacity in hexadecimal format (e.g. `ff`). Default value is `ff`.\n */\n opacity?: HEX;\n};\n\nconst TEST_ID_KEYBOARD_TOOLBAR = \"keyboard.toolbar\";\nconst TEST_ID_KEYBOARD_TOOLBAR_PREVIOUS = `${TEST_ID_KEYBOARD_TOOLBAR}.previous`;\nconst TEST_ID_KEYBOARD_TOOLBAR_NEXT = `${TEST_ID_KEYBOARD_TOOLBAR}.next`;\nconst TEST_ID_KEYBOARD_TOOLBAR_CONTENT = `${TEST_ID_KEYBOARD_TOOLBAR}.content`;\nconst TEST_ID_KEYBOARD_TOOLBAR_DONE = `${TEST_ID_KEYBOARD_TOOLBAR}.done`;\n\nconst KEYBOARD_TOOLBAR_HEIGHT = 42;\nconst DEFAULT_OPACITY: HEX = \"FF\";\nconst offset = { closed: KEYBOARD_TOOLBAR_HEIGHT };\n\nconst dismissKeyboard = () => KeyboardController.dismiss();\nconst goToNextField = () => KeyboardController.setFocusTo(\"next\");\nconst goToPrevField = () => KeyboardController.setFocusTo(\"prev\");\n\n/**\n * `KeyboardToolbar` is a component that is shown above the keyboard with `Prev`/`Next` and\n * `Done` buttons.\n */\nconst KeyboardToolbar: React.FC<KeyboardToolbarProps> = ({\n content,\n theme = colors,\n doneText,\n button,\n icon,\n showArrows = true,\n onNextCallback,\n onPrevCallback,\n onDoneCallback,\n blur = null,\n opacity = DEFAULT_OPACITY,\n}) => {\n const colorScheme = useColorScheme();\n const [inputs, setInputs] = useState({\n current: 0,\n count: 0,\n });\n const isPrevDisabled = inputs.current === 0;\n const isNextDisabled = inputs.current === inputs.count - 1;\n\n useEffect(() => {\n const subscription = FocusedInputEvents.addListener(\"focusDidSet\", (e) => {\n setInputs(e);\n });\n\n return subscription.remove;\n }, []);\n const doneStyle = useMemo(\n () => [styles.doneButton, { color: theme[colorScheme].primary }],\n [colorScheme, theme],\n );\n const toolbarStyle = useMemo(\n () => [\n styles.toolbar,\n {\n backgroundColor: `${theme[colorScheme].background}${opacity}`,\n },\n ],\n [colorScheme, opacity, theme],\n );\n const ButtonContainer = button || Button;\n const IconContainer = icon || Arrow;\n\n const onPressNext = useCallback(\n (event: GestureResponderEvent) => {\n onNextCallback?.(event);\n\n if (!event.isDefaultPrevented()) {\n goToNextField();\n }\n },\n [onNextCallback],\n );\n const onPressPrev = useCallback(\n (event: GestureResponderEvent) => {\n onPrevCallback?.(event);\n\n if (!event.isDefaultPrevented()) {\n goToPrevField();\n }\n },\n [onPrevCallback],\n );\n const onPressDone = useCallback(\n (event: GestureResponderEvent) => {\n onDoneCallback?.(event);\n\n if (!event.isDefaultPrevented()) {\n dismissKeyboard();\n }\n },\n [onDoneCallback],\n );\n\n return (\n <KeyboardStickyView offset={offset}>\n <View style={toolbarStyle} testID={TEST_ID_KEYBOARD_TOOLBAR}>\n {blur}\n {showArrows && (\n <>\n <ButtonContainer\n accessibilityHint=\"Moves focus to the previous field\"\n accessibilityLabel=\"Previous\"\n disabled={isPrevDisabled}\n testID={TEST_ID_KEYBOARD_TOOLBAR_PREVIOUS}\n theme={theme}\n onPress={onPressPrev}\n >\n <IconContainer\n disabled={isPrevDisabled}\n theme={theme}\n type=\"prev\"\n />\n </ButtonContainer>\n <ButtonContainer\n accessibilityHint=\"Moves focus to the next field\"\n accessibilityLabel=\"Next\"\n disabled={isNextDisabled}\n testID={TEST_ID_KEYBOARD_TOOLBAR_NEXT}\n theme={theme}\n onPress={onPressNext}\n >\n <IconContainer\n disabled={isNextDisabled}\n theme={theme}\n type=\"next\"\n />\n </ButtonContainer>\n </>\n )}\n\n <View style={styles.flex} testID={TEST_ID_KEYBOARD_TOOLBAR_CONTENT}>\n {content}\n </View>\n <ButtonContainer\n accessibilityHint=\"Closes the keyboard\"\n accessibilityLabel=\"Done\"\n rippleRadius={28}\n style={styles.doneButtonContainer}\n testID={TEST_ID_KEYBOARD_TOOLBAR_DONE}\n theme={theme}\n onPress={onPressDone}\n >\n <Text maxFontSizeMultiplier={1.3} style={doneStyle}>\n {doneText || \"Done\"}\n </Text>\n </ButtonContainer>\n </View>\n </KeyboardStickyView>\n );\n};\n\nconst styles = StyleSheet.create({\n flex: {\n flex: 1,\n },\n toolbar: {\n position: \"absolute\",\n bottom: 0,\n alignItems: \"center\",\n width: \"100%\",\n flexDirection: \"row\",\n height: KEYBOARD_TOOLBAR_HEIGHT,\n paddingHorizontal: 8,\n },\n doneButton: {\n fontWeight: \"600\",\n fontSize: 15,\n },\n doneButtonContainer: {\n marginRight: 8,\n },\n});\n\nexport { colors as DefaultKeyboardToolbarTheme };\nexport default KeyboardToolbar;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AACxE,SAASC,UAAU,EAAEC,IAAI,EAAEC,IAAI,QAAQ,cAAc;AAErD,SAASC,kBAAkB,EAAEC,kBAAkB,QAAQ,gBAAgB;AACvE,OAAOC,cAAc,MAAM,yBAAyB;AACpD,OAAOC,kBAAkB,MAAM,uBAAuB;AAEtD,OAAOC,KAAK,MAAM,SAAS;AAC3B,OAAOC,MAAM,MAAM,UAAU;AAC7B,SAASC,MAAM,QAAQ,UAAU;AA4CjC,MAAMC,wBAAwB,GAAG,kBAAkB;AACnD,MAAMC,iCAAiC,GAAG,GAAGD,wBAAwB,WAAW;AAChF,MAAME,6BAA6B,GAAG,GAAGF,wBAAwB,OAAO;AACxE,MAAMG,gCAAgC,GAAG,GAAGH,wBAAwB,UAA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,EAAEhB,MAAM,CAAC0B,mBAAoB;IAClCT,MAAM,EAAEnD,6BAA8B;IACtCY,KAAK,EAAEA,KAAM;IACb4C,OAAO,EAAER;EAAY,gBAErBnE,KAAA,CAAAoE,aAAA,CAAC9D,IAAI;IAAC0E,qBAAqB,EAAE,GAAI;IAACX,KAAK,EAAEjB;EAAU,GAChDpB,QAAQ,IAAI,MACT,CACS,CACb,CACY,CAAC;AAEzB,CAAC;AAED,MAAMqB,MAAM,GAAGhD,UAAU,CAAC4E,MAAM,CAAC;EAC/BJ,IAAI,EAAE;IACJA,IAAI,EAAE;EACR,CAAC;EACDnB,OAAO,EAAE;IACPwB,QAAQ,EAAE,UAAU;IACpBC,MAAM,EAAE,CAAC;IACTC,UAAU,EAAE,QAAQ;IACpBC,KAAK,EAAE,MAAM;IACbC,aAAa,EAAE,KAAK;IACpBC,MAAM,EAAEnE,uBAAuB;IAC/BoE,iBAAiB,EAAE;EACrB,CAAC;EACDlC,UAAU,EAAE;IACVmC,UAAU,EAAE,KAAK;IACjBC,QAAQ,EAAE;EACZ,CAAC;EACDX,mBAAmB,EAAE;IACnBY,WAAW,EAAE;EACf;AACF,CAAC,CAAC;AAEF,SAAS7E,MAAM,IAAI8E,2BAA2B;AAC9C,eAAe/D,eAAe","ignoreList":[]}
@@ -1,8 +1,7 @@
1
- import { useEffect } from "react";
1
+ import { useEffect, useLayoutEffect } from "react";
2
2
  import { KeyboardController } from "../bindings";
3
3
  import { AndroidSoftInputModes } from "../constants";
4
4
  import { useKeyboardContext } from "../context";
5
- import useSyncEffect from "./useSyncEffect";
6
5
  export const useResizeMode = () => {
7
6
  useEffect(() => {
8
7
  KeyboardController.setInputMode(AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE);
@@ -21,7 +20,7 @@ export const useReanimatedKeyboardAnimation = () => {
21
20
  };
22
21
  export function useGenericKeyboardHandler(handler, deps) {
23
22
  const context = useKeyboardContext();
24
- useSyncEffect(() => {
23
+ useLayoutEffect(() => {
25
24
  const cleanup = context.setKeyboardHandlers(handler);
26
25
  return () => cleanup();
27
26
  }, deps);
@@ -45,7 +44,7 @@ export function useReanimatedFocusedInput() {
45
44
  }
46
45
  export function useFocusedInputHandler(handler, deps) {
47
46
  const context = useKeyboardContext();
48
- useSyncEffect(() => {
47
+ useLayoutEffect(() => {
49
48
  const cleanup = context.setInputHandlers(handler);
50
49
  return () => cleanup();
51
50
  }, deps);
@@ -1 +1 @@
1
- {"version":3,"names":["useEffect","KeyboardController","AndroidSoftInputModes","useKeyboardContext","useSyncEffect","useResizeMode","setInputMode","SOFT_INPUT_ADJUST_RESIZE","setDefaultMode","useKeyboardAnimation","context","animated","useReanimatedKeyboardAnimation","reanimated","useGenericKeyboardHandler","handler","deps","cleanup","setKeyboardHandlers","useKeyboardHandler","useKeyboardController","setEnabled","enabled","useReanimatedFocusedInput","input","layout","useFocusedInputHandler","setInputHandlers"],"sources":["index.ts"],"sourcesContent":["import { useEffect } from \"react\";\n\nimport { KeyboardController } from \"../bindings\";\nimport { AndroidSoftInputModes } from \"../constants\";\nimport { useKeyboardContext } from \"../context\";\n\nimport useSyncEffect from \"./useSyncEffect\";\n\nimport type { AnimatedContext, ReanimatedContext } from \"../context\";\nimport type { FocusedInputHandler, KeyboardHandler } from \"../types\";\nimport type { DependencyList } from \"react\";\n\nexport const useResizeMode = () => {\n useEffect(() => {\n KeyboardController.setInputMode(\n AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE,\n );\n\n return () => KeyboardController.setDefaultMode();\n }, []);\n};\n\nexport const useKeyboardAnimation = (): AnimatedContext => {\n useResizeMode();\n const context = useKeyboardContext();\n\n return context.animated;\n};\n\nexport const useReanimatedKeyboardAnimation = (): ReanimatedContext => {\n useResizeMode();\n const context = useKeyboardContext();\n\n return context.reanimated;\n};\n\nexport function useGenericKeyboardHandler(\n handler: KeyboardHandler,\n deps?: DependencyList,\n) {\n const context = useKeyboardContext();\n\n useSyncEffect(() => {\n const cleanup = context.setKeyboardHandlers(handler);\n\n return () => cleanup();\n }, deps);\n}\n\nexport function useKeyboardHandler(\n handler: KeyboardHandler,\n deps?: DependencyList,\n) {\n useResizeMode();\n useGenericKeyboardHandler(handler, deps);\n}\n\nexport function useKeyboardController() {\n const context = useKeyboardContext();\n\n return { setEnabled: context.setEnabled, enabled: context.enabled };\n}\n\nexport function useReanimatedFocusedInput() {\n const context = useKeyboardContext();\n\n return { input: context.layout };\n}\n\nexport function useFocusedInputHandler(\n handler: FocusedInputHandler,\n deps?: DependencyList,\n) {\n const context = useKeyboardContext();\n\n useSyncEffect(() => {\n const cleanup = context.setInputHandlers(handler);\n\n return () => cleanup();\n }, deps);\n}\n\nexport * from \"./useWindowDimensions\";\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,OAAO;AAEjC,SAASC,kBAAkB,QAAQ,aAAa;AAChD,SAASC,qBAAqB,QAAQ,cAAc;AACpD,SAASC,kBAAkB,QAAQ,YAAY;AAE/C,OAAOC,aAAa,MAAM,iBAAiB;AAM3C,OAAO,MAAMC,aAAa,GAAGA,CAAA,KAAM;EACjCL,SAAS,CAAC,MAAM;IACdC,kBAAkB,CAACK,YAAY,CAC7BJ,qBAAqB,CAACK,wBACxB,CAAC;IAED,OAAO,MAAMN,kBAAkB,CAACO,cAAc,CAAC,CAAC;EAClD,CAAC,EAAE,EAAE,CAAC;AACR,CAAC;AAED,OAAO,MAAMC,oBAAoB,GAAGA,CAAA,KAAuB;EACzDJ,aAAa,CAAC,CAAC;EACf,MAAMK,OAAO,GAAGP,kBAAkB,CAAC,CAAC;EAEpC,OAAOO,OAAO,CAACC,QAAQ;AACzB,CAAC;AAED,OAAO,MAAMC,8BAA8B,GAAGA,CAAA,KAAyB;EACrEP,aAAa,CAAC,CAAC;EACf,MAAMK,OAAO,GAAGP,kBAAkB,CAAC,CAAC;EAEpC,OAAOO,OAAO,CAACG,UAAU;AAC3B,CAAC;AAED,OAAO,SAASC,yBAAyBA,CACvCC,OAAwB,EACxBC,IAAqB,EACrB;EACA,MAAMN,OAAO,GAAGP,kBAAkB,CAAC,CAAC;EAEpCC,aAAa,CAAC,MAAM;IAClB,MAAMa,OAAO,GAAGP,OAAO,CAACQ,mBAAmB,CAACH,OAAO,CAAC;IAEpD,OAAO,MAAME,OAAO,CAAC,CAAC;EACxB,CAAC,EAAED,IAAI,CAAC;AACV;AAEA,OAAO,SAASG,kBAAkBA,CAChCJ,OAAwB,EACxBC,IAAqB,EACrB;EACAX,aAAa,CAAC,CAAC;EACfS,yBAAyB,CAACC,OAAO,EAAEC,IAAI,CAAC;AAC1C;AAEA,OAAO,SAASI,qBAAqBA,CAAA,EAAG;EACtC,MAAMV,OAAO,GAAGP,kBAAkB,CAAC,CAAC;EAEpC,OAAO;IAAEkB,UAAU,EAAEX,OAAO,CAACW,UAAU;IAAEC,OAAO,EAAEZ,OAAO,CAACY;EAAQ,CAAC;AACrE;AAEA,OAAO,SAASC,yBAAyBA,CAAA,EAAG;EAC1C,MAAMb,OAAO,GAAGP,kBAAkB,CAAC,CAAC;EAEpC,OAAO;IAAEqB,KAAK,EAAEd,OAAO,CAACe;EAAO,CAAC;AAClC;AAEA,OAAO,SAASC,sBAAsBA,CACpCX,OAA4B,EAC5BC,IAAqB,EACrB;EACA,MAAMN,OAAO,GAAGP,kBAAkB,CAAC,CAAC;EAEpCC,aAAa,CAAC,MAAM;IAClB,MAAMa,OAAO,GAAGP,OAAO,CAACiB,gBAAgB,CAACZ,OAAO,CAAC;IAEjD,OAAO,MAAME,OAAO,CAAC,CAAC;EACxB,CAAC,EAAED,IAAI,CAAC;AACV;AAEA,cAAc,uBAAuB","ignoreList":[]}
1
+ {"version":3,"names":["useEffect","useLayoutEffect","KeyboardController","AndroidSoftInputModes","useKeyboardContext","useResizeMode","setInputMode","SOFT_INPUT_ADJUST_RESIZE","setDefaultMode","useKeyboardAnimation","context","animated","useReanimatedKeyboardAnimation","reanimated","useGenericKeyboardHandler","handler","deps","cleanup","setKeyboardHandlers","useKeyboardHandler","useKeyboardController","setEnabled","enabled","useReanimatedFocusedInput","input","layout","useFocusedInputHandler","setInputHandlers"],"sources":["index.ts"],"sourcesContent":["import { useEffect, useLayoutEffect } from \"react\";\n\nimport { KeyboardController } from \"../bindings\";\nimport { AndroidSoftInputModes } from \"../constants\";\nimport { useKeyboardContext } from \"../context\";\n\nimport type { AnimatedContext, ReanimatedContext } from \"../context\";\nimport type { FocusedInputHandler, KeyboardHandler } from \"../types\";\nimport type { DependencyList } from \"react\";\n\nexport const useResizeMode = () => {\n useEffect(() => {\n KeyboardController.setInputMode(\n AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE,\n );\n\n return () => KeyboardController.setDefaultMode();\n }, []);\n};\n\nexport const useKeyboardAnimation = (): AnimatedContext => {\n useResizeMode();\n const context = useKeyboardContext();\n\n return context.animated;\n};\n\nexport const useReanimatedKeyboardAnimation = (): ReanimatedContext => {\n useResizeMode();\n const context = useKeyboardContext();\n\n return context.reanimated;\n};\n\nexport function useGenericKeyboardHandler(\n handler: KeyboardHandler,\n deps?: DependencyList,\n) {\n const context = useKeyboardContext();\n\n useLayoutEffect(() => {\n const cleanup = context.setKeyboardHandlers(handler);\n\n return () => cleanup();\n }, deps);\n}\n\nexport function useKeyboardHandler(\n handler: KeyboardHandler,\n deps?: DependencyList,\n) {\n useResizeMode();\n useGenericKeyboardHandler(handler, deps);\n}\n\nexport function useKeyboardController() {\n const context = useKeyboardContext();\n\n return { setEnabled: context.setEnabled, enabled: context.enabled };\n}\n\nexport function useReanimatedFocusedInput() {\n const context = useKeyboardContext();\n\n return { input: context.layout };\n}\n\nexport function useFocusedInputHandler(\n handler: FocusedInputHandler,\n deps?: DependencyList,\n) {\n const context = useKeyboardContext();\n\n useLayoutEffect(() => {\n const cleanup = context.setInputHandlers(handler);\n\n return () => cleanup();\n }, deps);\n}\n\nexport * from \"./useWindowDimensions\";\n"],"mappings":"AAAA,SAASA,SAAS,EAAEC,eAAe,QAAQ,OAAO;AAElD,SAASC,kBAAkB,QAAQ,a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AEA,OAAO,SAASC,yBAAyBA,CAAA,EAAG;EAC1C,MAAMb,OAAO,GAAGN,kBAAkB,CAAC,CAAC;EAEpC,OAAO;IAAEoB,KAAK,EAAEd,OAAO,CAACe;EAAO,CAAC;AAClC;AAEA,OAAO,SAASC,sBAAsBA,CACpCX,OAA4B,EAC5BC,IAAqB,EACrB;EACA,MAAMN,OAAO,GAAGN,kBAAkB,CAAC,CAAC;EAEpCH,eAAe,CAAC,MAAM;IACpB,MAAMgB,OAAO,GAAGP,OAAO,CAACiB,gBAAgB,CAACZ,OAAO,CAAC;IAEjD,OAAO,MAAME,OAAO,CAAC,CAAC;EACxB,CAAC,EAAED,IAAI,CAAC;AACV;AAEA,cAAc,uBAAuB","ignoreList":[]}
@@ -3,19 +3,31 @@ import { Animated, findNodeHandle } from "react-native";
3
3
  import { registerEventHandler, unregisterEventHandler } from "./event-handler";
4
4
  export function useEventHandlerRegistration(map, viewTagRef) {
5
5
  const onRegisterHandler = handler => {
6
- const viewTag = findNodeHandle(viewTagRef.current);
7
- const ids = Object.keys(handler).map(handlerName => {
8
- const eventName = map.get(handlerName);
9
- const functionToCall = handler[handlerName];
10
- if (eventName && viewTag) {
11
- return registerEventHandler(event => {
12
- "worklet";
13
-
14
- functionToCall === null || functionToCall === void 0 || functionToCall(event);
15
- }, eventName, viewTag);
6
+ const ids = [];
7
+ const attachWorkletHandlers = () => {
8
+ const viewTag = findNodeHandle(viewTagRef.current);
9
+ if (__DEV__ && !viewTag) {
10
+ console.warn("Can not attach worklet handlers for `react-native-keyboard-controller` because view tag can not be resolved. Be sure that `KeyboardProvider` is fully mounted before registering handlers. If you think it is a bug in library, please open an issue.");
16
11
  }
17
- return null;
18
- });
12
+ ids.push(...Object.keys(handler).map(handlerName => {
13
+ const eventName = map.get(handlerName);
14
+ const functionToCall = handler[handlerName];
15
+ if (eventName && viewTag) {
16
+ return registerEventHandler(event => {
17
+ "worklet";
18
+
19
+ functionToCall === null || functionToCall === void 0 || functionToCall(event);
20
+ }, eventName, viewTag);
21
+ }
22
+ return null;
23
+ }));
24
+ };
25
+ if (viewTagRef.current) {
26
+ attachWorkletHandlers();
27
+ } else {
28
+ // view may not be mounted yet - defer registration to next event loop
29
+ setImmediate(attachWorkletHandlers);
30
+ }
19
31
  return () => {
20
32
  ids.forEach(id => id ? unregisterEventHandler(id) : null);
21
33
  };
@@ -1 +1 @@
1
- {"version":3,"names":["useRef","Animated","findNodeHandle","registerEventHandler","unregisterEventHandler","useEventHandlerRegistration","map","viewTagRef","onRegisterHandler","handler","viewTag","current","ids","Object","keys","handlerName","eventName","get","functionToCall","event","forEach","id","useAnimatedValue","initialValue","config","ref","Value"],"sources":["internal.ts"],"sourcesContent":["import { useRef } from \"react\";\nimport { Animated, findNodeHandle } from \"react-native\";\n\nimport { registerEventHandler, unregisterEventHandler } from \"./event-handler\";\n\ntype EventHandler = (event: never) => void;\ntype ComponentOrHandle = Parameters<typeof findNodeHandle>[0];\n\nexport function useEventHandlerRegistration<\n H extends Partial<Record<string, EventHandler>>,\n>(\n map: Map<keyof H, string>,\n viewTagRef: React.MutableRefObject<ComponentOrHandle>,\n) {\n const onRegisterHandler = (handler: H) => {\n const viewTag = findNodeHandle(viewTagRef.current);\n const ids = Object.keys(handler).map((handlerName) => {\n const eventName = map.get(handlerName as keyof H);\n const functionToCall = handler[handlerName as keyof H];\n\n if (eventName && viewTag) {\n return registerEventHandler(\n (event: Parameters<NonNullable<H[keyof H]>>[0]) => {\n \"worklet\";\n\n functionToCall?.(event);\n },\n eventName,\n viewTag,\n );\n }\n\n return null;\n });\n\n return () => {\n ids.forEach((id) => (id ? unregisterEventHandler(id) : null));\n };\n };\n\n return onRegisterHandler;\n}\n\n/**\n * TS variant of `useAnimatedValue` hook which is added in RN 0.71\n * A better alternative of storing animated values in refs, since\n * it doesn't recreate a new `Animated.Value` object on every re-render\n * and therefore consumes less memory. We can not use a variant from\n * RN, since this library supports earlier versions of RN.\n *\n * @see https://github.com/facebook/react-native/commit/e22217fe8b9455e32695f88ca835e11442b0a937\n */\nexport function useAnimatedValue(\n initialValue: number,\n config?: Animated.AnimatedConfig,\n): Animated.Value {\n const ref = useRef<Animated.Value | null>(null);\n\n if (ref.current === null) {\n ref.current = new Animated.Value(initialValue, config);\n }\n\n return ref.current;\n}\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,OAAO;AAC9B,SAASC,QAAQ,EAAEC,cAAc,QAAQ,cAAc;AAEvD,SAASC,oBAAoB,EAAEC,sBAAsB,QAAQ,iBAAiB;AAK9E,OAAO,SAASC,2BAA2BA,CAGzCC,GAAyB,EACzBC,UAAqD,EACrD;EACA,MAAMC,iBAAiB,GAAIC,OAAU,IAAK;IACxC,MAAMC,OAAO,GAAGR,cAAc,CAACK,UAAU,CAACI,OAAO,CAAC;IAClD,MAAMC,GAAG,GAAGC,MAAM,CAACC,IAAI,CAACL,OAAO,CAAC,CAACH,GAAG,CAAES,WAAW,IAAK;MACpD,MAAMC,SAAS,GAAGV,GAAG,CAACW,GAAG,CAACF,WAAsB,CAAC;MACjD,MAAMG,cAAc,GAAGT,OAAO,CAACM,WAAW,CAAY;MAEtD,IAAIC,SAAS,IAAIN,OAAO,EAAE;QACxB,OAAOP,oBAAoB,CACxBgB,KAA6C,IAAK;UACjD,SAAS;;UAETD,cAAc,aAAdA,cAAc,eAAdA,cAAc,CAAGC,KAAK,CAAC;QACzB,CAAC,EACDH,SAAS,EACTN,OACF,CAAC;MACH;MAEA,OAAO,IAAI;IACb,CAAC,CAAC;IAEF,OAAO,MAAM;MACXE,GAAG,CAACQ,OAAO,CAAEC,EAAE,IAAMA,EAAE,GAAGjB,sBAAsB,CAACiB,EAAE,CAAC,GAAG,IAAK,CAAC;IAC/D,CAAC;EACH,CAAC;EAED,OAAOb,iBAAiB;AAC1B;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASc,gBAAgBA,CAC9BC,YAAoB,EACpBC,MAAgC,EAChB;EAChB,MAAMC,GAAG,GAAGzB,MAAM,CAAwB,IAAI,CAAC;EAE/C,IAAIyB,GAAG,CAACd,OAAO,KAAK,IAAI,EAAE;IACxBc,GAAG,CAACd,OAAO,GAAG,IAAIV,QAAQ,CAACyB,KAAK,CAACH,YAAY,EAAEC,MAAM,CAAC;EACxD;EAEA,OAAOC,GAAG,CAACd,OAAO;AACpB","ignoreList":[]}
1
+ {"version":3,"names":["useRef","Animated","findNodeHandle","registerEventHandler","unregisterEventHandler","useEventHandlerRegistration","map","viewTagRef","onRegisterHandler","handler","ids","attachWorkletHandlers","viewTag","current","__DEV__","console","warn","push","Object","keys","handlerName","eventName","get","functionToCall","event","setImmediate","forEach","id","useAnimatedValue","initialValue","config","ref","Value"],"sources":["internal.ts"],"sourcesContent":["import { useRef } from \"react\";\nimport { Animated, findNodeHandle } from \"react-native\";\n\nimport { registerEventHandler, unregisterEventHandler } from \"./event-handler\";\n\ntype EventHandler = (event: never) => void;\ntype ComponentOrHandle = Parameters<typeof findNodeHandle>[0];\n\nexport function useEventHandlerRegistration<\n H extends Partial<Record<string, EventHandler>>,\n>(\n map: Map<keyof H, string>,\n viewTagRef: React.MutableRefObject<ComponentOrHandle>,\n) {\n const onRegisterHandler = (handler: H) => {\n const ids: (number | null)[] = [];\n const attachWorkletHandlers = () => {\n const viewTag = findNodeHandle(viewTagRef.current);\n\n if (__DEV__ && !viewTag) {\n console.warn(\n \"Can not attach worklet handlers for `react-native-keyboard-controller` because view tag can not be resolved. Be sure that `KeyboardProvider` is fully mounted before registering handlers. If you think it is a bug in library, please open an issue.\",\n );\n }\n\n ids.push(\n ...Object.keys(handler).map((handlerName) => {\n const eventName = map.get(handlerName as keyof H);\n const functionToCall = handler[handlerName as keyof H];\n\n if (eventName && viewTag) {\n return registerEventHandler(\n (event: Parameters<NonNullable<H[keyof H]>>[0]) => {\n \"worklet\";\n\n functionToCall?.(event);\n },\n eventName,\n viewTag,\n );\n }\n\n return null;\n }),\n );\n };\n\n if (viewTagRef.current) {\n attachWorkletHandlers();\n } else {\n // view may not be mounted yet - defer registration to next event loop\n setImmediate(attachWorkletHandlers);\n }\n\n return () => {\n ids.forEach((id) => (id ? unregisterEventHandler(id) : null));\n };\n };\n\n return onRegisterHandler;\n}\n\n/**\n * TS variant of `useAnimatedValue` hook which is added in RN 0.71\n * A better alternative of storing animated values in refs, since\n * it doesn't recreate a new `Animated.Value` object on every re-render\n * and therefore consumes less memory. We can not use a variant from\n * RN, since this library supports earlier versions of RN.\n *\n * @see https://github.com/facebook/react-native/commit/e22217fe8b9455e32695f88ca835e11442b0a937\n */\nexport function useAnimatedValue(\n initialValue: number,\n config?: Animated.AnimatedConfig,\n): Animated.Value {\n const ref = useRef<Animated.Value | null>(null);\n\n if (ref.current === null) {\n ref.current = new Animated.Value(initialValue, config);\n }\n\n return ref.current;\n}\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,OAAO;AAC9B,SAASC,QAAQ,EAAEC,cAAc,QAAQ,cAAc;AAEvD,SAASC,oBAAoB,EAAEC,sBAAsB,QAAQ,iBAAiB;AAK9E,OAAO,SAASC,2BAA2BA,CAGzCC,GAAyB,EACzBC,UAAqD,EACrD;EACA,MAAMC,iBAAiB,GAAIC,OAAU,IAAK;IACxC,MAAMC,GAAsB,GAAG,EAAE;IACjC,MAAMC,qBAAqB,GAAGA,CAAA,KAAM;MAClC,MAAMC,OAAO,GAAGV,cAAc,CAACK,UAAU,CAACM,OAAO,CAAC;MAElD,IAAIC,OAAO,IAAI,CAACF,OAAO,EAAE;QACvBG,OAAO,CAACC,IAAI,CACV,uPACF,CAAC;MACH;MAEAN,GAAG,CAACO,IAAI,CACN,GAAGC,MAAM,CAACC,IAAI,CAACV,OAAO,CAAC,CAACH,GAAG,CAAEc,WAAW,IAAK;QAC3C,MAAMC,SAAS,GAAGf,GAAG,CAACgB,GAAG,CAACF,WAAsB,CAAC;QACjD,MAAMG,cAAc,GAAGd,OAAO,CAACW,WAAW,CAAY;QAEtD,IAAIC,SAAS,IAAIT,OAAO,EAAE;UACxB,OAAOT,oBAAoB,CACxBqB,KAA6C,IAAK;YACjD,SAAS;;YAETD,cAAc,aAAdA,cAAc,eAAdA,cAAc,CAAGC,KAAK,CAAC;UACzB,CAAC,EACDH,SAAS,EACTT,OACF,CAAC;QACH;QAEA,OAAO,IAAI;MACb,CAAC,CACH,CAAC;IACH,CAAC;IAED,IAAIL,UAAU,CAACM,OAAO,EAAE;MACtBF,qBAAqB,CAAC,CAAC;IACzB,CAAC,MAAM;MACL;MACAc,YAAY,CAACd,qBAAqB,CAAC;IACrC;IAEA,OAAO,MAAM;MACXD,GAAG,CAACgB,OAAO,CAAEC,EAAE,IAAMA,EAAE,GAAGvB,sBAAsB,CAACuB,EAAE,CAAC,GAAG,IAAK,CAAC;IAC/D,CAAC;EACH,CAAC;EAED,OAAOnB,iBAAiB;AAC1B;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASoB,gBAAgBA,CAC9BC,YAAoB,EACpBC,MAAgC,EAChB;EAChB,MAAMC,GAAG,GAAG/B,MAAM,CAAwB,IAAI,CAAC;EAE/C,IAAI+B,GAAG,CAAClB,OAAO,KAAK,IAAI,EAAE;IACxBkB,GAAG,CAAClB,OAAO,GAAG,IAAIZ,QAAQ,CAAC+B,KAAK,CAACH,YAAY,EAAEC,MAAM,CAAC;EACxD;EAEA,OAAOC,GAAG,CAAClB,OAAO;AACpB","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import { useKeyboardHandler } from "react-native-keyboard-controller";
1
+ import { useKeyboardHandler } from "../../hooks";
2
2
  /**
3
3
  * Hook that uses default transitions for iOS and Android > 11, and uses
4
4
  * custom interpolation on Android < 11 to achieve more smooth animation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-keyboard-controller",
3
- "version": "1.13.2",
3
+ "version": "1.13.4",
4
4
  "description": "Keyboard manager which works in identical way on both iOS and Android",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -1,9 +1,7 @@
1
1
  import { useSharedValue } from "react-native-reanimated";
2
2
 
3
- import {
4
- useKeyboardContext,
5
- useKeyboardHandler,
6
- } from "react-native-keyboard-controller";
3
+ import { useKeyboardContext } from "../../context";
4
+ import { useKeyboardHandler } from "../../hooks";
7
5
 
8
6
  export const useKeyboardAnimation = () => {
9
7
  const { reanimated } = useKeyboardContext();
@@ -8,7 +8,7 @@ import Reanimated, {
8
8
  useSharedValue,
9
9
  } from "react-native-reanimated";
10
10
 
11
- import { useWindowDimensions } from "react-native-keyboard-controller";
11
+ import { useWindowDimensions } from "../../hooks";
12
12
 
13
13
  import { useKeyboardAnimation } from "./hooks";
14
14
 
@@ -14,7 +14,7 @@ import {
14
14
  useFocusedInputHandler,
15
15
  useReanimatedFocusedInput,
16
16
  useWindowDimensions,
17
- } from "react-native-keyboard-controller";
17
+ } from "../../hooks";
18
18
 
19
19
  import { useSmoothKeyboardHandler } from "./useSmoothKeyboardHandler";
20
20
  import { debounce, scrollDistanceWithRespectToSnapPoints } from "./utils";
@@ -6,7 +6,7 @@ import {
6
6
  withTiming,
7
7
  } from "react-native-reanimated";
8
8
 
9
- import { useKeyboardHandler } from "react-native-keyboard-controller";
9
+ import { useKeyboardHandler } from "../../hooks";
10
10
 
11
11
  const IS_ANDROID_ELEVEN_OR_HIGHER =
12
12
  Platform.OS === "android" && Platform.Version >= 30;
@@ -4,7 +4,7 @@ import Reanimated, {
4
4
  useAnimatedStyle,
5
5
  } from "react-native-reanimated";
6
6
 
7
- import { useReanimatedKeyboardAnimation } from "react-native-keyboard-controller";
7
+ import { useReanimatedKeyboardAnimation } from "../../hooks";
8
8
 
9
9
  import type { View, ViewProps } from "react-native";
10
10
 
@@ -1,13 +1,9 @@
1
1
  import React, { useCallback, useEffect, useMemo, useState } from "react";
2
2
  import { StyleSheet, Text, View } from "react-native";
3
3
 
4
- import {
5
- FocusedInputEvents,
6
- KeyboardStickyView,
7
- } from "react-native-keyboard-controller";
8
-
9
- import { KeyboardController } from "../../bindings";
4
+ import { FocusedInputEvents, KeyboardController } from "../../bindings";
10
5
  import useColorScheme from "../hooks/useColorScheme";
6
+ import KeyboardStickyView from "../KeyboardStickyView";
11
7
 
12
8
  import Arrow from "./Arrow";
13
9
  import Button from "./Button";
@@ -1,11 +1,9 @@
1
- import { useEffect } from "react";
1
+ import { useEffect, useLayoutEffect } from "react";
2
2
 
3
3
  import { KeyboardController } from "../bindings";
4
4
  import { AndroidSoftInputModes } from "../constants";
5
5
  import { useKeyboardContext } from "../context";
6
6
 
7
- import useSyncEffect from "./useSyncEffect";
8
-
9
7
  import type { AnimatedContext, ReanimatedContext } from "../context";
10
8
  import type { FocusedInputHandler, KeyboardHandler } from "../types";
11
9
  import type { DependencyList } from "react";
@@ -40,7 +38,7 @@ export function useGenericKeyboardHandler(
40
38
  ) {
41
39
  const context = useKeyboardContext();
42
40
 
43
- useSyncEffect(() => {
41
+ useLayoutEffect(() => {
44
42
  const cleanup = context.setKeyboardHandlers(handler);
45
43
 
46
44
  return () => cleanup();
@@ -73,7 +71,7 @@ export function useFocusedInputHandler(
73
71
  ) {
74
72
  const context = useKeyboardContext();
75
73
 
76
- useSyncEffect(() => {
74
+ useLayoutEffect(() => {
77
75
  const cleanup = context.setInputHandlers(handler);
78
76
 
79
77
  return () => cleanup();
package/src/internal.ts CHANGED
@@ -13,25 +13,44 @@ export function useEventHandlerRegistration<
13
13
  viewTagRef: React.MutableRefObject<ComponentOrHandle>,
14
14
  ) {
15
15
  const onRegisterHandler = (handler: H) => {
16
- const viewTag = findNodeHandle(viewTagRef.current);
17
- const ids = Object.keys(handler).map((handlerName) => {
18
- const eventName = map.get(handlerName as keyof H);
19
- const functionToCall = handler[handlerName as keyof H];
16
+ const ids: (number | null)[] = [];
17
+ const attachWorkletHandlers = () => {
18
+ const viewTag = findNodeHandle(viewTagRef.current);
20
19
 
21
- if (eventName && viewTag) {
22
- return registerEventHandler(
23
- (event: Parameters<NonNullable<H[keyof H]>>[0]) => {
24
- "worklet";
25
-
26
- functionToCall?.(event);
27
- },
28
- eventName,
29
- viewTag,
20
+ if (__DEV__ && !viewTag) {
21
+ console.warn(
22
+ "Can not attach worklet handlers for `react-native-keyboard-controller` because view tag can not be resolved. Be sure that `KeyboardProvider` is fully mounted before registering handlers. If you think it is a bug in library, please open an issue.",
30
23
  );
31
24
  }
32
25
 
33
- return null;
34
- });
26
+ ids.push(
27
+ ...Object.keys(handler).map((handlerName) => {
28
+ const eventName = map.get(handlerName as keyof H);
29
+ const functionToCall = handler[handlerName as keyof H];
30
+
31
+ if (eventName && viewTag) {
32
+ return registerEventHandler(
33
+ (event: Parameters<NonNullable<H[keyof H]>>[0]) => {
34
+ "worklet";
35
+
36
+ functionToCall?.(event);
37
+ },
38
+ eventName,
39
+ viewTag,
40
+ );
41
+ }
42
+
43
+ return null;
44
+ }),
45
+ );
46
+ };
47
+
48
+ if (viewTagRef.current) {
49
+ attachWorkletHandlers();
50
+ } else {
51
+ // view may not be mounted yet - defer registration to next event loop
52
+ setImmediate(attachWorkletHandlers);
53
+ }
35
54
 
36
55
  return () => {
37
56
  ids.forEach((id) => (id ? unregisterEventHandler(id) : null));
@@ -1,37 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _react = require("react");
8
- /**
9
- * @description
10
- * Equivalent to `useEffect` but will run the effect synchronously, i. e. before render.
11
- *
12
- * @param {effect} - imperative function
13
- * @param {deps} - if present, effect will only activate if the values in the list change
14
- *
15
- * @author Kiryl Ziusko
16
- * @since 1.13.0
17
- * @version 1.0.0
18
- */
19
- const useSyncEffect = (effect, deps) => {
20
- const cachedDeps = (0, _react.useRef)(null);
21
- const areDepsEqual = deps === null || deps === void 0 ? void 0 : deps.every((el, index) => cachedDeps.current && el === cachedDeps.current[index]);
22
- const cleanupRef = (0, _react.useRef)();
23
- if (!areDepsEqual || !cachedDeps.current) {
24
- var _cleanupRef$current;
25
- (_cleanupRef$current = cleanupRef.current) === null || _cleanupRef$current === void 0 || _cleanupRef$current.call(cleanupRef);
26
- cleanupRef.current = effect();
27
- cachedDeps.current = deps;
28
- }
29
- (0, _react.useEffect)(() => {
30
- return () => {
31
- var _cleanupRef$current2;
32
- (_cleanupRef$current2 = cleanupRef.current) === null || _cleanupRef$current2 === void 0 || _cleanupRef$current2.call(cleanupRef);
33
- };
34
- }, []);
35
- };
36
- var _default = exports.default = useSyncEffect;
37
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_react","require","useSyncEffect","effect","deps","cachedDeps","useRef","areDepsEqual","every","el","index","current","cleanupRef","_cleanupRef$current","call","useEffect","_cleanupRef$current2","_default","exports","default"],"sources":["index.ts"],"sourcesContent":["import { useEffect, useRef } from \"react\";\n\nimport type { DependencyList } from \"react\";\n\n/**\n * @description\n * Equivalent to `useEffect` but will run the effect synchronously, i. e. before render.\n *\n * @param {effect} - imperative function\n * @param {deps} - if present, effect will only activate if the values in the list change\n *\n * @author Kiryl Ziusko\n * @since 1.13.0\n * @version 1.0.0\n */\nconst useSyncEffect: typeof useEffect = (effect, deps) => {\n const cachedDeps = useRef<DependencyList | undefined | null>(null);\n const areDepsEqual = deps?.every(\n (el, index) => cachedDeps.current && el === cachedDeps.current[index],\n );\n const cleanupRef = useRef<(() => void) | void>();\n\n if (!areDepsEqual || !cachedDeps.current) {\n cleanupRef.current?.();\n cleanupRef.current = effect();\n cachedDeps.current = deps;\n }\n\n useEffect(() => {\n return () => {\n cleanupRef.current?.();\n };\n }, []);\n};\n\nexport default useSyncEffect;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,aAA+B,GAAGA,CAACC,MAAM,EAAEC,IAAI,KAAK;EACxD,MAAMC,UAAU,GAAG,IAAAC,aAAM,EAAoC,IAAI,CAAC;EAClE,MAAMC,YAAY,GAAGH,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEI,KAAK,CAC9B,CAACC,EAAE,EAAEC,KAAK,KAAKL,UAAU,CAACM,OAAO,IAAIF,EAAE,KAAKJ,UAAU,CAACM,OAAO,CAACD,KAAK,CACtE,CAAC;EACD,MAAME,UAAU,GAAG,IAAAN,aAAM,EAAsB,CAAC;EAEhD,IAAI,CAACC,YAAY,IAAI,CAACF,UAAU,CAACM,OAAO,EAAE;IAAA,IAAAE,mBAAA;IACxC,CAAAA,mBAAA,GAAAD,UAAU,CAACD,OAAO,cAAAE,mBAAA,eAAlBA,mBAAA,CAAAC,IAAA,CAAAF,UAAqB,CAAC;IACtBA,UAAU,CAACD,OAAO,GAAGR,MAAM,CAAC,CAAC;IAC7BE,UAAU,CAACM,OAAO,GAAGP,IAAI;EAC3B;EAEA,IAAAW,gBAAS,EAAC,MAAM;IACd,OAAO,MAAM;MAAA,IAAAC,oBAAA;MACX,CAAAA,oBAAA,GAAAJ,UAAU,CAACD,OAAO,cAAAK,oBAAA,eAAlBA,oBAAA,CAAAF,IAAA,CAAAF,UAAqB,CAAC;IACxB,CAAC;EACH,CAAC,EAAE,EAAE,CAAC;AACR,CAAC;AAAC,IAAAK,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEajB,aAAa","ignoreList":[]}
@@ -1,31 +0,0 @@
1
- import { useEffect, useRef } from "react";
2
- /**
3
- * @description
4
- * Equivalent to `useEffect` but will run the effect synchronously, i. e. before render.
5
- *
6
- * @param {effect} - imperative function
7
- * @param {deps} - if present, effect will only activate if the values in the list change
8
- *
9
- * @author Kiryl Ziusko
10
- * @since 1.13.0
11
- * @version 1.0.0
12
- */
13
- const useSyncEffect = (effect, deps) => {
14
- const cachedDeps = useRef(null);
15
- const areDepsEqual = deps === null || deps === void 0 ? void 0 : deps.every((el, index) => cachedDeps.current && el === cachedDeps.current[index]);
16
- const cleanupRef = useRef();
17
- if (!areDepsEqual || !cachedDeps.current) {
18
- var _cleanupRef$current;
19
- (_cleanupRef$current = cleanupRef.current) === null || _cleanupRef$current === void 0 || _cleanupRef$current.call(cleanupRef);
20
- cleanupRef.current = effect();
21
- cachedDeps.current = deps;
22
- }
23
- useEffect(() => {
24
- return () => {
25
- var _cleanupRef$current2;
26
- (_cleanupRef$current2 = cleanupRef.current) === null || _cleanupRef$current2 === void 0 || _cleanupRef$current2.call(cleanupRef);
27
- };
28
- }, []);
29
- };
30
- export default useSyncEffect;
31
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["useEffect","useRef","useSyncEffect","effect","deps","cachedDeps","areDepsEqual","every","el","index","current","cleanupRef","_cleanupRef$current","call","_cleanupRef$current2"],"sources":["index.ts"],"sourcesContent":["import { useEffect, useRef } from \"react\";\n\nimport type { DependencyList } from \"react\";\n\n/**\n * @description\n * Equivalent to `useEffect` but will run the effect synchronously, i. e. before render.\n *\n * @param {effect} - imperative function\n * @param {deps} - if present, effect will only activate if the values in the list change\n *\n * @author Kiryl Ziusko\n * @since 1.13.0\n * @version 1.0.0\n */\nconst useSyncEffect: typeof useEffect = (effect, deps) => {\n const cachedDeps = useRef<DependencyList | undefined | null>(null);\n const areDepsEqual = deps?.every(\n (el, index) => cachedDeps.current && el === cachedDeps.current[index],\n );\n const cleanupRef = useRef<(() => void) | void>();\n\n if (!areDepsEqual || !cachedDeps.current) {\n cleanupRef.current?.();\n cleanupRef.current = effect();\n cachedDeps.current = deps;\n }\n\n useEffect(() => {\n return () => {\n cleanupRef.current?.();\n };\n }, []);\n};\n\nexport default useSyncEffect;\n"],"mappings":"AAAA,SAASA,SAAS,EAAEC,MAAM,QAAQ,OAAO;AAIzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,aAA+B,GAAGA,CAACC,MAAM,EAAEC,IAAI,KAAK;EACxD,MAAMC,UAAU,GAAGJ,MAAM,CAAoC,IAAI,CAAC;EAClE,MAAMK,YAAY,GAAGF,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEG,KAAK,CAC9B,CAACC,EAAE,EAAEC,KAAK,KAAKJ,UAAU,CAACK,OAAO,IAAIF,EAAE,KAAKH,UAAU,CAACK,OAAO,CAACD,KAAK,CACtE,CAAC;EACD,MAAME,UAAU,GAAGV,MAAM,CAAsB,CAAC;EAEhD,IAAI,CAACK,YAAY,IAAI,CAACD,UAAU,CAACK,OAAO,EAAE;IAAA,IAAAE,mBAAA;IACxC,CAAAA,mBAAA,GAAAD,UAAU,CAACD,OAAO,cAAAE,mBAAA,eAAlBA,mBAAA,CAAAC,IAAA,CAAAF,UAAqB,CAAC;IACtBA,UAAU,CAACD,OAAO,GAAGP,MAAM,CAAC,CAAC;IAC7BE,UAAU,CAACK,OAAO,GAAGN,IAAI;EAC3B;EAEAJ,SAAS,CAAC,MAAM;IACd,OAAO,MAAM;MAAA,IAAAc,oBAAA;MACX,CAAAA,oBAAA,GAAAH,UAAU,CAACD,OAAO,cAAAI,oBAAA,eAAlBA,oBAAA,CAAAD,IAAA,CAAAF,UAAqB,CAAC;IACxB,CAAC;EACH,CAAC,EAAE,EAAE,CAAC;AACR,CAAC;AAED,eAAeT,aAAa","ignoreList":[]}
@@ -1,14 +0,0 @@
1
- import { useEffect } from "react";
2
- /**
3
- * @description
4
- * Equivalent to `useEffect` but will run the effect synchronously, i. e. before render.
5
- *
6
- * @param {effect} - imperative function
7
- * @param {deps} - if present, effect will only activate if the values in the list change
8
- *
9
- * @author Kiryl Ziusko
10
- * @since 1.13.0
11
- * @version 1.0.0
12
- */
13
- declare const useSyncEffect: typeof useEffect;
14
- export default useSyncEffect;
@@ -1,36 +0,0 @@
1
- import { useEffect, useRef } from "react";
2
-
3
- import type { DependencyList } from "react";
4
-
5
- /**
6
- * @description
7
- * Equivalent to `useEffect` but will run the effect synchronously, i. e. before render.
8
- *
9
- * @param {effect} - imperative function
10
- * @param {deps} - if present, effect will only activate if the values in the list change
11
- *
12
- * @author Kiryl Ziusko
13
- * @since 1.13.0
14
- * @version 1.0.0
15
- */
16
- const useSyncEffect: typeof useEffect = (effect, deps) => {
17
- const cachedDeps = useRef<DependencyList | undefined | null>(null);
18
- const areDepsEqual = deps?.every(
19
- (el, index) => cachedDeps.current && el === cachedDeps.current[index],
20
- );
21
- const cleanupRef = useRef<(() => void) | void>();
22
-
23
- if (!areDepsEqual || !cachedDeps.current) {
24
- cleanupRef.current?.();
25
- cleanupRef.current = effect();
26
- cachedDeps.current = deps;
27
- }
28
-
29
- useEffect(() => {
30
- return () => {
31
- cleanupRef.current?.();
32
- };
33
- }, []);
34
- };
35
-
36
- export default useSyncEffect;