@react-native-ohos/react-native-keyboard-controller 1.17.0-beta.2 → 1.17.0
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.
- package/LICENSE +21 -21
- package/README.OpenSource +11 -11
- package/README.md +686 -19
- package/harmony/keyboard_controller/BuildProfile.ets +16 -16
- package/harmony/keyboard_controller/Index.ets +29 -28
- package/harmony/keyboard_controller/build-profile.json5 +31 -31
- package/harmony/keyboard_controller/hvigorfile.ts +6 -6
- package/harmony/keyboard_controller/obfuscation-rules.txt +17 -17
- package/harmony/keyboard_controller/oh-package-lock.json5 +28 -18
- package/harmony/keyboard_controller/oh-package.json5 +10 -10
- package/harmony/keyboard_controller/src/main/cpp/CMakeLists.txt +7 -7
- package/harmony/keyboard_controller/src/main/cpp/ClippingScrollViewComponentDescriptor.h +86 -0
- package/harmony/keyboard_controller/src/main/cpp/ClippingScrollViewComponentInstance.cpp +104 -0
- package/harmony/keyboard_controller/src/main/cpp/ClippingScrollViewComponentInstance.h +64 -0
- package/harmony/keyboard_controller/src/main/cpp/ClippingScrollViewJSIBinder.h +60 -0
- package/harmony/keyboard_controller/src/main/cpp/EventEmitters.cpp +119 -96
- package/harmony/keyboard_controller/src/main/cpp/EventEmitters.h +111 -111
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentDescriptor.h +94 -94
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentInstance.cpp +840 -288
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentInstance.h +169 -103
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewJSIBinder.h +65 -65
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentDescriptor.h +79 -79
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentInstance.cpp +108 -108
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentInstance.h +83 -83
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaJSIBinder.h +60 -60
- package/harmony/keyboard_controller/src/main/cpp/KeyboardToolbarGroupViewComponentDescriptor.h +46 -0
- package/harmony/keyboard_controller/src/main/cpp/KeyboardToolbarGroupViewComponentInstance.cpp +37 -0
- package/harmony/keyboard_controller/src/main/cpp/KeyboardToolbarGroupViewComponentInstance.h +32 -0
- package/harmony/keyboard_controller/src/main/cpp/KeyboardToolbarGroupViewJSIBinder.h +23 -0
- package/harmony/keyboard_controller/src/main/cpp/RNKeyboardController.cpp +103 -46
- package/harmony/keyboard_controller/src/main/cpp/RNKeyboardController.h +48 -48
- package/harmony/keyboard_controller/src/main/cpp/RNKeyboardControllerPackage.h +20 -0
- package/harmony/keyboard_controller/src/main/cpp/RNStatusBarManagerCompat.cpp +45 -45
- package/harmony/keyboard_controller/src/main/cpp/RNStatusBarManagerCompat.h +49 -49
- package/harmony/keyboard_controller/src/main/cpp/ViewHierarchyNavigator.cpp +207 -186
- package/harmony/keyboard_controller/src/main/cpp/ViewHierarchyNavigator.h +131 -112
- package/harmony/keyboard_controller/src/main/cpp/keyboardControllerPackage.cpp +77 -64
- package/harmony/keyboard_controller/src/main/cpp/keyboardControllerPackage.h +85 -77
- package/harmony/keyboard_controller/src/main/ets/Logger.ts +66 -66
- package/harmony/keyboard_controller/src/main/ets/{RNKeyboardControllerPackage.ts → RNKeyboardControllerPackage.ets} +70 -66
- package/harmony/keyboard_controller/src/main/ets/RNKeyboardControllerTurboModule.ts +465 -273
- package/harmony/keyboard_controller/src/main/ets/RNStatusBarManagerCompatTurboModule.ts +128 -119
- package/harmony/keyboard_controller/src/main/ets/Type.ts +63 -62
- package/harmony/keyboard_controller/src/main/module.json5 +11 -11
- package/harmony/keyboard_controller/src/main/resources/base/element/string.json +8 -8
- package/harmony/keyboard_controller/src/main/resources/en_US/element/string.json +8 -8
- package/harmony/keyboard_controller/src/main/resources/zh_CN/element/string.json +8 -8
- package/harmony/keyboard_controller/{ts.ts → ts.ets} +29 -29
- package/harmony/keyboard_controller.har +0 -0
- package/lib/commonjs/animated.js +22 -11
- package/lib/commonjs/animated.js.map +1 -1
- package/lib/commonjs/architecture.js +8 -0
- package/lib/commonjs/architecture.js.map +1 -0
- package/lib/commonjs/bindings.js +40 -5
- package/lib/commonjs/bindings.js.map +1 -1
- package/lib/commonjs/bindings.native.js +28 -5
- package/lib/commonjs/bindings.native.js.map +1 -1
- package/lib/commonjs/compat.js +50 -0
- package/lib/commonjs/compat.js.map +1 -0
- package/lib/commonjs/components/KeyboardAvoidingView/hooks.js +21 -15
- package/lib/commonjs/components/KeyboardAvoidingView/hooks.js.map +1 -1
- package/lib/commonjs/components/KeyboardAvoidingView/index.js +39 -14
- package/lib/commonjs/components/KeyboardAvoidingView/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js +94 -57
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +5 -5
- package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -1
- package/lib/commonjs/components/KeyboardAwareScrollView/utils.js.map +1 -1
- package/lib/commonjs/components/KeyboardChatScrollView/hooks.js +13 -0
- package/lib/commonjs/components/KeyboardChatScrollView/hooks.js.map +1 -0
- package/lib/commonjs/components/KeyboardChatScrollView/index.js +122 -0
- package/lib/commonjs/components/KeyboardChatScrollView/index.js.map +1 -0
- package/lib/commonjs/components/KeyboardChatScrollView/types.js +6 -0
- package/lib/commonjs/components/KeyboardChatScrollView/types.js.map +1 -0
- package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/helpers.js +221 -0
- package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/helpers.js.map +1 -0
- package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js +149 -0
- package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js.map +1 -0
- package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.js +240 -0
- package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.js.map +1 -0
- package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/types.js +6 -0
- package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/types.js.map +1 -0
- package/lib/commonjs/components/KeyboardChatScrollView/useEndVisible.js +40 -0
- package/lib/commonjs/components/KeyboardChatScrollView/useEndVisible.js.map +1 -0
- package/lib/commonjs/components/KeyboardChatScrollView/useExtraContentPadding/index.js +92 -0
- package/lib/commonjs/components/KeyboardChatScrollView/useExtraContentPadding/index.js.map +1 -0
- package/lib/commonjs/components/KeyboardStickyView/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardToolbar/Arrow.js +2 -3
- package/lib/commonjs/components/KeyboardToolbar/Arrow.js.map +1 -1
- package/lib/commonjs/components/KeyboardToolbar/Button.js +2 -3
- package/lib/commonjs/components/KeyboardToolbar/Button.js.map +1 -1
- package/lib/commonjs/components/KeyboardToolbar/colors.js.map +1 -1
- package/lib/commonjs/components/KeyboardToolbar/colors.native.js.map +1 -1
- package/lib/commonjs/components/KeyboardToolbar/compound/components/Background.js +13 -0
- package/lib/commonjs/components/KeyboardToolbar/compound/components/Background.js.map +1 -0
- package/lib/commonjs/components/KeyboardToolbar/compound/components/Content.js +25 -0
- package/lib/commonjs/components/KeyboardToolbar/compound/components/Content.js.map +1 -0
- package/lib/commonjs/components/KeyboardToolbar/compound/components/Done.js +58 -0
- package/lib/commonjs/components/KeyboardToolbar/compound/components/Done.js.map +1 -0
- package/lib/commonjs/components/KeyboardToolbar/compound/components/Next.js +49 -0
- package/lib/commonjs/components/KeyboardToolbar/compound/components/Next.js.map +1 -0
- package/lib/commonjs/components/KeyboardToolbar/compound/components/Prev.js +49 -0
- package/lib/commonjs/components/KeyboardToolbar/compound/components/Prev.js.map +1 -0
- package/lib/commonjs/components/KeyboardToolbar/compound/components/index.js +42 -0
- package/lib/commonjs/components/KeyboardToolbar/compound/components/index.js.map +1 -0
- package/lib/commonjs/components/KeyboardToolbar/compound/components/types.js +6 -0
- package/lib/commonjs/components/KeyboardToolbar/compound/components/types.js.map +1 -0
- package/lib/commonjs/components/KeyboardToolbar/compound/context.js +17 -0
- package/lib/commonjs/components/KeyboardToolbar/compound/context.js.map +1 -0
- package/lib/commonjs/components/KeyboardToolbar/constants.js +17 -0
- package/lib/commonjs/components/KeyboardToolbar/constants.js.map +1 -0
- package/lib/commonjs/components/KeyboardToolbar/index.js +98 -87
- package/lib/commonjs/components/KeyboardToolbar/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardToolbar/types.js.map +1 -1
- package/lib/commonjs/components/ScrollViewWithBottomPadding/index.js +120 -0
- package/lib/commonjs/components/ScrollViewWithBottomPadding/index.js.map +1 -0
- package/lib/commonjs/components/ScrollViewWithBottomPadding/styles.js +15 -0
- package/lib/commonjs/components/ScrollViewWithBottomPadding/styles.js.map +1 -0
- package/lib/commonjs/components/hooks/useColorScheme.js.map +1 -1
- package/lib/commonjs/components/hooks/useCombinedRef.js +24 -0
- package/lib/commonjs/components/hooks/useCombinedRef.js.map +1 -0
- package/lib/commonjs/components/hooks/useScrollState.js +62 -0
- package/lib/commonjs/components/hooks/useScrollState.js.map +1 -0
- package/lib/commonjs/components/index.js +7 -0
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/constants.js +3 -1
- package/lib/commonjs/constants.js.map +1 -1
- package/lib/commonjs/context.js +1 -0
- package/lib/commonjs/context.js.map +1 -1
- package/lib/commonjs/hooks/index.js +14 -1
- package/lib/commonjs/hooks/index.js.map +1 -1
- package/lib/commonjs/hooks/useKeyboardState/index.js +39 -0
- package/lib/commonjs/hooks/useKeyboardState/index.js.map +1 -0
- package/lib/commonjs/hooks/useWindowDimensions/index.android.js.map +1 -1
- package/lib/commonjs/hooks/useWindowDimensions/index.js.map +1 -1
- package/lib/commonjs/index.js +27 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/internal.js +54 -18
- package/lib/commonjs/internal.js.map +1 -1
- package/lib/commonjs/module.js +21 -12
- package/lib/commonjs/module.js.map +1 -1
- package/lib/commonjs/reanimated.js.map +1 -1
- package/lib/commonjs/reanimated.native.js.map +1 -1
- package/lib/commonjs/specs/ClippingScrollViewDecoratorViewNativeComponent.js +12 -0
- package/lib/commonjs/specs/ClippingScrollViewDecoratorViewNativeComponent.js.map +1 -0
- package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js +8 -2
- package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/KeyboardGestureAreaNativeComponent.js +2 -1
- package/lib/commonjs/specs/KeyboardGestureAreaNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/KeyboardToolbarGroupViewNativeComponent.js +12 -0
- package/lib/commonjs/specs/KeyboardToolbarGroupViewNativeComponent.js.map +1 -0
- package/lib/commonjs/specs/NativeKeyboardController.js.map +1 -1
- package/lib/commonjs/specs/NativeStatusBarManagerCompat.js.map +1 -1
- package/lib/commonjs/specs/OverKeyboardViewNativeComponent.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/utils/findNodeHandle/index.js +9 -0
- package/lib/commonjs/utils/findNodeHandle/index.js.map +1 -0
- package/lib/commonjs/utils/findNodeHandle/index.native.js +13 -0
- package/lib/commonjs/utils/findNodeHandle/index.native.js.map +1 -0
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/commonjs/views/KeyboardExtender/index.js +30 -0
- package/lib/commonjs/views/KeyboardExtender/index.js.map +1 -0
- package/lib/commonjs/views/OverKeyboardView/index.js.map +1 -1
- package/lib/commonjs/views/index.js +7 -0
- package/lib/commonjs/views/index.js.map +1 -1
- package/lib/module/animated.js +24 -13
- package/lib/module/animated.js.map +1 -1
- package/lib/module/architecture.js +2 -0
- package/lib/module/architecture.js.map +1 -0
- package/lib/module/bindings.js +39 -5
- package/lib/module/bindings.js.map +1 -1
- package/lib/module/bindings.native.js +27 -5
- package/lib/module/bindings.native.js.map +1 -1
- package/lib/module/compat.js +43 -0
- package/lib/module/compat.js.map +1 -0
- package/lib/module/components/KeyboardAvoidingView/hooks.js +22 -16
- package/lib/module/components/KeyboardAvoidingView/hooks.js.map +1 -1
- package/lib/module/components/KeyboardAvoidingView/index.js +38 -14
- package/lib/module/components/KeyboardAvoidingView/index.js.map +1 -1
- package/lib/module/components/KeyboardAwareScrollView/index.js +97 -60
- package/lib/module/components/KeyboardAwareScrollView/index.js.map +1 -1
- package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +5 -5
- package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -1
- package/lib/module/components/KeyboardAwareScrollView/utils.js.map +1 -1
- package/lib/module/components/KeyboardChatScrollView/hooks.js +2 -0
- package/lib/module/components/KeyboardChatScrollView/hooks.js.map +1 -0
- package/lib/module/components/KeyboardChatScrollView/index.js +115 -0
- package/lib/module/components/KeyboardChatScrollView/index.js.map +1 -0
- package/lib/module/components/KeyboardChatScrollView/types.js +2 -0
- package/lib/module/components/KeyboardChatScrollView/types.js.map +1 -0
- package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/helpers.js +207 -0
- package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/helpers.js.map +1 -0
- package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js +143 -0
- package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js.map +1 -0
- package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.js +234 -0
- package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.js.map +1 -0
- package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/types.js +2 -0
- package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/types.js.map +1 -0
- package/lib/module/components/KeyboardChatScrollView/useEndVisible.js +33 -0
- package/lib/module/components/KeyboardChatScrollView/useEndVisible.js.map +1 -0
- package/lib/module/components/KeyboardChatScrollView/useExtraContentPadding/index.js +87 -0
- package/lib/module/components/KeyboardChatScrollView/useExtraContentPadding/index.js.map +1 -0
- package/lib/module/components/KeyboardStickyView/index.js.map +1 -1
- package/lib/module/components/KeyboardToolbar/Arrow.js +2 -2
- package/lib/module/components/KeyboardToolbar/Arrow.js.map +1 -1
- package/lib/module/components/KeyboardToolbar/Button.js +2 -2
- package/lib/module/components/KeyboardToolbar/Button.js.map +1 -1
- package/lib/module/components/KeyboardToolbar/colors.js.map +1 -1
- package/lib/module/components/KeyboardToolbar/colors.native.js.map +1 -1
- package/lib/module/components/KeyboardToolbar/compound/components/Background.js +6 -0
- package/lib/module/components/KeyboardToolbar/compound/components/Background.js.map +1 -0
- package/lib/module/components/KeyboardToolbar/compound/components/Content.js +18 -0
- package/lib/module/components/KeyboardToolbar/compound/components/Content.js.map +1 -0
- package/lib/module/components/KeyboardToolbar/compound/components/Done.js +50 -0
- package/lib/module/components/KeyboardToolbar/compound/components/Done.js.map +1 -0
- package/lib/module/components/KeyboardToolbar/compound/components/Next.js +41 -0
- package/lib/module/components/KeyboardToolbar/compound/components/Next.js.map +1 -0
- package/lib/module/components/KeyboardToolbar/compound/components/Prev.js +41 -0
- package/lib/module/components/KeyboardToolbar/compound/components/Prev.js.map +1 -0
- package/lib/module/components/KeyboardToolbar/compound/components/index.js +6 -0
- package/lib/module/components/KeyboardToolbar/compound/components/index.js.map +1 -0
- package/lib/module/components/KeyboardToolbar/compound/components/types.js +2 -0
- package/lib/module/components/KeyboardToolbar/compound/components/types.js.map +1 -0
- package/lib/module/components/KeyboardToolbar/compound/context.js +10 -0
- package/lib/module/components/KeyboardToolbar/compound/context.js.map +1 -0
- package/lib/module/components/KeyboardToolbar/constants.js +11 -0
- package/lib/module/components/KeyboardToolbar/constants.js.map +1 -0
- package/lib/module/components/KeyboardToolbar/index.js +98 -88
- package/lib/module/components/KeyboardToolbar/index.js.map +1 -1
- package/lib/module/components/KeyboardToolbar/types.js.map +1 -1
- package/lib/module/components/ScrollViewWithBottomPadding/index.js +112 -0
- package/lib/module/components/ScrollViewWithBottomPadding/index.js.map +1 -0
- package/lib/module/components/ScrollViewWithBottomPadding/styles.js +9 -0
- package/lib/module/components/ScrollViewWithBottomPadding/styles.js.map +1 -0
- package/lib/module/components/hooks/useColorScheme.js.map +1 -1
- package/lib/module/components/hooks/useCombinedRef.js +18 -0
- package/lib/module/components/hooks/useCombinedRef.js.map +1 -0
- package/lib/module/components/hooks/useScrollState.js +56 -0
- package/lib/module/components/hooks/useScrollState.js.map +1 -0
- package/lib/module/components/index.js +1 -0
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/constants.js +3 -0
- package/lib/module/constants.js.map +1 -1
- package/lib/module/context.js +1 -0
- package/lib/module/context.js.map +1 -1
- package/lib/module/hooks/index.js +3 -1
- package/lib/module/hooks/index.js.map +1 -1
- package/lib/module/hooks/useKeyboardState/index.js +33 -0
- package/lib/module/hooks/useKeyboardState/index.js.map +1 -0
- package/lib/module/hooks/useWindowDimensions/index.android.js.map +1 -1
- package/lib/module/hooks/useWindowDimensions/index.js.map +1 -1
- package/lib/module/index.js +3 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/internal.js +53 -18
- package/lib/module/internal.js.map +1 -1
- package/lib/module/module.js +21 -12
- package/lib/module/module.js.map +1 -1
- package/lib/module/reanimated.js.map +1 -1
- package/lib/module/reanimated.native.js.map +1 -1
- package/lib/module/specs/ClippingScrollViewDecoratorViewNativeComponent.js +6 -0
- package/lib/module/specs/ClippingScrollViewDecoratorViewNativeComponent.js.map +1 -0
- package/lib/module/specs/KeyboardControllerViewNativeComponent.js +7 -1
- package/lib/module/specs/KeyboardControllerViewNativeComponent.js.map +1 -1
- package/lib/module/specs/KeyboardGestureAreaNativeComponent.js +2 -1
- package/lib/module/specs/KeyboardGestureAreaNativeComponent.js.map +1 -1
- package/lib/module/specs/KeyboardToolbarGroupViewNativeComponent.js +5 -0
- package/lib/module/specs/KeyboardToolbarGroupViewNativeComponent.js.map +1 -0
- package/lib/module/specs/NativeKeyboardController.js.map +1 -1
- package/lib/module/specs/NativeStatusBarManagerCompat.js.map +1 -1
- package/lib/module/specs/OverKeyboardViewNativeComponent.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils/findNodeHandle/index.js +2 -0
- package/lib/module/utils/findNodeHandle/index.js.map +1 -0
- package/lib/module/utils/findNodeHandle/index.native.js +3 -0
- package/lib/module/utils/findNodeHandle/index.native.js.map +1 -0
- package/lib/module/utils.js.map +1 -1
- package/lib/module/views/KeyboardExtender/index.js +23 -0
- package/lib/module/views/KeyboardExtender/index.js.map +1 -0
- package/lib/module/views/OverKeyboardView/index.js.map +1 -1
- package/lib/module/views/index.js +1 -0
- package/lib/module/views/index.js.map +1 -1
- package/lib/typescript/animated.d.ts +2 -38
- package/lib/typescript/architecture.d.ts +1 -0
- package/lib/typescript/bindings.d.ts +15 -1
- package/lib/typescript/bindings.native.d.ts +10 -1
- package/lib/typescript/compat.d.ts +12 -0
- package/lib/typescript/components/KeyboardAvoidingView/index.d.ts +5 -0
- package/lib/typescript/components/KeyboardAwareScrollView/index.d.ts +4 -1
- package/lib/typescript/components/KeyboardChatScrollView/hooks.d.ts +2 -0
- package/lib/typescript/components/KeyboardChatScrollView/index.d.ts +17 -0
- package/lib/typescript/components/KeyboardChatScrollView/types.d.ts +113 -0
- package/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/helpers.d.ts +132 -0
- package/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/index.d.ts +18 -0
- package/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/index.ios.d.ts +21 -0
- package/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/types.d.ts +37 -0
- package/lib/typescript/components/KeyboardChatScrollView/useEndVisible.d.ts +17 -0
- package/lib/typescript/components/KeyboardChatScrollView/useExtraContentPadding/index.d.ts +45 -0
- package/lib/typescript/components/KeyboardToolbar/Button.d.ts +2 -2
- package/lib/typescript/components/KeyboardToolbar/compound/components/Background.d.ts +6 -0
- package/lib/typescript/components/KeyboardToolbar/compound/components/Content.d.ts +7 -0
- package/lib/typescript/components/KeyboardToolbar/compound/components/Done.d.ts +7 -0
- package/lib/typescript/components/KeyboardToolbar/compound/components/Next.d.ts +4 -0
- package/lib/typescript/components/KeyboardToolbar/compound/components/Prev.d.ts +4 -0
- package/lib/typescript/components/KeyboardToolbar/compound/components/index.d.ts +5 -0
- package/lib/typescript/components/KeyboardToolbar/compound/components/types.d.ts +14 -0
- package/lib/typescript/components/KeyboardToolbar/compound/context.d.ts +9 -0
- package/lib/typescript/components/KeyboardToolbar/constants.d.ts +10 -0
- package/lib/typescript/components/KeyboardToolbar/index.d.ts +12 -45
- package/lib/typescript/components/KeyboardToolbar/types.d.ts +24 -1
- package/lib/typescript/components/ScrollViewWithBottomPadding/index.d.ts +30 -0
- package/lib/typescript/components/ScrollViewWithBottomPadding/styles.d.ts +7 -0
- package/lib/typescript/components/hooks/useCombinedRef.d.ts +3 -0
- package/lib/typescript/components/hooks/useScrollState.d.ts +17 -0
- package/lib/typescript/components/index.d.ts +3 -0
- package/lib/typescript/constants.d.ts +1 -0
- package/lib/typescript/context.d.ts +1 -0
- package/lib/typescript/hooks/index.d.ts +2 -0
- package/lib/typescript/hooks/useKeyboardState/index.d.ts +4 -0
- package/lib/typescript/index.d.ts +4 -3
- package/lib/typescript/internal.d.ts +4 -0
- package/lib/typescript/specs/ClippingScrollViewDecoratorViewNativeComponent.d.ts +10 -0
- package/lib/typescript/specs/KeyboardControllerViewNativeComponent.d.ts +4 -0
- package/lib/typescript/specs/KeyboardToolbarGroupViewNativeComponent.d.ts +6 -0
- package/lib/typescript/specs/NativeKeyboardController.d.ts +6 -2
- package/lib/typescript/types.d.ts +81 -5
- package/lib/typescript/utils/findNodeHandle/index.d.ts +4 -0
- package/lib/typescript/utils/findNodeHandle/index.native.d.ts +2 -0
- package/lib/typescript/views/KeyboardExtender/index.d.ts +5 -0
- package/lib/typescript/views/index.d.ts +1 -0
- package/package.json +183 -174
- package/src/animated.tsx +248 -255
- package/src/architecture.ts +1 -0
- package/src/bindings.native.ts +97 -62
- package/src/bindings.ts +81 -42
- package/src/compat.ts +44 -0
- package/src/components/KeyboardAvoidingView/hooks.ts +130 -123
- package/src/components/KeyboardAvoidingView/index.tsx +232 -188
- package/src/components/KeyboardAwareScrollView/index.tsx +452 -389
- package/src/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.ts +133 -133
- package/src/components/KeyboardAwareScrollView/utils.ts +41 -41
- package/src/components/KeyboardChatScrollView/hooks.ts +2 -0
- package/src/components/KeyboardChatScrollView/index.tsx +164 -0
- package/src/components/KeyboardChatScrollView/types.ts +117 -0
- package/src/components/KeyboardChatScrollView/useChatKeyboard/helpers.ts +268 -0
- package/src/components/KeyboardChatScrollView/useChatKeyboard/index.ios.ts +260 -0
- package/src/components/KeyboardChatScrollView/useChatKeyboard/index.ts +374 -0
- package/src/components/KeyboardChatScrollView/useChatKeyboard/types.ts +39 -0
- package/src/components/KeyboardChatScrollView/useEndVisible.ts +66 -0
- package/src/components/KeyboardChatScrollView/useExtraContentPadding/index.ts +149 -0
- package/src/components/KeyboardStickyView/index.tsx +66 -66
- package/src/components/KeyboardToolbar/Arrow.tsx +80 -80
- package/src/components/KeyboardToolbar/Button.tsx +98 -98
- package/src/components/KeyboardToolbar/colors.native.ts +37 -37
- package/src/components/KeyboardToolbar/colors.ts +16 -16
- package/src/components/KeyboardToolbar/compound/components/Background.tsx +9 -0
- package/src/components/KeyboardToolbar/compound/components/Content.tsx +25 -0
- package/src/components/KeyboardToolbar/compound/components/Done.tsx +57 -0
- package/src/components/KeyboardToolbar/compound/components/Next.tsx +49 -0
- package/src/components/KeyboardToolbar/compound/components/Prev.tsx +49 -0
- package/src/components/KeyboardToolbar/compound/components/index.ts +5 -0
- package/src/components/KeyboardToolbar/compound/components/types.ts +15 -0
- package/src/components/KeyboardToolbar/compound/context.ts +25 -0
- package/src/components/KeyboardToolbar/constants.ts +14 -0
- package/src/components/KeyboardToolbar/index.tsx +220 -223
- package/src/components/KeyboardToolbar/types.ts +72 -40
- package/src/components/ScrollViewWithBottomPadding/index.tsx +216 -0
- package/src/components/ScrollViewWithBottomPadding/styles.ts +10 -0
- package/src/components/hooks/useColorScheme.ts +6 -6
- package/src/components/hooks/useCombinedRef.ts +22 -0
- package/src/components/hooks/useScrollState.ts +81 -0
- package/src/components/index.ts +14 -11
- package/src/constants.ts +23 -19
- package/src/context.ts +70 -68
- package/src/hooks/index.ts +91 -90
- package/src/hooks/useKeyboardState/index.ts +52 -0
- package/src/hooks/useWindowDimensions/index.android.ts +38 -38
- package/src/hooks/useWindowDimensions/index.ts +1 -1
- package/src/index.ts +27 -23
- package/src/internal.ts +146 -84
- package/src/module.ts +64 -52
- package/src/reanimated.native.ts +132 -132
- package/src/reanimated.ts +29 -29
- package/src/specs/ClippingScrollViewDecoratorViewNativeComponent.ts +19 -0
- package/src/specs/KeyboardControllerViewNativeComponent.ts +82 -71
- package/src/specs/KeyboardGestureAreaNativeComponent.ts +21 -20
- package/src/specs/KeyboardToolbarGroupViewNativeComponent.ts +10 -0
- package/src/specs/NativeKeyboardController.ts +23 -19
- package/src/specs/NativeStatusBarManagerCompat.ts +14 -14
- package/src/specs/OverKeyboardViewNativeComponent.ts +12 -12
- package/src/types.ts +330 -243
- package/src/utils/findNodeHandle/index.native.ts +3 -0
- package/src/utils/findNodeHandle/index.ts +6 -0
- package/src/utils.ts +1 -1
- package/src/views/KeyboardExtender/index.tsx +30 -0
- package/src/views/OverKeyboardView/index.tsx +43 -43
- package/src/views/index.ts +2 -1
- package/lib/commonjs/monkey-patch.android.js +0 -57
- package/lib/commonjs/monkey-patch.android.js.map +0 -1
- package/lib/commonjs/monkey-patch.js +0 -11
- package/lib/commonjs/monkey-patch.js.map +0 -1
- package/lib/module/monkey-patch.android.js +0 -47
- package/lib/module/monkey-patch.android.js.map +0 -1
- package/lib/module/monkey-patch.js +0 -5
- package/lib/module/monkey-patch.js.map +0 -1
- package/lib/typescript/monkey-patch.android.d.ts +0 -2
- package/lib/typescript/monkey-patch.d.ts +0 -2
- package/src/monkey-patch.android.ts +0 -44
- package/src/monkey-patch.ts +0 -4
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import { scrollTo, useSharedValue } from "react-native-reanimated";
|
|
2
|
+
|
|
3
|
+
import { useKeyboardHandler } from "../../../hooks";
|
|
4
|
+
import useScrollState from "../../hooks/useScrollState";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
clampedScrollTarget,
|
|
8
|
+
getEffectiveHeight,
|
|
9
|
+
getMinimumPaddingAbsorbed,
|
|
10
|
+
getScrollEffective,
|
|
11
|
+
getVisibleMinimumPaddingFraction,
|
|
12
|
+
isScrollAtEnd,
|
|
13
|
+
shouldShiftContent,
|
|
14
|
+
} from "./helpers";
|
|
15
|
+
|
|
16
|
+
import type { UseChatKeyboardOptions, UseChatKeyboardReturn } from "./types";
|
|
17
|
+
import type { AnimatedRef } from "react-native-reanimated";
|
|
18
|
+
import type Reanimated from "react-native-reanimated";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Hook that manages keyboard-driven scrolling for chat-style scroll views.
|
|
22
|
+
* Calculates padding (extra scrollable space) and content shift values,
|
|
23
|
+
* using per-frame scrollTo updates (Android and other platforms).
|
|
24
|
+
*
|
|
25
|
+
* @param scrollViewRef - Animated ref to the scroll view.
|
|
26
|
+
* @param options - Configuration for inverted and keyboardLiftBehavior.
|
|
27
|
+
* @returns Shared values for padding and contentOffsetY (always `undefined`).
|
|
28
|
+
* @example
|
|
29
|
+
* ```tsx
|
|
30
|
+
* const { padding } = useChatKeyboard(ref, { inverted: false, keyboardLiftBehavior: "always" });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
function useChatKeyboard(
|
|
34
|
+
scrollViewRef: AnimatedRef<Reanimated.ScrollView>,
|
|
35
|
+
options: UseChatKeyboardOptions,
|
|
36
|
+
): UseChatKeyboardReturn {
|
|
37
|
+
const {
|
|
38
|
+
inverted,
|
|
39
|
+
keyboardLiftBehavior,
|
|
40
|
+
freeze,
|
|
41
|
+
offset,
|
|
42
|
+
blankSpace,
|
|
43
|
+
extraContentPadding,
|
|
44
|
+
} = options;
|
|
45
|
+
|
|
46
|
+
const padding = useSharedValue(0);
|
|
47
|
+
const currentHeight = useSharedValue(0);
|
|
48
|
+
const offsetBeforeScroll = useSharedValue(0);
|
|
49
|
+
const targetKeyboardHeight = useSharedValue(0);
|
|
50
|
+
const closing = useSharedValue(false);
|
|
51
|
+
const minimumPaddingFractionOnOpen = useSharedValue(0);
|
|
52
|
+
const actualOpenShift = useSharedValue(0);
|
|
53
|
+
const {
|
|
54
|
+
layout,
|
|
55
|
+
size,
|
|
56
|
+
offset: scroll,
|
|
57
|
+
onLayout,
|
|
58
|
+
onContentSizeChange,
|
|
59
|
+
} = useScrollState(scrollViewRef);
|
|
60
|
+
const clampScrollIfNeeded = (
|
|
61
|
+
effective: number,
|
|
62
|
+
totalPaddingForMaxScroll?: number,
|
|
63
|
+
) => {
|
|
64
|
+
"worklet";
|
|
65
|
+
|
|
66
|
+
const paddingForMax =
|
|
67
|
+
totalPaddingForMaxScroll !== undefined
|
|
68
|
+
? totalPaddingForMaxScroll
|
|
69
|
+
: effective;
|
|
70
|
+
const maxScroll = Math.max(
|
|
71
|
+
size.value.height - layout.value.height + paddingForMax,
|
|
72
|
+
0,
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
if (scroll.value > maxScroll) {
|
|
76
|
+
scrollTo(scrollViewRef, 0, maxScroll, false);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
useKeyboardHandler(
|
|
81
|
+
{
|
|
82
|
+
onStart: (e) => {
|
|
83
|
+
"worklet";
|
|
84
|
+
|
|
85
|
+
if (freeze.value) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (e.height > 0) {
|
|
90
|
+
// eslint-disable-next-line react-compiler/react-compiler
|
|
91
|
+
targetKeyboardHeight.value = e.height;
|
|
92
|
+
closing.value = false;
|
|
93
|
+
} else {
|
|
94
|
+
closing.value = true;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const effective = getEffectiveHeight(
|
|
98
|
+
e.height,
|
|
99
|
+
targetKeyboardHeight.value,
|
|
100
|
+
offset,
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
const atEnd = isScrollAtEnd(
|
|
104
|
+
scroll.value,
|
|
105
|
+
layout.value.height,
|
|
106
|
+
size.value.height,
|
|
107
|
+
inverted,
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
// Scale minimum padding absorption by how much of it is visible.
|
|
111
|
+
// Fully visible → full absorption; fully off-screen → no absorption.
|
|
112
|
+
const visibleFraction = getVisibleMinimumPaddingFraction(
|
|
113
|
+
scroll.value,
|
|
114
|
+
layout.value.height,
|
|
115
|
+
size.value.height,
|
|
116
|
+
blankSpace.value,
|
|
117
|
+
inverted,
|
|
118
|
+
);
|
|
119
|
+
const minimumPaddingAbsorbed =
|
|
120
|
+
visibleFraction >= 1
|
|
121
|
+
? getMinimumPaddingAbsorbed(
|
|
122
|
+
blankSpace.value,
|
|
123
|
+
extraContentPadding.value,
|
|
124
|
+
)
|
|
125
|
+
: 0;
|
|
126
|
+
const scrollEffective = getScrollEffective(
|
|
127
|
+
effective,
|
|
128
|
+
minimumPaddingAbsorbed,
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
if (inverted && e.duration === -1) {
|
|
132
|
+
// Android inverted: skip post-interactive snap-back events
|
|
133
|
+
// (duration === -1 means the keyboard is re-establishing its
|
|
134
|
+
// position after an interactive gesture, not a real animation)
|
|
135
|
+
return;
|
|
136
|
+
} else if (e.height > 0) {
|
|
137
|
+
// Android: keyboard opening — set padding + capture scroll position
|
|
138
|
+
minimumPaddingFractionOnOpen.value = visibleFraction >= 1 ? 1 : 0;
|
|
139
|
+
padding.value = effective;
|
|
140
|
+
offsetBeforeScroll.value = scroll.value;
|
|
141
|
+
|
|
142
|
+
if (!inverted && keyboardLiftBehavior === "whenAtEnd" && !atEnd) {
|
|
143
|
+
// Sentinel: don't scroll in onMove (non-inverted only)
|
|
144
|
+
offsetBeforeScroll.value = -1;
|
|
145
|
+
} else if (!inverted && scrollEffective === 0) {
|
|
146
|
+
// blankSpace fully absorbs the keyboard — prevent scroll
|
|
147
|
+
offsetBeforeScroll.value = -1;
|
|
148
|
+
} else if (inverted && scrollEffective === 0) {
|
|
149
|
+
// blankSpace fully absorbs the keyboard — guard for inverted
|
|
150
|
+
offsetBeforeScroll.value = scroll.value;
|
|
151
|
+
}
|
|
152
|
+
} else {
|
|
153
|
+
// Android: keyboard closing — re-capture scroll position
|
|
154
|
+
if (inverted) {
|
|
155
|
+
offsetBeforeScroll.value = scroll.value;
|
|
156
|
+
} else {
|
|
157
|
+
// Preserve "whenAtEnd" sentinel: if open didn't shift, close shouldn't either
|
|
158
|
+
if (offsetBeforeScroll.value !== -1) {
|
|
159
|
+
// Use the actual displacement recorded at end of open animation
|
|
160
|
+
// (not the theoretical value) so close is symmetric with open
|
|
161
|
+
offsetBeforeScroll.value = scroll.value - actualOpenShift.value;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
onMove: (e) => {
|
|
167
|
+
"worklet";
|
|
168
|
+
|
|
169
|
+
if (freeze.value) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
currentHeight.value = e.height;
|
|
174
|
+
|
|
175
|
+
if (inverted) {
|
|
176
|
+
// Skip post-interactive snap-back (duration === -1)
|
|
177
|
+
if (e.duration === -1) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const effective = getEffectiveHeight(
|
|
182
|
+
e.height,
|
|
183
|
+
targetKeyboardHeight.value,
|
|
184
|
+
offset,
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
const minimumPaddingAbsorbed =
|
|
188
|
+
getMinimumPaddingAbsorbed(
|
|
189
|
+
blankSpace.value,
|
|
190
|
+
extraContentPadding.value,
|
|
191
|
+
) * minimumPaddingFractionOnOpen.value;
|
|
192
|
+
const scrollEffective = getScrollEffective(
|
|
193
|
+
effective,
|
|
194
|
+
minimumPaddingAbsorbed,
|
|
195
|
+
);
|
|
196
|
+
const actualTotalPadding = Math.max(
|
|
197
|
+
blankSpace.value,
|
|
198
|
+
effective + extraContentPadding.value,
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
// Check if we should shift content based on position when keyboard started
|
|
202
|
+
const wasAtEnd = isScrollAtEnd(
|
|
203
|
+
offsetBeforeScroll.value,
|
|
204
|
+
layout.value.height,
|
|
205
|
+
size.value.height,
|
|
206
|
+
inverted,
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
// "never" at end: scroll along when keyboard closes to avoid jump
|
|
210
|
+
if (
|
|
211
|
+
keyboardLiftBehavior === "never" &&
|
|
212
|
+
wasAtEnd &&
|
|
213
|
+
effective < padding.value
|
|
214
|
+
) {
|
|
215
|
+
padding.value = effective;
|
|
216
|
+
|
|
217
|
+
if (scrollEffective === 0 && minimumPaddingAbsorbed > 0) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
scrollTo(scrollViewRef, 0, 0, false);
|
|
222
|
+
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (!shouldShiftContent(keyboardLiftBehavior, wasAtEnd)) {
|
|
227
|
+
// Closing, not shifting: reduce padding to avoid gap
|
|
228
|
+
if (closing.value && effective < padding.value) {
|
|
229
|
+
padding.value = effective;
|
|
230
|
+
clampScrollIfNeeded(effective, actualTotalPadding);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// When blankSpace fully absorbs the keyboard, skip scroll
|
|
237
|
+
if (scrollEffective === 0 && minimumPaddingAbsorbed > 0) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// Persistent: don't let shift decrease
|
|
242
|
+
if (keyboardLiftBehavior === "persistent") {
|
|
243
|
+
const currentShift =
|
|
244
|
+
offsetBeforeScroll.value + padding.value - scroll.value;
|
|
245
|
+
|
|
246
|
+
if (effective < currentShift) {
|
|
247
|
+
// When at end, allow scrolling back (snap to end + reduce padding)
|
|
248
|
+
if (wasAtEnd) {
|
|
249
|
+
padding.value = effective;
|
|
250
|
+
scrollTo(scrollViewRef, 0, 0, false);
|
|
251
|
+
} else if (closing.value) {
|
|
252
|
+
// Not at end: reduce padding to avoid gap
|
|
253
|
+
padding.value = effective;
|
|
254
|
+
clampScrollIfNeeded(effective, actualTotalPadding);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const target =
|
|
262
|
+
offsetBeforeScroll.value + padding.value - scrollEffective;
|
|
263
|
+
|
|
264
|
+
scrollTo(scrollViewRef, 0, target, false);
|
|
265
|
+
} else {
|
|
266
|
+
const effective = getEffectiveHeight(
|
|
267
|
+
e.height,
|
|
268
|
+
targetKeyboardHeight.value,
|
|
269
|
+
offset,
|
|
270
|
+
);
|
|
271
|
+
|
|
272
|
+
const minimumPaddingAbsorbed =
|
|
273
|
+
getMinimumPaddingAbsorbed(
|
|
274
|
+
blankSpace.value,
|
|
275
|
+
extraContentPadding.value,
|
|
276
|
+
) * minimumPaddingFractionOnOpen.value;
|
|
277
|
+
const scrollEffective = getScrollEffective(
|
|
278
|
+
effective,
|
|
279
|
+
minimumPaddingAbsorbed,
|
|
280
|
+
);
|
|
281
|
+
const actualTotalPadding = Math.max(
|
|
282
|
+
blankSpace.value,
|
|
283
|
+
effective + extraContentPadding.value,
|
|
284
|
+
);
|
|
285
|
+
|
|
286
|
+
// "never" closing: clamp scroll to valid range as inset shrinks
|
|
287
|
+
if (
|
|
288
|
+
keyboardLiftBehavior === "never" &&
|
|
289
|
+
closing.value &&
|
|
290
|
+
effective < padding.value
|
|
291
|
+
) {
|
|
292
|
+
clampScrollIfNeeded(effective, actualTotalPadding);
|
|
293
|
+
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (!shouldShiftContent(keyboardLiftBehavior, true)) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// "whenAtEnd" sentinel check (also used for blankSpace full absorption)
|
|
302
|
+
if (offsetBeforeScroll.value === -1) {
|
|
303
|
+
if (closing.value) {
|
|
304
|
+
// Keyboard didn't shift on open; ensure valid position on close
|
|
305
|
+
clampScrollIfNeeded(effective, actualTotalPadding);
|
|
306
|
+
}
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// "persistent" closing: maintain position, clamped to valid range
|
|
311
|
+
if (keyboardLiftBehavior === "persistent" && closing.value) {
|
|
312
|
+
const keepAt = offsetBeforeScroll.value + padding.value;
|
|
313
|
+
const maxScroll = Math.max(
|
|
314
|
+
size.value.height - layout.value.height + actualTotalPadding,
|
|
315
|
+
0,
|
|
316
|
+
);
|
|
317
|
+
|
|
318
|
+
scrollTo(scrollViewRef, 0, Math.min(keepAt, maxScroll), false);
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const target = clampedScrollTarget(
|
|
323
|
+
offsetBeforeScroll.value,
|
|
324
|
+
scrollEffective,
|
|
325
|
+
size.value.height,
|
|
326
|
+
layout.value.height,
|
|
327
|
+
actualTotalPadding,
|
|
328
|
+
);
|
|
329
|
+
|
|
330
|
+
scrollTo(scrollViewRef, 0, target, false);
|
|
331
|
+
|
|
332
|
+
// Track actual (clamped) displacement during open for symmetric close
|
|
333
|
+
if (!closing.value) {
|
|
334
|
+
actualOpenShift.value = target - offsetBeforeScroll.value;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
},
|
|
338
|
+
onEnd: (e) => {
|
|
339
|
+
"worklet";
|
|
340
|
+
|
|
341
|
+
if (freeze.value) {
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const effective = getEffectiveHeight(
|
|
346
|
+
e.height,
|
|
347
|
+
targetKeyboardHeight.value,
|
|
348
|
+
offset,
|
|
349
|
+
);
|
|
350
|
+
|
|
351
|
+
padding.value = effective;
|
|
352
|
+
|
|
353
|
+
// Record actual scroll displacement so close can be symmetric
|
|
354
|
+
if (effective > 0 && offsetBeforeScroll.value !== -1) {
|
|
355
|
+
actualOpenShift.value = scroll.value - offsetBeforeScroll.value;
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
},
|
|
359
|
+
[inverted, keyboardLiftBehavior, offset],
|
|
360
|
+
);
|
|
361
|
+
|
|
362
|
+
return {
|
|
363
|
+
padding,
|
|
364
|
+
currentHeight,
|
|
365
|
+
contentOffsetY: undefined,
|
|
366
|
+
scroll,
|
|
367
|
+
layout,
|
|
368
|
+
size,
|
|
369
|
+
onLayout,
|
|
370
|
+
onContentSizeChange,
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export { useChatKeyboard };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { LayoutChangeEvent } from "react-native";
|
|
2
|
+
import type { SharedValue } from "react-native-reanimated";
|
|
3
|
+
|
|
4
|
+
type KeyboardLiftBehavior = "always" | "whenAtEnd" | "persistent" | "never";
|
|
5
|
+
|
|
6
|
+
type UseChatKeyboardOptions = {
|
|
7
|
+
inverted: boolean;
|
|
8
|
+
keyboardLiftBehavior: KeyboardLiftBehavior;
|
|
9
|
+
freeze: SharedValue<boolean>;
|
|
10
|
+
offset: number;
|
|
11
|
+
blankSpace: SharedValue<number>;
|
|
12
|
+
/** Extra content padding shared value — needed on iOS to correctly clamp contentOffset. */
|
|
13
|
+
extraContentPadding: SharedValue<number>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type UseChatKeyboardReturn = {
|
|
17
|
+
/** Extra scrollable space (= keyboard height). Used as contentInset on iOS, contentInsetBottom/contentInsetTop on Android. */
|
|
18
|
+
padding: SharedValue<number>;
|
|
19
|
+
/** Raw keyboard height updated every frame in onMove. Used to force Reanimated commits on Fabric. */
|
|
20
|
+
currentHeight: SharedValue<number>;
|
|
21
|
+
/** Absolute Y content offset for iOS (set once in onStart). `undefined` on Android. */
|
|
22
|
+
contentOffsetY: SharedValue<number> | undefined;
|
|
23
|
+
/** Current vertical scroll offset. */
|
|
24
|
+
scroll: SharedValue<number>;
|
|
25
|
+
/** Visible viewport dimensions. */
|
|
26
|
+
layout: SharedValue<{ width: number; height: number }>;
|
|
27
|
+
/** Total content dimensions. */
|
|
28
|
+
size: SharedValue<{ width: number; height: number }>;
|
|
29
|
+
/** Callback to attach to ScrollView's onLayout prop to capture initial viewport dimensions. */
|
|
30
|
+
onLayout: (e: LayoutChangeEvent) => void;
|
|
31
|
+
/** Callback to attach to ScrollView's onContentSizeChange prop to capture initial content dimensions. */
|
|
32
|
+
onContentSizeChange: (w: number, h: number) => void;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export type {
|
|
36
|
+
KeyboardLiftBehavior,
|
|
37
|
+
UseChatKeyboardOptions,
|
|
38
|
+
UseChatKeyboardReturn,
|
|
39
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import {
|
|
3
|
+
runOnJS,
|
|
4
|
+
useAnimatedReaction,
|
|
5
|
+
useDerivedValue,
|
|
6
|
+
} from "react-native-reanimated";
|
|
7
|
+
|
|
8
|
+
import { isScrollAtEnd } from "./useChatKeyboard/helpers";
|
|
9
|
+
|
|
10
|
+
import type { SharedValue } from "react-native-reanimated";
|
|
11
|
+
|
|
12
|
+
type EndVisibleCallback = (visible: boolean) => void;
|
|
13
|
+
|
|
14
|
+
type Options = {
|
|
15
|
+
scroll: SharedValue<number>;
|
|
16
|
+
layout: SharedValue<{ width: number; height: number }>;
|
|
17
|
+
size: SharedValue<{ width: number; height: number }>;
|
|
18
|
+
inverted: boolean;
|
|
19
|
+
onEndVisible?: EndVisibleCallback;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const hasWorkletHash = (value: unknown): boolean =>
|
|
23
|
+
typeof value === "function" &&
|
|
24
|
+
!!(value as unknown as Record<string, unknown>).__workletHash;
|
|
25
|
+
|
|
26
|
+
export const useEndVisible = ({
|
|
27
|
+
scroll,
|
|
28
|
+
layout,
|
|
29
|
+
size,
|
|
30
|
+
inverted,
|
|
31
|
+
onEndVisible,
|
|
32
|
+
}: Options) => {
|
|
33
|
+
const isWorklet = useMemo(() => hasWorkletHash(onEndVisible), [onEndVisible]);
|
|
34
|
+
|
|
35
|
+
const isAtEnd = useDerivedValue(() => {
|
|
36
|
+
// Wait until the scroll view has been measured to avoid a spurious initial
|
|
37
|
+
// `true` on a (0,0,0) layout (the helper would otherwise treat unmeasured
|
|
38
|
+
// state as "at end" because 0 + 0 >= 0 - threshold).
|
|
39
|
+
if (layout.value.height === 0 || size.value.height === 0) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return isScrollAtEnd(
|
|
44
|
+
scroll.value,
|
|
45
|
+
layout.value.height,
|
|
46
|
+
size.value.height,
|
|
47
|
+
inverted,
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
useAnimatedReaction(
|
|
52
|
+
() => isAtEnd.value,
|
|
53
|
+
(current, previous) => {
|
|
54
|
+
if (current === null || current === previous || !onEndVisible) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (isWorklet) {
|
|
59
|
+
onEndVisible(current);
|
|
60
|
+
} else {
|
|
61
|
+
runOnJS(onEndVisible)(current);
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
[onEndVisible, isWorklet, inverted],
|
|
65
|
+
);
|
|
66
|
+
};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { Platform } from "react-native";
|
|
3
|
+
import { scrollTo, useAnimatedReaction } from "react-native-reanimated";
|
|
4
|
+
|
|
5
|
+
import { IS_FABRIC } from "../../../architecture";
|
|
6
|
+
import { isScrollAtEnd, shouldShiftContent } from "../useChatKeyboard/helpers";
|
|
7
|
+
|
|
8
|
+
import type { KeyboardLiftBehavior } from "../useChatKeyboard/types";
|
|
9
|
+
import type { AnimatedRef, SharedValue } from "react-native-reanimated";
|
|
10
|
+
import type Reanimated from "react-native-reanimated";
|
|
11
|
+
|
|
12
|
+
type UseExtraContentPaddingOptions = {
|
|
13
|
+
scrollViewRef: AnimatedRef<Reanimated.ScrollView>;
|
|
14
|
+
extraContentPadding: SharedValue<number>;
|
|
15
|
+
/** Keyboard-only padding from useChatKeyboard — used to compute total padding for clamping. */
|
|
16
|
+
keyboardPadding: SharedValue<number>;
|
|
17
|
+
/** Minimum inset floor — used to absorb keyboard and extraContentPadding changes. */
|
|
18
|
+
blankSpace: SharedValue<number>;
|
|
19
|
+
/** Current vertical scroll offset. */
|
|
20
|
+
scroll: SharedValue<number>;
|
|
21
|
+
/** Visible viewport dimensions. */
|
|
22
|
+
layout: SharedValue<{ width: number; height: number }>;
|
|
23
|
+
/** Total content dimensions. */
|
|
24
|
+
size: SharedValue<{ width: number; height: number }>;
|
|
25
|
+
/** IOS only — when provided, sets contentOffset atomically with contentInset. */
|
|
26
|
+
contentOffsetY?: SharedValue<number>;
|
|
27
|
+
inverted: boolean;
|
|
28
|
+
keyboardLiftBehavior: KeyboardLiftBehavior;
|
|
29
|
+
freeze: SharedValue<boolean>;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Hook that reacts to `extraContentPadding` changes and conditionally
|
|
34
|
+
* adjusts the scroll position using `scrollTo` on both iOS and Android.
|
|
35
|
+
*
|
|
36
|
+
* Padding extension (scrollable range) is handled externally via a
|
|
37
|
+
* `useDerivedValue` that sums keyboard padding + extra content padding.
|
|
38
|
+
* This hook only handles the scroll correction.
|
|
39
|
+
*
|
|
40
|
+
* @param options - Configuration and shared values.
|
|
41
|
+
* @example
|
|
42
|
+
* ```tsx
|
|
43
|
+
* useExtraContentPadding({ scrollViewRef, extraContentPadding, ... });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
function useExtraContentPadding(options: UseExtraContentPaddingOptions): void {
|
|
47
|
+
const {
|
|
48
|
+
scrollViewRef,
|
|
49
|
+
extraContentPadding,
|
|
50
|
+
keyboardPadding,
|
|
51
|
+
blankSpace,
|
|
52
|
+
scroll,
|
|
53
|
+
layout,
|
|
54
|
+
size,
|
|
55
|
+
contentOffsetY,
|
|
56
|
+
inverted,
|
|
57
|
+
keyboardLiftBehavior,
|
|
58
|
+
freeze,
|
|
59
|
+
} = options;
|
|
60
|
+
|
|
61
|
+
const scrollToTarget = useCallback(
|
|
62
|
+
(target: number) => {
|
|
63
|
+
"worklet";
|
|
64
|
+
|
|
65
|
+
if (contentOffsetY && IS_FABRIC) {
|
|
66
|
+
// eslint-disable-next-line react-compiler/react-compiler
|
|
67
|
+
contentOffsetY.value = target;
|
|
68
|
+
} else if (Platform.OS === "android" || (Platform.OS as string) === "harmony") {
|
|
69
|
+
// Defer scrollTo so the animatedProps inset commit lands first;
|
|
70
|
+
// otherwise the native ScrollView clamps to the old range.
|
|
71
|
+
requestAnimationFrame(() => {
|
|
72
|
+
scrollTo(scrollViewRef, 0, target, false);
|
|
73
|
+
});
|
|
74
|
+
} else {
|
|
75
|
+
scrollTo(scrollViewRef, 0, target, false);
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
[scrollViewRef, contentOffsetY],
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
useAnimatedReaction(
|
|
82
|
+
() => extraContentPadding.value,
|
|
83
|
+
(current, previous) => {
|
|
84
|
+
if (freeze.value || previous === null) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const rawDelta = current - previous;
|
|
89
|
+
|
|
90
|
+
if (rawDelta === 0) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Compute effective delta considering blankSpace floor
|
|
95
|
+
const previousTotal = Math.max(
|
|
96
|
+
blankSpace.value,
|
|
97
|
+
keyboardPadding.value + previous,
|
|
98
|
+
);
|
|
99
|
+
const currentTotal = Math.max(
|
|
100
|
+
blankSpace.value,
|
|
101
|
+
keyboardPadding.value + current,
|
|
102
|
+
);
|
|
103
|
+
const effectiveDelta = currentTotal - previousTotal;
|
|
104
|
+
|
|
105
|
+
if (effectiveDelta === 0) {
|
|
106
|
+
// blankSpace absorbed the change
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const atEnd = isScrollAtEnd(
|
|
111
|
+
scroll.value,
|
|
112
|
+
layout.value.height,
|
|
113
|
+
size.value.height,
|
|
114
|
+
inverted,
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
// "persistent": scroll on grow, hold position on shrink (unless at end)
|
|
118
|
+
if (
|
|
119
|
+
keyboardLiftBehavior === "persistent" &&
|
|
120
|
+
effectiveDelta < 0 &&
|
|
121
|
+
!atEnd
|
|
122
|
+
) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (!shouldShiftContent(keyboardLiftBehavior, atEnd)) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (inverted) {
|
|
131
|
+
const target = Math.max(scroll.value - effectiveDelta, -currentTotal);
|
|
132
|
+
|
|
133
|
+
scrollToTarget(target);
|
|
134
|
+
} else {
|
|
135
|
+
const maxScroll = Math.max(
|
|
136
|
+
size.value.height - layout.value.height + currentTotal,
|
|
137
|
+
0,
|
|
138
|
+
);
|
|
139
|
+
const target = Math.min(scroll.value + effectiveDelta, maxScroll);
|
|
140
|
+
|
|
141
|
+
scrollToTarget(target);
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
[inverted, keyboardLiftBehavior],
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export { useExtraContentPadding };
|
|
149
|
+
export type { UseExtraContentPaddingOptions };
|