@react-native-ohos/react-native-keyboard-controller 1.16.6-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.OpenSource +11 -0
- package/README.md +19 -0
- package/harmony/keyboard_controller/BuildProfile.ets +17 -0
- package/harmony/keyboard_controller/Index.ets +7 -0
- package/harmony/keyboard_controller/ResourceTable.txt +1 -0
- package/harmony/keyboard_controller/build-profile.json5 +31 -0
- package/harmony/keyboard_controller/consumer-rules.txt +0 -0
- package/harmony/keyboard_controller/hvigorfile.ts +6 -0
- package/harmony/keyboard_controller/obfuscation-rules.txt +18 -0
- package/harmony/keyboard_controller/oh-package.json5 +11 -0
- package/harmony/keyboard_controller/src/main/cpp/CMakeLists.txt +7 -0
- package/harmony/keyboard_controller/src/main/cpp/EventEmitters.cpp +96 -0
- package/harmony/keyboard_controller/src/main/cpp/EventEmitters.h +90 -0
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentDescriptor.h +73 -0
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentInstance.cpp +172 -0
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentInstance.h +76 -0
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewJSIBinder.h +44 -0
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentDescriptor.h +58 -0
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentInstance.cpp +87 -0
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentInstance.h +62 -0
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaJSIBinder.h +39 -0
- package/harmony/keyboard_controller/src/main/cpp/RNKeyboardController.cpp +25 -0
- package/harmony/keyboard_controller/src/main/cpp/RNKeyboardController.h +27 -0
- package/harmony/keyboard_controller/src/main/cpp/RNStatusBarManagerCompat.cpp +24 -0
- package/harmony/keyboard_controller/src/main/cpp/RNStatusBarManagerCompat.h +28 -0
- package/harmony/keyboard_controller/src/main/cpp/keyboardControllerPackage.cpp +43 -0
- package/harmony/keyboard_controller/src/main/cpp/keyboardControllerPackage.h +56 -0
- package/harmony/keyboard_controller/src/main/ets/Logger.ts +46 -0
- package/harmony/keyboard_controller/src/main/ets/RNKeyboardControllerPackage.ts +45 -0
- package/harmony/keyboard_controller/src/main/ets/RNKeyboardControllerTurboModule.ts +238 -0
- package/harmony/keyboard_controller/src/main/ets/RNStatusBarManagerCompatTurboModule.ts +98 -0
- package/harmony/keyboard_controller/src/main/ets/Type.ts +41 -0
- package/harmony/keyboard_controller/src/main/module.json5 +11 -0
- package/harmony/keyboard_controller/src/main/resources/base/element/string.json +8 -0
- package/harmony/keyboard_controller/src/main/resources/en_US/element/string.json +8 -0
- package/harmony/keyboard_controller/src/main/resources/zh_CN/element/string.json +8 -0
- package/harmony/keyboard_controller/ts.ts +9 -0
- package/harmony/keyboard_controller.har +0 -0
- package/lib/commonjs/animated.js +176 -0
- package/lib/commonjs/animated.js.map +1 -0
- package/lib/commonjs/bindings.js +39 -0
- package/lib/commonjs/bindings.js.map +1 -0
- package/lib/commonjs/bindings.native.js +39 -0
- package/lib/commonjs/bindings.native.js.map +1 -0
- package/lib/commonjs/components/KeyboardAvoidingView/hooks.js +126 -0
- package/lib/commonjs/components/KeyboardAvoidingView/hooks.js.map +1 -0
- package/lib/commonjs/components/KeyboardAvoidingView/index.js +120 -0
- package/lib/commonjs/components/KeyboardAvoidingView/index.js.map +1 -0
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js +262 -0
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js.map +1 -0
- package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +110 -0
- package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -0
- package/lib/commonjs/components/KeyboardAwareScrollView/utils.js +37 -0
- package/lib/commonjs/components/KeyboardAwareScrollView/utils.js.map +1 -0
- package/lib/commonjs/components/KeyboardStickyView/index.js +41 -0
- package/lib/commonjs/components/KeyboardStickyView/index.js.map +1 -0
- package/lib/commonjs/components/KeyboardToolbar/Arrow.js +76 -0
- package/lib/commonjs/components/KeyboardToolbar/Arrow.js.map +1 -0
- package/lib/commonjs/components/KeyboardToolbar/Button.js +70 -0
- package/lib/commonjs/components/KeyboardToolbar/Button.js.map +1 -0
- package/lib/commonjs/components/KeyboardToolbar/colors.js +21 -0
- package/lib/commonjs/components/KeyboardToolbar/colors.js.map +1 -0
- package/lib/commonjs/components/KeyboardToolbar/colors.native.js +40 -0
- package/lib/commonjs/components/KeyboardToolbar/colors.native.js.map +1 -0
- package/lib/commonjs/components/KeyboardToolbar/index.js +161 -0
- package/lib/commonjs/components/KeyboardToolbar/index.js.map +1 -0
- package/lib/commonjs/components/KeyboardToolbar/types.js +6 -0
- package/lib/commonjs/components/KeyboardToolbar/types.js.map +1 -0
- package/lib/commonjs/components/hooks/useColorScheme.js +10 -0
- package/lib/commonjs/components/hooks/useColorScheme.js.map +1 -0
- package/lib/commonjs/components/index.js +42 -0
- package/lib/commonjs/components/index.js.map +1 -0
- package/lib/commonjs/constants.js +27 -0
- package/lib/commonjs/constants.js.map +1 -0
- package/lib/commonjs/context.js +45 -0
- package/lib/commonjs/context.js.map +1 -0
- package/lib/commonjs/hooks/index.js +104 -0
- package/lib/commonjs/hooks/index.js.map +1 -0
- package/lib/commonjs/hooks/useWindowDimensions/index.android.js +34 -0
- package/lib/commonjs/hooks/useWindowDimensions/index.android.js.map +1 -0
- package/lib/commonjs/hooks/useWindowDimensions/index.js +13 -0
- package/lib/commonjs/hooks/useWindowDimensions/index.js.map +1 -0
- package/lib/commonjs/index.js +136 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/internal.js +73 -0
- package/lib/commonjs/internal.js.map +1 -0
- package/lib/commonjs/module.js +47 -0
- package/lib/commonjs/module.js.map +1 -0
- package/lib/commonjs/monkey-patch.android.js +57 -0
- package/lib/commonjs/monkey-patch.android.js.map +1 -0
- package/lib/commonjs/monkey-patch.js +11 -0
- package/lib/commonjs/monkey-patch.js.map +1 -0
- package/lib/commonjs/reanimated.js +12 -0
- package/lib/commonjs/reanimated.js.map +1 -0
- package/lib/commonjs/reanimated.native.js +88 -0
- package/lib/commonjs/reanimated.native.js.map +1 -0
- package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js +10 -0
- package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js.map +1 -0
- package/lib/commonjs/specs/KeyboardGestureAreaNativeComponent.js +12 -0
- package/lib/commonjs/specs/KeyboardGestureAreaNativeComponent.js.map +1 -0
- package/lib/commonjs/specs/NativeKeyboardController.js +9 -0
- package/lib/commonjs/specs/NativeKeyboardController.js.map +1 -0
- package/lib/commonjs/specs/NativeStatusBarManagerCompat.js +9 -0
- package/lib/commonjs/specs/NativeStatusBarManagerCompat.js.map +1 -0
- package/lib/commonjs/specs/OverKeyboardViewNativeComponent.js +10 -0
- package/lib/commonjs/specs/OverKeyboardViewNativeComponent.js.map +1 -0
- package/lib/commonjs/types.js +6 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/utils.js +9 -0
- package/lib/commonjs/utils.js.map +1 -0
- package/lib/commonjs/views/OverKeyboardView/index.js +42 -0
- package/lib/commonjs/views/OverKeyboardView/index.js.map +1 -0
- package/lib/commonjs/views/index.js +14 -0
- package/lib/commonjs/views/index.js.map +1 -0
- package/lib/module/animated.js +168 -0
- package/lib/module/animated.js.map +1 -0
- package/lib/module/bindings.js +33 -0
- package/lib/module/bindings.js.map +1 -0
- package/lib/module/bindings.native.js +33 -0
- package/lib/module/bindings.native.js.map +1 -0
- package/lib/module/components/KeyboardAvoidingView/hooks.js +118 -0
- package/lib/module/components/KeyboardAvoidingView/hooks.js.map +1 -0
- package/lib/module/components/KeyboardAvoidingView/index.js +113 -0
- package/lib/module/components/KeyboardAvoidingView/index.js.map +1 -0
- package/lib/module/components/KeyboardAwareScrollView/index.js +255 -0
- package/lib/module/components/KeyboardAwareScrollView/index.js.map +1 -0
- package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +103 -0
- package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -0
- package/lib/module/components/KeyboardAwareScrollView/utils.js +29 -0
- package/lib/module/components/KeyboardAwareScrollView/utils.js.map +1 -0
- package/lib/module/components/KeyboardStickyView/index.js +34 -0
- package/lib/module/components/KeyboardStickyView/index.js.map +1 -0
- package/lib/module/components/KeyboardToolbar/Arrow.js +68 -0
- package/lib/module/components/KeyboardToolbar/Arrow.js.map +1 -0
- package/lib/module/components/KeyboardToolbar/Button.js +62 -0
- package/lib/module/components/KeyboardToolbar/Button.js.map +1 -0
- package/lib/module/components/KeyboardToolbar/colors.js +15 -0
- package/lib/module/components/KeyboardToolbar/colors.js.map +1 -0
- package/lib/module/components/KeyboardToolbar/colors.native.js +34 -0
- package/lib/module/components/KeyboardToolbar/colors.native.js.map +1 -0
- package/lib/module/components/KeyboardToolbar/index.js +149 -0
- package/lib/module/components/KeyboardToolbar/index.js.map +1 -0
- package/lib/module/components/KeyboardToolbar/types.js +2 -0
- package/lib/module/components/KeyboardToolbar/types.js.map +1 -0
- package/lib/module/components/hooks/useColorScheme.js +4 -0
- package/lib/module/components/hooks/useColorScheme.js.map +1 -0
- package/lib/module/components/index.js +5 -0
- package/lib/module/components/index.js.map +1 -0
- package/lib/module/constants.js +21 -0
- package/lib/module/constants.js.map +1 -0
- package/lib/module/context.js +38 -0
- package/lib/module/context.js.map +1 -0
- package/lib/module/hooks/index.js +68 -0
- package/lib/module/hooks/index.js.map +1 -0
- package/lib/module/hooks/useWindowDimensions/index.android.js +27 -0
- package/lib/module/hooks/useWindowDimensions/index.android.js.map +1 -0
- package/lib/module/hooks/useWindowDimensions/index.js +2 -0
- package/lib/module/hooks/useWindowDimensions/index.js.map +1 -0
- package/lib/module/index.js +12 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/internal.js +66 -0
- package/lib/module/internal.js.map +1 -0
- package/lib/module/module.js +41 -0
- package/lib/module/module.js.map +1 -0
- package/lib/module/monkey-patch.android.js +47 -0
- package/lib/module/monkey-patch.android.js.map +1 -0
- package/lib/module/monkey-patch.js +5 -0
- package/lib/module/monkey-patch.js.map +1 -0
- package/lib/module/reanimated.js +6 -0
- package/lib/module/reanimated.js.map +1 -0
- package/lib/module/reanimated.native.js +78 -0
- package/lib/module/reanimated.native.js.map +1 -0
- package/lib/module/specs/KeyboardControllerViewNativeComponent.js +3 -0
- package/lib/module/specs/KeyboardControllerViewNativeComponent.js.map +1 -0
- package/lib/module/specs/KeyboardGestureAreaNativeComponent.js +5 -0
- package/lib/module/specs/KeyboardGestureAreaNativeComponent.js.map +1 -0
- package/lib/module/specs/NativeKeyboardController.js +3 -0
- package/lib/module/specs/NativeKeyboardController.js.map +1 -0
- package/lib/module/specs/NativeStatusBarManagerCompat.js +3 -0
- package/lib/module/specs/NativeStatusBarManagerCompat.js.map +1 -0
- package/lib/module/specs/OverKeyboardViewNativeComponent.js +3 -0
- package/lib/module/specs/OverKeyboardViewNativeComponent.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/utils.js +2 -0
- package/lib/module/utils.js.map +1 -0
- package/lib/module/views/OverKeyboardView/index.js +35 -0
- package/lib/module/views/OverKeyboardView/index.js.map +1 -0
- package/lib/module/views/index.js +2 -0
- package/lib/module/views/index.js.map +1 -0
- package/lib/typescript/animated.d.ts +39 -0
- package/lib/typescript/bindings.d.ts +12 -0
- package/lib/typescript/bindings.native.d.ts +12 -0
- package/lib/typescript/components/KeyboardAvoidingView/hooks.d.ts +10 -0
- package/lib/typescript/components/KeyboardAvoidingView/index.d.ts +40 -0
- package/lib/typescript/components/KeyboardAwareScrollView/index.d.ts +29 -0
- package/lib/typescript/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.d.ts +6 -0
- package/lib/typescript/components/KeyboardAwareScrollView/utils.d.ts +2 -0
- package/lib/typescript/components/KeyboardStickyView/index.d.ts +39 -0
- package/lib/typescript/components/KeyboardToolbar/Arrow.d.ts +9 -0
- package/lib/typescript/components/KeyboardToolbar/Button.d.ts +16 -0
- package/lib/typescript/components/KeyboardToolbar/colors.d.ts +2 -0
- package/lib/typescript/components/KeyboardToolbar/colors.native.d.ts +2 -0
- package/lib/typescript/components/KeyboardToolbar/index.d.ts +52 -0
- package/lib/typescript/components/KeyboardToolbar/types.d.ts +18 -0
- package/lib/typescript/components/hooks/useColorScheme.d.ts +2 -0
- package/lib/typescript/components/index.d.ts +8 -0
- package/lib/typescript/constants.d.ts +16 -0
- package/lib/typescript/context.d.ts +23 -0
- package/lib/typescript/hooks/index.d.ts +17 -0
- package/lib/typescript/hooks/useWindowDimensions/index.android.d.ts +2 -0
- package/lib/typescript/hooks/useWindowDimensions/index.d.ts +1 -0
- package/lib/typescript/index.d.ts +10 -0
- package/lib/typescript/internal.d.ts +30 -0
- package/lib/typescript/module.d.ts +2 -0
- package/lib/typescript/monkey-patch.android.d.ts +2 -0
- package/lib/typescript/monkey-patch.d.ts +2 -0
- package/lib/typescript/reanimated.d.ts +5 -0
- package/lib/typescript/reanimated.native.d.ts +7 -0
- package/lib/typescript/specs/KeyboardControllerViewNativeComponent.d.ts +54 -0
- package/lib/typescript/specs/KeyboardGestureAreaNativeComponent.d.ts +12 -0
- package/lib/typescript/specs/NativeKeyboardController.d.ts +12 -0
- package/lib/typescript/specs/NativeStatusBarManagerCompat.d.ts +10 -0
- package/lib/typescript/specs/OverKeyboardViewNativeComponent.d.ts +7 -0
- package/lib/typescript/types.d.ts +161 -0
- package/lib/typescript/utils.d.ts +1 -0
- package/lib/typescript/views/OverKeyboardView/index.d.ts +5 -0
- package/lib/typescript/views/index.d.ts +1 -0
- package/package.json +173 -0
- package/react-native-keyboard-controller.podspec +61 -0
- package/src/animated.tsx +256 -0
- package/src/bindings.native.ts +62 -0
- package/src/bindings.ts +42 -0
- package/src/components/KeyboardAvoidingView/hooks.ts +123 -0
- package/src/components/KeyboardAvoidingView/index.tsx +188 -0
- package/src/components/KeyboardAwareScrollView/index.tsx +389 -0
- package/src/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.ts +133 -0
- package/src/components/KeyboardAwareScrollView/utils.ts +41 -0
- package/src/components/KeyboardStickyView/index.tsx +66 -0
- package/src/components/KeyboardToolbar/Arrow.tsx +80 -0
- package/src/components/KeyboardToolbar/Button.tsx +98 -0
- package/src/components/KeyboardToolbar/colors.native.ts +37 -0
- package/src/components/KeyboardToolbar/colors.ts +16 -0
- package/src/components/KeyboardToolbar/index.tsx +223 -0
- package/src/components/KeyboardToolbar/types.ts +40 -0
- package/src/components/hooks/useColorScheme.ts +5 -0
- package/src/components/index.ts +11 -0
- package/src/constants.ts +19 -0
- package/src/context.ts +68 -0
- package/src/hooks/index.ts +90 -0
- package/src/hooks/useWindowDimensions/index.android.ts +38 -0
- package/src/hooks/useWindowDimensions/index.ts +1 -0
- package/src/index.ts +23 -0
- package/src/internal.ts +84 -0
- package/src/module.ts +52 -0
- package/src/monkey-patch.android.ts +44 -0
- package/src/monkey-patch.ts +4 -0
- package/src/reanimated.native.ts +132 -0
- package/src/reanimated.ts +29 -0
- package/src/specs/KeyboardControllerViewNativeComponent.ts +71 -0
- package/src/specs/KeyboardGestureAreaNativeComponent.ts +20 -0
- package/src/specs/NativeKeyboardController.ts +19 -0
- package/src/specs/NativeStatusBarManagerCompat.ts +14 -0
- package/src/specs/OverKeyboardViewNativeComponent.ts +12 -0
- package/src/types.ts +243 -0
- package/src/utils.ts +1 -0
- package/src/views/OverKeyboardView/index.tsx +43 -0
- package/src/views/index.ts +1 -0
|
@@ -0,0 +1,255 @@
|
|
|
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
|
+
import React, { forwardRef, useCallback, useMemo } from "react";
|
|
3
|
+
import { findNodeHandle } from "react-native";
|
|
4
|
+
import Reanimated, { interpolate, scrollTo, useAnimatedReaction, useAnimatedRef, useAnimatedStyle, useScrollViewOffset, useSharedValue } from "react-native-reanimated";
|
|
5
|
+
import { useFocusedInputHandler, useReanimatedFocusedInput, useWindowDimensions } from "../../hooks";
|
|
6
|
+
import { useSmoothKeyboardHandler } from "./useSmoothKeyboardHandler";
|
|
7
|
+
import { debounce, scrollDistanceWithRespectToSnapPoints } from "./utils";
|
|
8
|
+
/*
|
|
9
|
+
* Everything begins from `onStart` handler. This handler is called every time,
|
|
10
|
+
* when keyboard changes its size or when focused `TextInput` was changed. In
|
|
11
|
+
* this handler we are calculating/memoizing values which later will be used
|
|
12
|
+
* during layout movement. For that we calculate:
|
|
13
|
+
* - layout of focused field (`layout`) - to understand whether there will be overlap
|
|
14
|
+
* - initial keyboard size (`initialKeyboardSize`) - used in scroll interpolation
|
|
15
|
+
* - future keyboard height (`keyboardHeight`) - used in scroll interpolation
|
|
16
|
+
* - current scroll position (`scrollPosition`) - used to scroll from this point
|
|
17
|
+
*
|
|
18
|
+
* Once we've calculated all necessary variables - we can actually start to use them.
|
|
19
|
+
* It happens in `onMove` handler - this function simply calls `maybeScroll` with
|
|
20
|
+
* current keyboard frame height. This functions makes the smooth transition.
|
|
21
|
+
*
|
|
22
|
+
* When the transition has finished we go to `onEnd` handler. In this handler
|
|
23
|
+
* we verify, that the current field is not overlapped within a keyboard frame.
|
|
24
|
+
* For full `onStart`/`onMove`/`onEnd` flow it may look like a redundant thing,
|
|
25
|
+
* however there could be some cases, when `onMove` is not called:
|
|
26
|
+
* - on iOS when TextInput was changed - keyboard transition is instant
|
|
27
|
+
* - on Android when TextInput was changed and keyboard size wasn't changed
|
|
28
|
+
* So `onEnd` handler handle the case, when `onMove` wasn't triggered.
|
|
29
|
+
*
|
|
30
|
+
* ====================================================================================================================+
|
|
31
|
+
* -----------------------------------------------------Flow chart-----------------------------------------------------+
|
|
32
|
+
* ====================================================================================================================+
|
|
33
|
+
*
|
|
34
|
+
* +============================+ +============================+ +==================================+
|
|
35
|
+
* + User Press on TextInput + => + Keyboard starts showing + => + As keyboard moves frame by frame + =>
|
|
36
|
+
* + + + (run `onStart`) + + `onMove` is getting called +
|
|
37
|
+
* +============================+ +============================+ +==================================+
|
|
38
|
+
*
|
|
39
|
+
*
|
|
40
|
+
* +============================+ +============================+ +=====================================+
|
|
41
|
+
* + Keyboard is shown and we + => + User moved focus to + => + Only `onStart`/`onEnd` maybe called +
|
|
42
|
+
* + call `onEnd` handler + + another `TextInput` + + (without involving `onMove`) +
|
|
43
|
+
* +============================+ +============================+ +=====================================+
|
|
44
|
+
*
|
|
45
|
+
*/
|
|
46
|
+
const KeyboardAwareScrollView = /*#__PURE__*/forwardRef(({
|
|
47
|
+
children,
|
|
48
|
+
onLayout,
|
|
49
|
+
bottomOffset = 0,
|
|
50
|
+
disableScrollOnKeyboardHide = false,
|
|
51
|
+
enabled = true,
|
|
52
|
+
extraKeyboardSpace = 0,
|
|
53
|
+
ScrollViewComponent = Reanimated.ScrollView,
|
|
54
|
+
...rest
|
|
55
|
+
}, ref) => {
|
|
56
|
+
const scrollViewAnimatedRef = useAnimatedRef();
|
|
57
|
+
const scrollViewTarget = useSharedValue(null);
|
|
58
|
+
const scrollPosition = useSharedValue(0);
|
|
59
|
+
const position = useScrollViewOffset(scrollViewAnimatedRef);
|
|
60
|
+
const currentKeyboardFrameHeight = useSharedValue(0);
|
|
61
|
+
const keyboardHeight = useSharedValue(0);
|
|
62
|
+
const keyboardWillAppear = useSharedValue(false);
|
|
63
|
+
const tag = useSharedValue(-1);
|
|
64
|
+
const initialKeyboardSize = useSharedValue(0);
|
|
65
|
+
const scrollBeforeKeyboardMovement = useSharedValue(0);
|
|
66
|
+
const {
|
|
67
|
+
input
|
|
68
|
+
} = useReanimatedFocusedInput();
|
|
69
|
+
const layout = useSharedValue(null);
|
|
70
|
+
const {
|
|
71
|
+
height
|
|
72
|
+
} = useWindowDimensions();
|
|
73
|
+
const onRef = useCallback(assignedRef => {
|
|
74
|
+
if (typeof ref === "function") {
|
|
75
|
+
ref(assignedRef);
|
|
76
|
+
} else if (ref) {
|
|
77
|
+
ref.current = assignedRef;
|
|
78
|
+
}
|
|
79
|
+
scrollViewAnimatedRef(assignedRef);
|
|
80
|
+
}, []);
|
|
81
|
+
const onScrollViewLayout = useCallback(e => {
|
|
82
|
+
scrollViewTarget.value = findNodeHandle(scrollViewAnimatedRef.current);
|
|
83
|
+
onLayout === null || onLayout === void 0 || onLayout(e);
|
|
84
|
+
}, [onLayout]);
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Function that will scroll a ScrollView as keyboard gets moving
|
|
88
|
+
*/
|
|
89
|
+
const maybeScroll = useCallback((e, animated = false) => {
|
|
90
|
+
"worklet";
|
|
91
|
+
|
|
92
|
+
var _layout$value, _layout$value2, _layout$value3;
|
|
93
|
+
if (!enabled) {
|
|
94
|
+
return 0;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// input belongs to ScrollView
|
|
98
|
+
if (((_layout$value = layout.value) === null || _layout$value === void 0 ? void 0 : _layout$value.parentScrollViewTarget) !== scrollViewTarget.value) {
|
|
99
|
+
return 0;
|
|
100
|
+
}
|
|
101
|
+
const visibleRect = height - keyboardHeight.value;
|
|
102
|
+
const absoluteY = ((_layout$value2 = layout.value) === null || _layout$value2 === void 0 ? void 0 : _layout$value2.layout.absoluteY) || 0;
|
|
103
|
+
const inputHeight = ((_layout$value3 = layout.value) === null || _layout$value3 === void 0 ? void 0 : _layout$value3.layout.height) || 0;
|
|
104
|
+
const point = absoluteY + inputHeight;
|
|
105
|
+
if (visibleRect - point <= bottomOffset) {
|
|
106
|
+
const relativeScrollTo = keyboardHeight.value - (height - point) + bottomOffset;
|
|
107
|
+
const interpolatedScrollTo = interpolate(e, [initialKeyboardSize.value, keyboardHeight.value], [0, scrollDistanceWithRespectToSnapPoints(relativeScrollTo + scrollPosition.value, rest.snapToOffsets) - scrollPosition.value]);
|
|
108
|
+
const targetScrollY = Math.max(interpolatedScrollTo, 0) + scrollPosition.value;
|
|
109
|
+
scrollTo(scrollViewAnimatedRef, 0, targetScrollY, animated);
|
|
110
|
+
return interpolatedScrollTo;
|
|
111
|
+
}
|
|
112
|
+
if (absoluteY < 0) {
|
|
113
|
+
const positionOnScreen = visibleRect - inputHeight - bottomOffset;
|
|
114
|
+
const topOfScreen = scrollPosition.value + absoluteY;
|
|
115
|
+
scrollTo(scrollViewAnimatedRef, 0, topOfScreen - positionOnScreen, animated);
|
|
116
|
+
}
|
|
117
|
+
return 0;
|
|
118
|
+
}, [bottomOffset, enabled, height, rest.snapToOffsets]);
|
|
119
|
+
const syncKeyboardFrame = useCallback(e => {
|
|
120
|
+
"worklet";
|
|
121
|
+
|
|
122
|
+
const keyboardFrame = interpolate(e.height, [0, keyboardHeight.value], [0, keyboardHeight.value + extraKeyboardSpace]);
|
|
123
|
+
currentKeyboardFrameHeight.value = keyboardFrame;
|
|
124
|
+
}, [extraKeyboardSpace]);
|
|
125
|
+
const scrollFromCurrentPosition = useCallback(customHeight => {
|
|
126
|
+
"worklet";
|
|
127
|
+
|
|
128
|
+
var _input$value;
|
|
129
|
+
const prevScrollPosition = scrollPosition.value;
|
|
130
|
+
const prevLayout = layout.value;
|
|
131
|
+
if (!((_input$value = input.value) !== null && _input$value !== void 0 && _input$value.layout)) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// eslint-disable-next-line react-compiler/react-compiler
|
|
136
|
+
layout.value = {
|
|
137
|
+
...input.value,
|
|
138
|
+
layout: {
|
|
139
|
+
...input.value.layout,
|
|
140
|
+
height: customHeight ?? input.value.layout.height
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
scrollPosition.value = position.value;
|
|
144
|
+
maybeScroll(keyboardHeight.value, true);
|
|
145
|
+
scrollPosition.value = prevScrollPosition;
|
|
146
|
+
layout.value = prevLayout;
|
|
147
|
+
}, [maybeScroll]);
|
|
148
|
+
const onChangeText = useCallback(() => {
|
|
149
|
+
"worklet";
|
|
150
|
+
|
|
151
|
+
// if typing a text caused layout shift, then we need to ignore this handler
|
|
152
|
+
// because this event will be handled in `useAnimatedReaction` below
|
|
153
|
+
var _layout$value4, _input$value2;
|
|
154
|
+
if (((_layout$value4 = layout.value) === null || _layout$value4 === void 0 ? void 0 : _layout$value4.layout.height) !== ((_input$value2 = input.value) === null || _input$value2 === void 0 ? void 0 : _input$value2.layout.height)) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
scrollFromCurrentPosition();
|
|
158
|
+
}, [scrollFromCurrentPosition]);
|
|
159
|
+
const onSelectionChange = useCallback(e => {
|
|
160
|
+
"worklet";
|
|
161
|
+
|
|
162
|
+
if (e.selection.start.position !== e.selection.end.position) {
|
|
163
|
+
scrollFromCurrentPosition(e.selection.end.y);
|
|
164
|
+
}
|
|
165
|
+
}, [scrollFromCurrentPosition]);
|
|
166
|
+
const onChangeTextHandler = useMemo(() => debounce(onChangeText, 200), [onChangeText]);
|
|
167
|
+
useFocusedInputHandler({
|
|
168
|
+
onChangeText: onChangeTextHandler,
|
|
169
|
+
onSelectionChange: onSelectionChange
|
|
170
|
+
}, [onChangeTextHandler, onSelectionChange]);
|
|
171
|
+
useSmoothKeyboardHandler({
|
|
172
|
+
onStart: e => {
|
|
173
|
+
"worklet";
|
|
174
|
+
|
|
175
|
+
const keyboardWillChangeSize = keyboardHeight.value !== e.height && e.height > 0;
|
|
176
|
+
keyboardWillAppear.value = e.height > 0 && keyboardHeight.value === 0;
|
|
177
|
+
const keyboardWillHide = e.height === 0;
|
|
178
|
+
const focusWasChanged = tag.value !== e.target && e.target !== -1 || keyboardWillChangeSize;
|
|
179
|
+
if (keyboardWillChangeSize) {
|
|
180
|
+
initialKeyboardSize.value = keyboardHeight.value;
|
|
181
|
+
}
|
|
182
|
+
if (keyboardWillHide) {
|
|
183
|
+
// on back transition need to interpolate as [0, keyboardHeight]
|
|
184
|
+
initialKeyboardSize.value = 0;
|
|
185
|
+
scrollPosition.value = scrollBeforeKeyboardMovement.value;
|
|
186
|
+
}
|
|
187
|
+
if (keyboardWillAppear.value || keyboardWillChangeSize || focusWasChanged) {
|
|
188
|
+
// persist scroll value
|
|
189
|
+
scrollPosition.value = position.value;
|
|
190
|
+
// just persist height - later will be used in interpolation
|
|
191
|
+
keyboardHeight.value = e.height;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// focus was changed
|
|
195
|
+
if (focusWasChanged) {
|
|
196
|
+
tag.value = e.target;
|
|
197
|
+
|
|
198
|
+
// save position of focused text input when keyboard starts to move
|
|
199
|
+
layout.value = input.value;
|
|
200
|
+
// save current scroll position - when keyboard will hide we'll reuse
|
|
201
|
+
// this value to achieve smooth hide effect
|
|
202
|
+
scrollBeforeKeyboardMovement.value = position.value;
|
|
203
|
+
}
|
|
204
|
+
if (focusWasChanged && !keyboardWillAppear.value) {
|
|
205
|
+
// update position on scroll value, so `onEnd` handler
|
|
206
|
+
// will pick up correct values
|
|
207
|
+
position.value += maybeScroll(e.height, true);
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
onMove: e => {
|
|
211
|
+
"worklet";
|
|
212
|
+
|
|
213
|
+
syncKeyboardFrame(e);
|
|
214
|
+
|
|
215
|
+
// if the user has set disableScrollOnKeyboardHide, only auto-scroll when the keyboard opens
|
|
216
|
+
if (!disableScrollOnKeyboardHide || keyboardWillAppear.value) {
|
|
217
|
+
maybeScroll(e.height);
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
onEnd: e => {
|
|
221
|
+
"worklet";
|
|
222
|
+
|
|
223
|
+
keyboardHeight.value = e.height;
|
|
224
|
+
scrollPosition.value = position.value;
|
|
225
|
+
syncKeyboardFrame(e);
|
|
226
|
+
}
|
|
227
|
+
}, [maybeScroll, disableScrollOnKeyboardHide, syncKeyboardFrame]);
|
|
228
|
+
useAnimatedReaction(() => input.value, (current, previous) => {
|
|
229
|
+
if ((current === null || current === void 0 ? void 0 : current.target) === (previous === null || previous === void 0 ? void 0 : previous.target) && (current === null || current === void 0 ? void 0 : current.layout.height) !== (previous === null || previous === void 0 ? void 0 : previous.layout.height)) {
|
|
230
|
+
const prevLayout = layout.value;
|
|
231
|
+
layout.value = input.value;
|
|
232
|
+
scrollPosition.value += maybeScroll(keyboardHeight.value, true);
|
|
233
|
+
layout.value = prevLayout;
|
|
234
|
+
}
|
|
235
|
+
}, []);
|
|
236
|
+
const view = useAnimatedStyle(() => enabled ? {
|
|
237
|
+
// animations become choppy when scrolling to the end of the `ScrollView` (when the last input is focused)
|
|
238
|
+
// this happens because the layout recalculates on every frame. To avoid this we slightly increase padding
|
|
239
|
+
// by `+1`. In this way we assure, that `scrollTo` will never scroll to the end, because it uses interpolation
|
|
240
|
+
// from 0 to `keyboardHeight`, and here our padding is `keyboardHeight + 1`. It allows us not to re-run layout
|
|
241
|
+
// re-calculation on every animation frame and it helps to achieve smooth animation.
|
|
242
|
+
// see: https://github.com/kirillzyusko/react-native-keyboard-controller/pull/342
|
|
243
|
+
paddingBottom: currentKeyboardFrameHeight.value + 1
|
|
244
|
+
} : {}, [enabled]);
|
|
245
|
+
return /*#__PURE__*/React.createElement(ScrollViewComponent, _extends({
|
|
246
|
+
ref: onRef
|
|
247
|
+
}, rest, {
|
|
248
|
+
onLayout: onScrollViewLayout,
|
|
249
|
+
scrollEventThrottle: 16
|
|
250
|
+
}), children, /*#__PURE__*/React.createElement(Reanimated.View, {
|
|
251
|
+
style: view
|
|
252
|
+
}));
|
|
253
|
+
});
|
|
254
|
+
export default KeyboardAwareScrollView;
|
|
255
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","forwardRef","useCallback","useMemo","findNodeHandle","Reanimated","interpolate","scrollTo","useAnimatedReaction","useAnimatedRef","useAnimatedStyle","useScrollViewOffset","useSharedValue","useFocusedInputHandler","useReanimatedFocusedInput","useWindowDimensions","useSmoothKeyboardHandler","debounce","scrollDistanceWithRespectToSnapPoints","KeyboardAwareScrollView","children","onLayout","bottomOffset","disableScrollOnKeyboardHide","enabled","extraKeyboardSpace","ScrollViewComponent","ScrollView","rest","ref","scrollViewAnimatedRef","scrollViewTarget","scrollPosition","position","currentKeyboardFrameHeight","keyboardHeight","keyboardWillAppear","tag","initialKeyboardSize","scrollBeforeKeyboardMovement","input","layout","height","onRef","assignedRef","current","onScrollViewLayout","e","value","maybeScroll","animated","_layout$value","_layout$value2","_layout$value3","parentScrollViewTarget","visibleRect","absoluteY","inputHeight","point","relativeScrollTo","interpolatedScrollTo","snapToOffsets","targetScrollY","Math","max","positionOnScreen","topOfScreen","syncKeyboardFrame","keyboardFrame","scrollFromCurrentPosition","customHeight","_input$value","prevScrollPosition","prevLayout","onChangeText","_layout$value4","_input$value2","onSelectionChange","selection","start","end","y","onChangeTextHandler","onStart","keyboardWillChangeSize","keyboardWillHide","focusWasChanged","target","onMove","onEnd","previous","view","paddingBottom","createElement","_extends","scrollEventThrottle","View","style"],"sources":["index.tsx"],"sourcesContent":["import React, { forwardRef, useCallback, useMemo } from \"react\";\nimport { findNodeHandle } from \"react-native\";\nimport Reanimated, {\n interpolate,\n scrollTo,\n useAnimatedReaction,\n useAnimatedRef,\n useAnimatedStyle,\n useScrollViewOffset,\n useSharedValue,\n} from \"react-native-reanimated\";\n\nimport {\n useFocusedInputHandler,\n useReanimatedFocusedInput,\n useWindowDimensions,\n} from \"../../hooks\";\n\nimport { useSmoothKeyboardHandler } from \"./useSmoothKeyboardHandler\";\nimport { debounce, scrollDistanceWithRespectToSnapPoints } from \"./utils\";\n\nimport type {\n LayoutChangeEvent,\n ScrollView,\n ScrollViewProps,\n} from \"react-native\";\nimport type {\n FocusedInputLayoutChangedEvent,\n FocusedInputSelectionChangedEvent,\n NativeEvent,\n} from \"..//../types\";\n\nexport type KeyboardAwareScrollViewProps = {\n /** The distance between keyboard and focused `TextInput` when keyboard is shown. Default is `0`. */\n bottomOffset?: number;\n /** Prevents automatic scrolling of the `ScrollView` when the keyboard gets hidden, maintaining the current screen position. Default is `false`. */\n disableScrollOnKeyboardHide?: boolean;\n /** Controls whether this `KeyboardAwareScrollView` instance should take effect. Default is `true` */\n enabled?: boolean;\n /** Adjusting the bottom spacing of KeyboardAwareScrollView. Default is `0` */\n extraKeyboardSpace?: number;\n /** Custom component for `ScrollView`. Default is `ScrollView` */\n ScrollViewComponent?: React.ComponentType<ScrollViewProps>;\n} & ScrollViewProps;\n\n/*\n * Everything begins from `onStart` handler. This handler is called every time,\n * when keyboard changes its size or when focused `TextInput` was changed. In\n * this handler we are calculating/memoizing values which later will be used\n * during layout movement. For that we calculate:\n * - layout of focused field (`layout`) - to understand whether there will be overlap\n * - initial keyboard size (`initialKeyboardSize`) - used in scroll interpolation\n * - future keyboard height (`keyboardHeight`) - used in scroll interpolation\n * - current scroll position (`scrollPosition`) - used to scroll from this point\n *\n * Once we've calculated all necessary variables - we can actually start to use them.\n * It happens in `onMove` handler - this function simply calls `maybeScroll` with\n * current keyboard frame height. This functions makes the smooth transition.\n *\n * When the transition has finished we go to `onEnd` handler. In this handler\n * we verify, that the current field is not overlapped within a keyboard frame.\n * For full `onStart`/`onMove`/`onEnd` flow it may look like a redundant thing,\n * however there could be some cases, when `onMove` is not called:\n * - on iOS when TextInput was changed - keyboard transition is instant\n * - on Android when TextInput was changed and keyboard size wasn't changed\n * So `onEnd` handler handle the case, when `onMove` wasn't triggered.\n *\n * ====================================================================================================================+\n * -----------------------------------------------------Flow chart-----------------------------------------------------+\n * ====================================================================================================================+\n *\n * +============================+ +============================+ +==================================+\n * + User Press on TextInput + => + Keyboard starts showing + => + As keyboard moves frame by frame + =>\n * + + + (run `onStart`) + + `onMove` is getting called +\n * +============================+ +============================+ +==================================+\n *\n *\n * +============================+ +============================+ +=====================================+\n * + Keyboard is shown and we + => + User moved focus to + => + Only `onStart`/`onEnd` maybe called +\n * + call `onEnd` handler + + another `TextInput` + + (without involving `onMove`) +\n * +============================+ +============================+ +=====================================+\n *\n */\nconst KeyboardAwareScrollView = forwardRef<\n ScrollView,\n React.PropsWithChildren<KeyboardAwareScrollViewProps>\n>(\n (\n {\n children,\n onLayout,\n bottomOffset = 0,\n disableScrollOnKeyboardHide = false,\n enabled = true,\n extraKeyboardSpace = 0,\n ScrollViewComponent = Reanimated.ScrollView,\n ...rest\n },\n ref,\n ) => {\n const scrollViewAnimatedRef = useAnimatedRef<Reanimated.ScrollView>();\n const scrollViewTarget = useSharedValue<number | null>(null);\n const scrollPosition = useSharedValue(0);\n const position = useScrollViewOffset(scrollViewAnimatedRef);\n const currentKeyboardFrameHeight = useSharedValue(0);\n const keyboardHeight = useSharedValue(0);\n const keyboardWillAppear = useSharedValue(false);\n const tag = useSharedValue(-1);\n const initialKeyboardSize = useSharedValue(0);\n const scrollBeforeKeyboardMovement = useSharedValue(0);\n const { input } = useReanimatedFocusedInput();\n const layout = useSharedValue<FocusedInputLayoutChangedEvent | null>(null);\n\n const { height } = useWindowDimensions();\n\n const onRef = useCallback((assignedRef: Reanimated.ScrollView) => {\n if (typeof ref === \"function\") {\n ref(assignedRef);\n } else if (ref) {\n ref.current = assignedRef;\n }\n\n scrollViewAnimatedRef(assignedRef);\n }, []);\n const onScrollViewLayout = useCallback(\n (e: LayoutChangeEvent) => {\n scrollViewTarget.value = findNodeHandle(scrollViewAnimatedRef.current);\n\n onLayout?.(e);\n },\n [onLayout],\n );\n\n /**\n * Function that will scroll a ScrollView as keyboard gets moving\n */\n const maybeScroll = useCallback(\n (e: number, animated: boolean = false) => {\n \"worklet\";\n\n if (!enabled) {\n return 0;\n }\n\n // input belongs to ScrollView\n if (layout.value?.parentScrollViewTarget !== scrollViewTarget.value) {\n return 0;\n }\n\n const visibleRect = height - keyboardHeight.value;\n const absoluteY = layout.value?.layout.absoluteY || 0;\n const inputHeight = layout.value?.layout.height || 0;\n const point = absoluteY + inputHeight;\n\n if (visibleRect - point <= bottomOffset) {\n const relativeScrollTo =\n keyboardHeight.value - (height - point) + bottomOffset;\n const interpolatedScrollTo = interpolate(\n e,\n [initialKeyboardSize.value, keyboardHeight.value],\n [\n 0,\n scrollDistanceWithRespectToSnapPoints(\n relativeScrollTo + scrollPosition.value,\n rest.snapToOffsets,\n ) - scrollPosition.value,\n ],\n );\n const targetScrollY =\n Math.max(interpolatedScrollTo, 0) + scrollPosition.value;\n scrollTo(scrollViewAnimatedRef, 0, targetScrollY, animated);\n\n return interpolatedScrollTo;\n }\n\n if (absoluteY < 0) {\n const positionOnScreen = visibleRect - inputHeight - bottomOffset;\n const topOfScreen = scrollPosition.value + absoluteY;\n\n scrollTo(\n scrollViewAnimatedRef,\n 0,\n topOfScreen - positionOnScreen,\n animated,\n );\n }\n\n return 0;\n },\n [bottomOffset, enabled, height, rest.snapToOffsets],\n );\n\n const syncKeyboardFrame = useCallback(\n (e: NativeEvent) => {\n \"worklet\";\n\n const keyboardFrame = interpolate(\n e.height,\n [0, keyboardHeight.value],\n [0, keyboardHeight.value + extraKeyboardSpace],\n );\n\n currentKeyboardFrameHeight.value = keyboardFrame;\n },\n [extraKeyboardSpace],\n );\n\n const scrollFromCurrentPosition = useCallback(\n (customHeight?: number) => {\n \"worklet\";\n\n const prevScrollPosition = scrollPosition.value;\n const prevLayout = layout.value;\n\n if (!input.value?.layout) {\n return;\n }\n\n // eslint-disable-next-line react-compiler/react-compiler\n layout.value = {\n ...input.value,\n layout: {\n ...input.value.layout,\n height: customHeight ?? input.value.layout.height,\n },\n };\n scrollPosition.value = position.value;\n maybeScroll(keyboardHeight.value, true);\n scrollPosition.value = prevScrollPosition;\n layout.value = prevLayout;\n },\n [maybeScroll],\n );\n const onChangeText = useCallback(() => {\n \"worklet\";\n\n // if typing a text caused layout shift, then we need to ignore this handler\n // because this event will be handled in `useAnimatedReaction` below\n if (layout.value?.layout.height !== input.value?.layout.height) {\n return;\n }\n\n scrollFromCurrentPosition();\n }, [scrollFromCurrentPosition]);\n const onSelectionChange = useCallback(\n (e: FocusedInputSelectionChangedEvent) => {\n \"worklet\";\n\n if (e.selection.start.position !== e.selection.end.position) {\n scrollFromCurrentPosition(e.selection.end.y);\n }\n },\n [scrollFromCurrentPosition],\n );\n\n const onChangeTextHandler = useMemo(\n () => debounce(onChangeText, 200),\n [onChangeText],\n );\n\n useFocusedInputHandler(\n {\n onChangeText: onChangeTextHandler,\n onSelectionChange: onSelectionChange,\n },\n [onChangeTextHandler, onSelectionChange],\n );\n\n useSmoothKeyboardHandler(\n {\n onStart: (e) => {\n \"worklet\";\n\n const keyboardWillChangeSize =\n keyboardHeight.value !== e.height && e.height > 0;\n keyboardWillAppear.value = e.height > 0 && keyboardHeight.value === 0;\n const keyboardWillHide = e.height === 0;\n const focusWasChanged =\n (tag.value !== e.target && e.target !== -1) ||\n keyboardWillChangeSize;\n\n if (keyboardWillChangeSize) {\n initialKeyboardSize.value = keyboardHeight.value;\n }\n\n if (keyboardWillHide) {\n // on back transition need to interpolate as [0, keyboardHeight]\n initialKeyboardSize.value = 0;\n scrollPosition.value = scrollBeforeKeyboardMovement.value;\n }\n\n if (\n keyboardWillAppear.value ||\n keyboardWillChangeSize ||\n focusWasChanged\n ) {\n // persist scroll value\n scrollPosition.value = position.value;\n // just persist height - later will be used in interpolation\n keyboardHeight.value = e.height;\n }\n\n // focus was changed\n if (focusWasChanged) {\n tag.value = e.target;\n\n // save position of focused text input when keyboard starts to move\n layout.value = input.value;\n // save current scroll position - when keyboard will hide we'll reuse\n // this value to achieve smooth hide effect\n scrollBeforeKeyboardMovement.value = position.value;\n }\n\n if (focusWasChanged && !keyboardWillAppear.value) {\n // update position on scroll value, so `onEnd` handler\n // will pick up correct values\n position.value += maybeScroll(e.height, true);\n }\n },\n onMove: (e) => {\n \"worklet\";\n\n syncKeyboardFrame(e);\n\n // if the user has set disableScrollOnKeyboardHide, only auto-scroll when the keyboard opens\n if (!disableScrollOnKeyboardHide || keyboardWillAppear.value) {\n maybeScroll(e.height);\n }\n },\n onEnd: (e) => {\n \"worklet\";\n\n keyboardHeight.value = e.height;\n scrollPosition.value = position.value;\n\n syncKeyboardFrame(e);\n },\n },\n [maybeScroll, disableScrollOnKeyboardHide, syncKeyboardFrame],\n );\n\n useAnimatedReaction(\n () => input.value,\n (current, previous) => {\n if (\n current?.target === previous?.target &&\n current?.layout.height !== previous?.layout.height\n ) {\n const prevLayout = layout.value;\n\n layout.value = input.value;\n scrollPosition.value += maybeScroll(keyboardHeight.value, true);\n layout.value = prevLayout;\n }\n },\n [],\n );\n\n const view = useAnimatedStyle(\n () =>\n enabled\n ? {\n // animations become choppy when scrolling to the end of the `ScrollView` (when the last input is focused)\n // this happens because the layout recalculates on every frame. To avoid this we slightly increase padding\n // by `+1`. In this way we assure, that `scrollTo` will never scroll to the end, because it uses interpolation\n // from 0 to `keyboardHeight`, and here our padding is `keyboardHeight + 1`. It allows us not to re-run layout\n // re-calculation on every animation frame and it helps to achieve smooth animation.\n // see: https://github.com/kirillzyusko/react-native-keyboard-controller/pull/342\n paddingBottom: currentKeyboardFrameHeight.value + 1,\n }\n : {},\n [enabled],\n );\n\n return (\n <ScrollViewComponent\n ref={onRef}\n {...rest}\n onLayout={onScrollViewLayout}\n scrollEventThrottle={16}\n >\n {children}\n <Reanimated.View style={view} />\n </ScrollViewComponent>\n );\n },\n);\n\nexport default KeyboardAwareScrollView;\n"],"mappings":";AAAA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,WAAW,EAAEC,OAAO,QAAQ,OAAO;AAC/D,SAASC,cAAc,QAAQ,cAAc;AAC7C,OAAOC,UAAU,IACfC,WAAW,EACXC,QAAQ,EACRC,mBAAmB,EACnBC,cAAc,EACdC,gBAAgB,EAChBC,mBAAmB,EACnBC,cAAc,QACT,yBAAyB;AAEhC,SACEC,sBAAsB,EACtBC,yBAAyB,EACzBC,mBAAmB,QACd,aAAa;AAEpB,SAASC,wBAAwB,QAAQ,4BAA4B;AACrE,SAASC,QAAQ,EAAEC,qC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rB,IACE,CAAA7C,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAE0C,MAAM,OAAKG,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAEH,MAAM,KACpC,CAAA1C,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEJ,MAAM,CAACC,MAAM,OAAKgD,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAEjD,MAAM,CAACC,MAAM,GAClD;MACA,MAAM+B,UAAU,GAAGhC,MAAM,CAACO,KAAK;MAE/BP,MAAM,CAACO,KAAK,GAAGR,KAAK,CAACQ,KAAK;MAC1BhB,cAAc,CAACgB,KAAK,IAAIC,WAAW,CAACd,cAAc,CAACa,KAAK,EAAE,IAAI,CAAC;MAC/DP,MAAM,CAACO,KAAK,GAAGyB,UAAU;IAC3B;EACF,CAAC,EACD,EACF,CAAC;EAED,MAAMkB,IAAI,GAAGjF,gBAAgB,CAC3B,MACEc,OAAO,GACH;IACA;IACA;IACA;IACA;IACA;IACA;IACAoE,aAAa,EAAE1D,0BAA0B,CAACc,KAAK,GAAG;EACpD,CAAC,GACC,CAAC,CAAC,EACR,CAACxB,OAAO,CACV,CAAC;EAED,oBACExB,KAAA,CAAA6F,aAAA,CAACnE,mBAAmB,EAAAoE,QAAA;IAClBjE,GAAG,EAAEc;EAAM,GACPf,IAAI;IACRP,QAAQ,EAAEyB,kBAAmB;IAC7BiD,mBAAmB,EAAE;EAAG,IAEvB3E,QAAQ,eACTpB,KAAA,CAAA6F,aAAA,CAACxF,UAAU,CAAC2F,IAAI;IAACC,KAAK,EAAEN;EAAK,CAAE,CACZ,CAAC;AAE1B,CACF,CAAC;AAED,eAAexE,uBAAuB","ignoreList":[]}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Platform } from "react-native";
|
|
2
|
+
import { Easing, useAnimatedReaction, useSharedValue, withTiming } from "react-native-reanimated";
|
|
3
|
+
import { useKeyboardHandler } from "../../hooks";
|
|
4
|
+
const IS_ANDROID_ELEVEN_OR_HIGHER = Platform.OS === "android" && Platform.Version >= 30;
|
|
5
|
+
// on these platforms keyboard transitions will be smooth
|
|
6
|
+
const IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS = IS_ANDROID_ELEVEN_OR_HIGHER || Platform.OS === "ios" || Platform.OS === 'harmony';
|
|
7
|
+
// on Android Telegram is not using androidx.core values and uses custom interpolation
|
|
8
|
+
// duration is taken from here: https://github.com/DrKLO/Telegram/blob/e9a35cea54c06277c69d41b8e25d94b5d7ede065/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/AdjustPanLayoutHelper.java#L39
|
|
9
|
+
// and bezier is taken from: https://github.com/DrKLO/Telegram/blob/e9a35cea54c06277c69d41b8e25d94b5d7ede065/TMessagesProj/src/main/java/androidx/recyclerview/widget/ChatListItemAnimator.java#L40
|
|
10
|
+
const TELEGRAM_ANDROID_TIMING_CONFIG = {
|
|
11
|
+
duration: 250,
|
|
12
|
+
easing: Easing.bezier(0.19919472913616398, 0.010644531250000006, 0.27920937042459737, 0.91025390625)
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Hook that uses default transitions for iOS and Android > 11, and uses
|
|
17
|
+
* custom interpolation on Android < 11 to achieve more smooth animation
|
|
18
|
+
*/
|
|
19
|
+
export const useSmoothKeyboardHandler = (handler, deps) => {
|
|
20
|
+
const target = useSharedValue(-1);
|
|
21
|
+
const height = useSharedValue(0);
|
|
22
|
+
const persistedHeight = useSharedValue(0);
|
|
23
|
+
const animatedKeyboardHeight = useSharedValue(0);
|
|
24
|
+
useAnimatedReaction(() => {
|
|
25
|
+
if (IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (persistedHeight.value === 0) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const event = {
|
|
32
|
+
// it'll be always `TELEGRAM_ANDROID_TIMING_CONFIG.duration`, since we're running animation via `withTiming`
|
|
33
|
+
duration: TELEGRAM_ANDROID_TIMING_CONFIG.duration,
|
|
34
|
+
target: target.value,
|
|
35
|
+
height: animatedKeyboardHeight.value,
|
|
36
|
+
progress: animatedKeyboardHeight.value / persistedHeight.value
|
|
37
|
+
};
|
|
38
|
+
return event;
|
|
39
|
+
}, evt => {
|
|
40
|
+
var _handler$onMove;
|
|
41
|
+
if (!evt) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
(_handler$onMove = handler.onMove) === null || _handler$onMove === void 0 || _handler$onMove.call(handler, evt);
|
|
45
|
+
|
|
46
|
+
// dispatch `onEnd`
|
|
47
|
+
if (evt.height === height.value) {
|
|
48
|
+
var _handler$onEnd;
|
|
49
|
+
(_handler$onEnd = handler.onEnd) === null || _handler$onEnd === void 0 || _handler$onEnd.call(handler, evt);
|
|
50
|
+
// eslint-disable-next-line react-compiler/react-compiler
|
|
51
|
+
persistedHeight.value = height.value;
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
// REA uses own version of `DependencyList` and it's not compatible with the same type from React
|
|
55
|
+
deps);
|
|
56
|
+
useKeyboardHandler({
|
|
57
|
+
onStart: e => {
|
|
58
|
+
"worklet";
|
|
59
|
+
|
|
60
|
+
// immediately dispatch onStart/onEnd events if onStart dispatched with the same height
|
|
61
|
+
// and don't wait for animation 250ms
|
|
62
|
+
var _handler$onStart2;
|
|
63
|
+
if (!IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS && e.height === persistedHeight.value) {
|
|
64
|
+
var _handler$onStart, _handler$onEnd2;
|
|
65
|
+
(_handler$onStart = handler.onStart) === null || _handler$onStart === void 0 || _handler$onStart.call(handler, e);
|
|
66
|
+
(_handler$onEnd2 = handler.onEnd) === null || _handler$onEnd2 === void 0 || _handler$onEnd2.call(handler, e);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
target.value = e.target;
|
|
70
|
+
height.value = e.height;
|
|
71
|
+
if (e.height > 0) {
|
|
72
|
+
persistedHeight.value = e.height;
|
|
73
|
+
}
|
|
74
|
+
// if we are running on Android < 9, then we are using custom interpolation
|
|
75
|
+
// to achieve smoother animation and use `animatedKeyboardHeight` as animation
|
|
76
|
+
// driver
|
|
77
|
+
if (!IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {
|
|
78
|
+
animatedKeyboardHeight.value = withTiming(e.height, TELEGRAM_ANDROID_TIMING_CONFIG);
|
|
79
|
+
}
|
|
80
|
+
(_handler$onStart2 = handler.onStart) === null || _handler$onStart2 === void 0 || _handler$onStart2.call(handler, {
|
|
81
|
+
...e,
|
|
82
|
+
duration: IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS ? e.duration : TELEGRAM_ANDROID_TIMING_CONFIG.duration
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
onMove: e => {
|
|
86
|
+
"worklet";
|
|
87
|
+
|
|
88
|
+
if (IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {
|
|
89
|
+
var _handler$onMove2;
|
|
90
|
+
(_handler$onMove2 = handler.onMove) === null || _handler$onMove2 === void 0 || _handler$onMove2.call(handler, e);
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
onEnd: e => {
|
|
94
|
+
"worklet";
|
|
95
|
+
|
|
96
|
+
if (IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {
|
|
97
|
+
var _handler$onEnd3;
|
|
98
|
+
(_handler$onEnd3 = handler.onEnd) === null || _handler$onEnd3 === void 0 || _handler$onEnd3.call(handler, e);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}, deps);
|
|
102
|
+
};
|
|
103
|
+
//# sourceMappingURL=useSmoothKeyboardHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Platform","Easing","useAnimatedReaction","useSharedValue","withTiming","useKeyboardHandler","IS_ANDROID_ELEVEN_OR_HIGHER","OS","Version","IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS","TELEGRAM_ANDROID_TIMING_CONFIG","duration","easing","bezier","useSmoothKeyboardHandler","handler","deps","target","height","persistedHeight","animatedKeyboardHeight","value","event","progress","evt","_handler$onMove","onMove","call","_handler$onEnd","onEnd","onStart","e","_handler$onStart2","_handler$onStart","_handler$onEnd2","_handler$onMove2","_handler$onEnd3"],"sources":["useSmoothKeyboardHandler.ts"],"sourcesContent":["import { Platform } from \"react-native\";\nimport {\n Easing,\n useAnimatedReaction,\n useSharedValue,\n withTiming,\n} from \"react-native-reanimated\";\n\nimport { useKeyboardHandler } from \"../../hooks\";\n\nconst IS_ANDROID_ELEVEN_OR_HIGHER =\n Platform.OS === \"android\" && Platform.Version >= 30;\n// on these platforms keyboard transitions will be smooth\nconst IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS =\n IS_ANDROID_ELEVEN_OR_HIGHER || Platform.OS === \"ios\" || Platform.OS as string === 'harmony';\n// on Android Telegram is not using androidx.core values and uses custom interpolation\n// duration is taken from here: https://github.com/DrKLO/Telegram/blob/e9a35cea54c06277c69d41b8e25d94b5d7ede065/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/AdjustPanLayoutHelper.java#L39\n// and bezier is taken from: https://github.com/DrKLO/Telegram/blob/e9a35cea54c06277c69d41b8e25d94b5d7ede065/TMessagesProj/src/main/java/androidx/recyclerview/widget/ChatListItemAnimator.java#L40\nconst TELEGRAM_ANDROID_TIMING_CONFIG = {\n duration: 250,\n easing: Easing.bezier(\n 0.19919472913616398,\n 0.010644531250000006,\n 0.27920937042459737,\n 0.91025390625,\n ),\n};\n\n/**\n * Hook that uses default transitions for iOS and Android > 11, and uses\n * custom interpolation on Android < 11 to achieve more smooth animation\n */\nexport const useSmoothKeyboardHandler: typeof useKeyboardHandler = (\n handler,\n deps,\n) => {\n const target = useSharedValue(-1);\n const height = useSharedValue(0);\n const persistedHeight = useSharedValue(0);\n const animatedKeyboardHeight = useSharedValue(0);\n\n useAnimatedReaction(\n () => {\n if (IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {\n return;\n }\n if (persistedHeight.value === 0) {\n return;\n }\n const event = {\n // it'll be always `TELEGRAM_ANDROID_TIMING_CONFIG.duration`, since we're running animation via `withTiming`\n duration: TELEGRAM_ANDROID_TIMING_CONFIG.duration,\n target: target.value,\n height: animatedKeyboardHeight.value,\n progress: animatedKeyboardHeight.value / persistedHeight.value,\n };\n return event;\n },\n (evt) => {\n if (!evt) {\n return;\n }\n handler.onMove?.(evt);\n\n // dispatch `onEnd`\n if (evt.height === height.value) {\n handler.onEnd?.(evt);\n // eslint-disable-next-line react-compiler/react-compiler\n persistedHeight.value = height.value;\n }\n },\n // REA uses own version of `DependencyList` and it's not compatible with the same type from React\n deps as unknown[],\n );\n\n useKeyboardHandler(\n {\n onStart: (e) => {\n \"worklet\";\n\n // immediately dispatch onStart/onEnd events if onStart dispatched with the same height\n // and don't wait for animation 250ms\n if (\n !IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS &&\n e.height === persistedHeight.value\n ) {\n handler.onStart?.(e);\n handler.onEnd?.(e);\n\n return;\n }\n\n target.value = e.target;\n height.value = e.height;\n\n if (e.height > 0) {\n persistedHeight.value = e.height;\n }\n // if we are running on Android < 9, then we are using custom interpolation\n // to achieve smoother animation and use `animatedKeyboardHeight` as animation\n // driver\n if (!IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {\n animatedKeyboardHeight.value = withTiming(\n e.height,\n TELEGRAM_ANDROID_TIMING_CONFIG,\n );\n }\n\n handler.onStart?.({\n ...e,\n duration: IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS\n ? e.duration\n : TELEGRAM_ANDROID_TIMING_CONFIG.duration,\n });\n },\n onMove: (e) => {\n \"worklet\";\n\n if (IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {\n handler.onMove?.(e);\n }\n },\n onEnd: (e) => {\n \"worklet\";\n\n if (IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {\n handler.onEnd?.(e);\n }\n },\n },\n deps,\n );\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,GAAGjB,UAAU,CACvC2B,CAAC,CAACb,MAAM,EACRR,8BACF,CAAC;MACH;MAEA,CAAAsB,iBAAA,GAAAjB,OAAO,CAACe,OAAO,cAAAE,iBAAA,eAAfA,iBAAA,CAAAL,IAAA,CAAAZ,OAAO,EAAW;QAChB,GAAGgB,CAAC;QACJpB,QAAQ,EAAEF,kCAAkC,GACxCsB,CAAC,CAACpB,QAAQ,GACVD,8BAA8B,CAACC;MACrC,CAAC,CAAC;IACJ,CAAC;IACDe,MAAM,EAAGK,CAAC,IAAK;MACb,SAAS;;MAET,IAAItB,kCAAkC,EAAE;QAAA,IAAA0B,gBAAA;QACtC,CAAAA,gBAAA,GAAApB,OAAO,CAACW,MAAM,cAAAS,gBAAA,eAAdA,gBAAA,CAAAR,IAAA,CAAAZ,OAAO,EAAUgB,CAAC,CAAC;MACrB;IACF,CAAC;IACDF,KAAK,EAAGE,CAAC,IAAK;MACZ,SAAS;;MAET,IAAItB,kCAAkC,EAAE;QAAA,IAAA2B,eAAA;QACtC,CAAAA,eAAA,GAAArB,OAAO,CAACc,KAAK,cAAAO,eAAA,eAAbA,eAAA,CAAAT,IAAA,CAAAZ,OAAO,EAASgB,CAAC,CAAC;MACpB;IACF;EACF,CAAC,EACDf,IACF,CAAC;AACH,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export const debounce = (worklet, wait = 0) => {
|
|
2
|
+
"worklet";
|
|
3
|
+
|
|
4
|
+
const value = {
|
|
5
|
+
time: 0
|
|
6
|
+
};
|
|
7
|
+
return (...args) => {
|
|
8
|
+
"worklet";
|
|
9
|
+
|
|
10
|
+
const t = Date.now();
|
|
11
|
+
const now = t - value.time;
|
|
12
|
+
if (now < wait) {
|
|
13
|
+
value.time = t;
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
value.time = t;
|
|
17
|
+
return worklet(...args);
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export const scrollDistanceWithRespectToSnapPoints = (defaultScrollValue, snapPoints) => {
|
|
21
|
+
"worklet";
|
|
22
|
+
|
|
23
|
+
let snapPoint;
|
|
24
|
+
if (snapPoints) {
|
|
25
|
+
snapPoint = snapPoints.find(offset => offset >= defaultScrollValue);
|
|
26
|
+
}
|
|
27
|
+
return snapPoint ?? defaultScrollValue;
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["debounce","worklet","wait","value","time","args","t","Date","now","scrollDistanceWithRespectToSnapPoints","defaultScrollValue","snapPoints","snapPoint","find","offset"],"sources":["utils.ts"],"sourcesContent":["export const debounce = <F extends (...args: Parameters<F>) => ReturnType<F>>(\n worklet: F,\n wait = 0,\n) => {\n \"worklet\";\n\n const value = {\n time: 0,\n };\n\n return (...args: Parameters<F>): ReturnType<F> | void => {\n \"worklet\";\n\n const t = Date.now();\n const now = t - value.time;\n\n if (now < wait) {\n value.time = t;\n return;\n }\n\n value.time = t;\n\n return worklet(...args);\n };\n};\n\nexport const scrollDistanceWithRespectToSnapPoints = (\n defaultScrollValue: number,\n snapPoints?: number[],\n) => {\n \"worklet\";\n\n let snapPoint: number | undefined;\n\n if (snapPoints) {\n snapPoint = snapPoints.find((offset) => offset >= defaultScrollValue);\n }\n\n return snapPoint ?? defaultScrollValue;\n};\n"],"mappings":"AAAA,OAAO,MAAMA,QAAQ,GAAGA,CACtBC,OAAU,EACVC,IAAI,GAAG,CAAC,KACL;EACH,SAAS;;EAET,MAAMC,KAAK,GAAG;IACZC,IAAI,EAAE;EACR,CAAC;EAED,OAAO,CAAC,GAAGC,IAAmB,KAA2B;IACvD,SAAS;;IAET,MAAMC,CAAC,GAAGC,IAAI,CAACC,GAAG,CAAC,CAAC;IACpB,MAAMA,GAAG,GAAGF,CAAC,GAAGH,KAAK,CAACC,IAAI;IAE1B,IAAII,GAAG,GAAGN,IAAI,EAAE;MACdC,KAAK,CAACC,IAAI,GAAGE,CAAC;MACd;IACF;IAEAH,KAAK,CAACC,IAAI,GAAGE,CAAC;IAEd,OAAOL,OAAO,CAAC,GAAGI,IAAI,CAAC;EACzB,CAAC;AACH,CAAC;AAED,OAAO,MAAMI,qCAAqC,GAAGA,CACnDC,kBAA0B,EAC1BC,UAAqB,KAClB;EACH,SAAS;;EAET,IAAIC,SAA6B;EAEjC,IAAID,UAAU,EAAE;IACdC,SAAS,GAAGD,UAAU,CAACE,IAAI,CAAEC,MAAM,IAAKA,MAAM,IAAIJ,kBAAkB,CAAC;EACvE;EAEA,OAAOE,SAAS,IAAIF,kBAAkB;AACxC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
import React, { forwardRef, useMemo } from "react";
|
|
3
|
+
import Reanimated, { interpolate, useAnimatedStyle } from "react-native-reanimated";
|
|
4
|
+
import { useReanimatedKeyboardAnimation } from "../../hooks";
|
|
5
|
+
const KeyboardStickyView = /*#__PURE__*/forwardRef(({
|
|
6
|
+
children,
|
|
7
|
+
offset: {
|
|
8
|
+
closed = 0,
|
|
9
|
+
opened = 0
|
|
10
|
+
} = {},
|
|
11
|
+
style,
|
|
12
|
+
enabled = true,
|
|
13
|
+
...props
|
|
14
|
+
}, ref) => {
|
|
15
|
+
const {
|
|
16
|
+
height,
|
|
17
|
+
progress
|
|
18
|
+
} = useReanimatedKeyboardAnimation();
|
|
19
|
+
const stickyViewStyle = useAnimatedStyle(() => {
|
|
20
|
+
const offset = interpolate(progress.value, [0, 1], [closed, opened]);
|
|
21
|
+
return {
|
|
22
|
+
transform: [{
|
|
23
|
+
translateY: enabled ? height.value + offset : closed
|
|
24
|
+
}]
|
|
25
|
+
};
|
|
26
|
+
}, [closed, opened, enabled]);
|
|
27
|
+
const styles = useMemo(() => [style, stickyViewStyle], [style, stickyViewStyle]);
|
|
28
|
+
return /*#__PURE__*/React.createElement(Reanimated.View, _extends({
|
|
29
|
+
ref: ref,
|
|
30
|
+
style: styles
|
|
31
|
+
}, props), children);
|
|
32
|
+
});
|
|
33
|
+
export default KeyboardStickyView;
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","forwardRef","useMemo","Reanimated","interpolate","useAnimatedStyle","useReanimatedKeyboardAnimation","KeyboardStickyView","children","offset","closed","opened","style","enabled","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\n /** Controls whether this `KeyboardStickyView` instance should take effect. Default is `true` */\n enabled?: boolean;\n} & ViewProps;\n\nconst KeyboardStickyView = forwardRef<\n View,\n React.PropsWithChildren<KeyboardStickyViewProps>\n>(\n (\n {\n children,\n offset: { closed = 0, opened = 0 } = {},\n style,\n enabled = true,\n ...props\n },\n ref,\n ) => {\n const { height, progress } = useReanimatedKeyboardAnimation();\n const stickyViewStyle = useAnimatedStyle(() => {\n const offset = interpolate(progress.value, [0, 1], [closed, opened]);\n\n return {\n transform: [{ translateY: enabled ? height.value + offset : closed }],\n };\n }, [closed, opened, enabled]);\n\n const styles = useMemo(\n () => [style, stickyViewStyle],\n [style, stickyViewStyle],\n );\n\n return (\n <Reanimated.View ref={ref} style={styles} {...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]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import React, { useMemo } from "react";
|
|
2
|
+
import { Animated, StyleSheet, View } from "react-native";
|
|
3
|
+
import useColorScheme from "../hooks/useColorScheme";
|
|
4
|
+
const ArrowComponent = ({
|
|
5
|
+
type,
|
|
6
|
+
disabled,
|
|
7
|
+
theme
|
|
8
|
+
}) => {
|
|
9
|
+
const colorScheme = useColorScheme();
|
|
10
|
+
const color = useMemo(() => ({
|
|
11
|
+
backgroundColor: disabled ? theme[colorScheme].disabled : theme[colorScheme].primary
|
|
12
|
+
}), [disabled, theme, colorScheme]);
|
|
13
|
+
const left = useMemo(() => [styles.arrowLeftLine, color], [color]);
|
|
14
|
+
const right = useMemo(() => [styles.arrowRightLine, color], [color]);
|
|
15
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
16
|
+
style: type === "next" ? styles.arrowDownContainer : styles.arrowUpContainer
|
|
17
|
+
}, /*#__PURE__*/React.createElement(View, {
|
|
18
|
+
style: styles.arrow
|
|
19
|
+
}, /*#__PURE__*/React.createElement(Animated.View, {
|
|
20
|
+
style: left
|
|
21
|
+
}), /*#__PURE__*/React.createElement(Animated.View, {
|
|
22
|
+
style: right
|
|
23
|
+
})));
|
|
24
|
+
};
|
|
25
|
+
const arrowLine = {
|
|
26
|
+
width: 13,
|
|
27
|
+
height: 2,
|
|
28
|
+
borderRadius: 1
|
|
29
|
+
};
|
|
30
|
+
const arrowUpContainer = {
|
|
31
|
+
marginHorizontal: 5,
|
|
32
|
+
width: 30,
|
|
33
|
+
height: 30,
|
|
34
|
+
justifyContent: "center",
|
|
35
|
+
alignItems: "center"
|
|
36
|
+
};
|
|
37
|
+
const styles = StyleSheet.create({
|
|
38
|
+
arrowUpContainer: arrowUpContainer,
|
|
39
|
+
arrowDownContainer: {
|
|
40
|
+
...arrowUpContainer,
|
|
41
|
+
transform: [{
|
|
42
|
+
rotate: "180deg"
|
|
43
|
+
}]
|
|
44
|
+
},
|
|
45
|
+
arrow: {
|
|
46
|
+
width: 20,
|
|
47
|
+
height: 20,
|
|
48
|
+
flexDirection: "row",
|
|
49
|
+
alignItems: "center",
|
|
50
|
+
justifyContent: "space-between"
|
|
51
|
+
},
|
|
52
|
+
arrowLeftLine: {
|
|
53
|
+
...arrowLine,
|
|
54
|
+
transform: [{
|
|
55
|
+
rotate: "-45deg"
|
|
56
|
+
}],
|
|
57
|
+
left: -0.5
|
|
58
|
+
},
|
|
59
|
+
arrowRightLine: {
|
|
60
|
+
...arrowLine,
|
|
61
|
+
transform: [{
|
|
62
|
+
rotate: "45deg"
|
|
63
|
+
}],
|
|
64
|
+
left: -5.5
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
export default ArrowComponent;
|
|
68
|
+
//# sourceMappingURL=Arrow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","useMemo","Animated","StyleSheet","View","useColorScheme","ArrowComponent","type","disabled","theme","colorScheme","color","backgroundColor","primary","left","styles","arrowLeftLine","right","arrowRightLine","createElement","style","arrowDownContainer","arrowUpContainer","arrow","arrowLine","width","height","borderRadius","marginHorizontal","justifyContent","alignItems","create","transform","rotate","flexDirection"],"sources":["Arrow.tsx"],"sourcesContent":["import React, { useMemo } from \"react\";\nimport { Animated, StyleSheet, View } from \"react-native\";\n\nimport useColorScheme from \"../hooks/useColorScheme\";\n\nimport type { KeyboardToolbarTheme } from \"./types\";\nimport type { ViewStyle } from \"react-native\";\n\ntype ArrowProps = {\n type: \"prev\" | \"next\";\n disabled?: boolean;\n theme: KeyboardToolbarTheme;\n};\n\nconst ArrowComponent: React.FC<ArrowProps> = ({ type, disabled, theme }) => {\n const colorScheme = useColorScheme();\n\n const color = useMemo(\n () => ({\n backgroundColor: disabled\n ? theme[colorScheme].disabled\n : theme[colorScheme].primary,\n }),\n [disabled, theme, colorScheme],\n );\n const left = useMemo(() => [styles.arrowLeftLine, color], [color]);\n const right = useMemo(() => [styles.arrowRightLine, color], [color]);\n\n return (\n <View\n style={\n type === \"next\" ? styles.arrowDownContainer : styles.arrowUpContainer\n }\n >\n <View style={styles.arrow}>\n <Animated.View style={left} />\n <Animated.View style={right} />\n </View>\n </View>\n );\n};\n\nconst arrowLine: ViewStyle = {\n width: 13,\n height: 2,\n borderRadius: 1,\n};\nconst arrowUpContainer: ViewStyle = {\n marginHorizontal: 5,\n width: 30,\n height: 30,\n justifyContent: \"center\",\n alignItems: \"center\",\n};\nconst styles = StyleSheet.create({\n arrowUpContainer: arrowUpContainer,\n arrowDownContainer: {\n ...arrowUpContainer,\n transform: [{ rotate: \"180deg\" }],\n },\n arrow: {\n width: 20,\n height: 20,\n flexDirection: \"row\",\n alignItems: \"center\",\n justifyContent: \"space-between\",\n },\n arrowLeftLine: {\n ...arrowLine,\n transform: [{ rotate: \"-45deg\" }],\n left: -0.5,\n },\n arrowRightLine: {\n ...arrowLine,\n transform: [{ rotate: \"45deg\" }],\n left: -5.5,\n },\n});\n\nexport default ArrowComponent;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,OAAO,QAAQ,OAAO;AACtC,SAASC,QAAQ,EAAEC,UAAU,EAAEC,IAAI,QAAQ,cAAc;AAEzD,OAAOC,cAAc,MAAM,yBAAyB;AAWpD,MAAMC,cAAoC,GAAGA,CAAC;EAAEC,IAAI;EAAEC,QAAQ;EAAEC;AAAM,CAAC,KAAK;EAC1E,MAAMC,WAAW,GAAGL,cAAc,CAAC,CAAC;EAEpC,MAAMM,KAAK,GAAGV,OAAO,CACnB,OAAO;IACLW,eAAe,EAAEJ,QAAQ,GACrBC,KAAK,CAACC,WAAW,CAAC,CAACF,QAAQ,GAC3BC,KAAK,CAACC,WAAW,CAAC,CAACG;EACzB,CAAC,CAAC,EACF,CAACL,QAAQ,EAAEC,KAAK,EAAEC,WAAW,CAC/B,CAAC;EACD,MAAMI,IAAI,GAAGb,OAAO,CAAC,MAAM,CAACc,MAAM,CAACC,aAAa,EAAEL,KAAK,CAAC,EAAE,CAACA,KAAK,CAAC,C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