react-native-keyboard-controller 1.0.0-alpha.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 -0
- package/README.md +88 -0
- package/android/.gradle/6.8/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/6.8/fileChanges/last-build.bin +0 -0
- package/android/.gradle/6.8/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/6.8/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
- package/android/.gradle/checksums/checksums.lock +0 -0
- package/android/.gradle/configuration-cache/gc.properties +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/build.gradle +129 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
- package/android/gradle.properties +3 -0
- package/android/gradlew +185 -0
- package/android/gradlew.bat +89 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/EdgeToEdgeReactViewGroup.kt +18 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/KeyboardControllerModule.kt +39 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/KeyboardControllerPackage.kt +16 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/KeyboardControllerViewManager.kt +57 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/TranslateDeferringInsetsAnimationCallback.kt +150 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/events/KeyboardTransitionEvent.kt +23 -0
- package/ios/KeyboardController-Bridging-Header.h +1 -0
- package/ios/KeyboardController.xcodeproj/project.pbxproj +293 -0
- package/ios/KeyboardController.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/ios/KeyboardController.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/ios/KeyboardController.xcodeproj/project.xcworkspace/xcuserdata/kiryl.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/KeyboardController.xcodeproj/xcuserdata/kiryl.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
- package/ios/KeyboardControllerModule-Header.h +10 -0
- package/ios/KeyboardControllerModule.m +21 -0
- package/ios/KeyboardControllerModule.swift +38 -0
- package/ios/KeyboardControllerViewManager.m +7 -0
- package/ios/KeyboardControllerViewManager.swift +74 -0
- package/ios/KeyboardMoveEvent.swift +37 -0
- package/lib/commonjs/animated.js +145 -0
- package/lib/commonjs/animated.js.map +1 -0
- package/lib/commonjs/index.js +45 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/native.js +48 -0
- package/lib/commonjs/native.js.map +1 -0
- package/lib/commonjs/replicas.js +138 -0
- package/lib/commonjs/replicas.js.map +1 -0
- package/lib/module/animated.js +117 -0
- package/lib/module/animated.js.map +1 -0
- package/lib/module/index.js +4 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/native.js +32 -0
- package/lib/module/native.js.map +1 -0
- package/lib/module/replicas.js +114 -0
- package/lib/module/replicas.js.map +1 -0
- package/lib/typescript/animated.d.ts +22 -0
- package/lib/typescript/index.d.ts +3 -0
- package/lib/typescript/native.d.ts +36 -0
- package/lib/typescript/replicas.d.ts +45 -0
- package/package.json +149 -0
- package/react-native-keyboard-controller.podspec +19 -0
- package/src/animated.tsx +166 -0
- package/src/index.ts +3 -0
- package/src/native.ts +82 -0
- package/src/replicas.ts +152 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
@objc(KeyboardControllerViewManager)
|
|
2
|
+
class KeyboardControllerViewManager: RCTViewManager {
|
|
3
|
+
override class func requiresMainQueueSetup() -> Bool {
|
|
4
|
+
return false
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
override func view() -> (KeyboardControllerView) {
|
|
8
|
+
return KeyboardControllerView(frame: CGRect.zero, eventDispatcher: self.bridge.eventDispatcher())
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
class KeyboardControllerView : UIView {
|
|
13
|
+
private var eventDispatcher: RCTEventDispatcherProtocol
|
|
14
|
+
@objc var onKeyboardMove: RCTDirectEventBlock?
|
|
15
|
+
|
|
16
|
+
init(frame: CGRect, eventDispatcher: RCTEventDispatcherProtocol) {
|
|
17
|
+
self.eventDispatcher = eventDispatcher
|
|
18
|
+
super.init(frame: frame)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
required init?(coder: NSCoder) {
|
|
22
|
+
fatalError("init(coder:) has not been implemented")
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
override func willMove(toWindow newWindow: UIWindow?) {
|
|
26
|
+
super.willMove(toWindow: newWindow)
|
|
27
|
+
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillDisappear), name: UIResponder.keyboardWillHideNotification, object: nil)
|
|
28
|
+
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillAppear), name: UIResponder.keyboardWillShowNotification, object: nil)
|
|
29
|
+
NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidAppear), name: UIResponder.keyboardDidShowNotification, object: nil)
|
|
30
|
+
NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidDisappear), name: UIResponder.keyboardDidHideNotification, object: nil)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@objc func keyboardWillAppear(_ notification: Notification) {
|
|
34
|
+
if let keyboardFrame: NSValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue {
|
|
35
|
+
let keyboardHeight = keyboardFrame.cgRectValue.size.height
|
|
36
|
+
|
|
37
|
+
self.eventDispatcher.send(KeyboardMoveEvent(reactTag: self.reactTag, height: -keyboardHeight as NSNumber, progress: 1))
|
|
38
|
+
|
|
39
|
+
var data = [AnyHashable: Any]()
|
|
40
|
+
data["height"] = keyboardHeight
|
|
41
|
+
KeyboardController.shared?.sendEvent(withName: "KeyboardController::keyboardWillShow", body: data)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@objc func keyboardWillDisappear() {
|
|
46
|
+
self.eventDispatcher.send(KeyboardMoveEvent(reactTag: self.reactTag, height: 0, progress: 0))
|
|
47
|
+
|
|
48
|
+
var data = [AnyHashable: Any]()
|
|
49
|
+
data["height"] = 0
|
|
50
|
+
KeyboardController.shared?.sendEvent(withName: "KeyboardController::keyboardWillHide", body: data)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@objc func keyboardDidAppear(_ notification: Notification) {
|
|
54
|
+
if let keyboardFrame: NSValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue {
|
|
55
|
+
let keyboardHeight = keyboardFrame.cgRectValue.size.height
|
|
56
|
+
|
|
57
|
+
var data = [AnyHashable: Any]()
|
|
58
|
+
data["height"] = keyboardHeight
|
|
59
|
+
|
|
60
|
+
KeyboardController.shared?.sendEvent(withName: "KeyboardController::keyboardDidShow", body: data)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@objc func keyboardDidDisappear() {
|
|
65
|
+
var data = [AnyHashable: Any]()
|
|
66
|
+
data["height"] = 0
|
|
67
|
+
KeyboardController.shared?.sendEvent(withName: "KeyboardController::keyboardDidHide", body: data)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
override func willRemoveSubview(_ subview: UIView) {
|
|
71
|
+
super.willRemoveSubview(subview)
|
|
72
|
+
NotificationCenter.default.removeObserver(self) // TODO: correct place?
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//
|
|
2
|
+
// KeyboardMoveEvent.swift
|
|
3
|
+
// KeyboardController
|
|
4
|
+
//
|
|
5
|
+
// Created by Kiryl Ziusko on 26.04.22.
|
|
6
|
+
// Copyright © 2022 Facebook. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
class KeyboardMoveEvent: NSObject, RCTEvent {
|
|
10
|
+
var viewTag: NSNumber!
|
|
11
|
+
var eventName: String = "onKeyboardMove"
|
|
12
|
+
var coalescingKey: UInt16 = 0
|
|
13
|
+
var height: NSNumber!
|
|
14
|
+
var progress: NSNumber!
|
|
15
|
+
|
|
16
|
+
func canCoalesce() -> Bool {
|
|
17
|
+
return false
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
func coalesce(with newEvent: RCTEvent!) -> RCTEvent! {
|
|
21
|
+
return newEvent
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static func moduleDotMethod() -> String! {
|
|
25
|
+
return "RCTEventEmitter.receiveEvent"
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
func arguments() -> [Any]! {
|
|
29
|
+
return [self.viewTag, RCTNormalizeInputEventName(self.eventName), ["height": self.height, "progress": self.progress]]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
init(reactTag: NSNumber, height: NSNumber, progress: NSNumber) {
|
|
33
|
+
self.viewTag = reactTag
|
|
34
|
+
self.height = height
|
|
35
|
+
self.progress = progress
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useReanimatedKeyboardAnimation = exports.useKeyboardAnimation = exports.styles = exports.KeyboardProvider = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
|
|
10
|
+
var _reactNative = require("react-native");
|
|
11
|
+
|
|
12
|
+
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
|
|
13
|
+
|
|
14
|
+
var _native = require("./native");
|
|
15
|
+
|
|
16
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
|
+
|
|
18
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
19
|
+
|
|
20
|
+
const KeyboardControllerViewAnimated = _reactNativeReanimated.default.createAnimatedComponent(_reactNative.Animated.createAnimatedComponent(_native.KeyboardControllerView));
|
|
21
|
+
|
|
22
|
+
const defaultContext = {
|
|
23
|
+
animated: {
|
|
24
|
+
progress: new _reactNative.Animated.Value(0),
|
|
25
|
+
height: new _reactNative.Animated.Value(0)
|
|
26
|
+
},
|
|
27
|
+
reanimated: {
|
|
28
|
+
progress: {
|
|
29
|
+
value: 0
|
|
30
|
+
},
|
|
31
|
+
height: {
|
|
32
|
+
value: 0
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const KeyboardContext = /*#__PURE__*/_react.default.createContext(defaultContext);
|
|
38
|
+
|
|
39
|
+
const useKeyboardAnimation = () => {
|
|
40
|
+
(0, _native.useResizeMode)();
|
|
41
|
+
const context = (0, _react.useContext)(KeyboardContext);
|
|
42
|
+
return context.animated;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
exports.useKeyboardAnimation = useKeyboardAnimation;
|
|
46
|
+
|
|
47
|
+
const useReanimatedKeyboardAnimation = () => {
|
|
48
|
+
(0, _native.useResizeMode)();
|
|
49
|
+
const context = (0, _react.useContext)(KeyboardContext);
|
|
50
|
+
return context.reanimated;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
exports.useReanimatedKeyboardAnimation = useReanimatedKeyboardAnimation;
|
|
54
|
+
|
|
55
|
+
function useAnimatedKeyboardHandler(handlers, dependencies) {
|
|
56
|
+
const {
|
|
57
|
+
context,
|
|
58
|
+
doDependenciesDiffer
|
|
59
|
+
} = (0, _reactNativeReanimated.useHandler)(handlers, dependencies);
|
|
60
|
+
return (0, _reactNativeReanimated.useEvent)(event => {
|
|
61
|
+
'worklet';
|
|
62
|
+
|
|
63
|
+
const {
|
|
64
|
+
onKeyboardMove
|
|
65
|
+
} = handlers;
|
|
66
|
+
|
|
67
|
+
if (onKeyboardMove && event.eventName.endsWith('onKeyboardMove')) {
|
|
68
|
+
onKeyboardMove(event, context);
|
|
69
|
+
}
|
|
70
|
+
}, ['onKeyboardMove'], doDependenciesDiffer);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const styles = _reactNative.StyleSheet.create({
|
|
74
|
+
container: {
|
|
75
|
+
flex: 1
|
|
76
|
+
},
|
|
77
|
+
hidden: {
|
|
78
|
+
display: 'none',
|
|
79
|
+
position: 'absolute'
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
exports.styles = styles;
|
|
84
|
+
|
|
85
|
+
const KeyboardProvider = _ref => {
|
|
86
|
+
let {
|
|
87
|
+
children
|
|
88
|
+
} = _ref;
|
|
89
|
+
const progress = (0, _react.useMemo)(() => new _reactNative.Animated.Value(0), []);
|
|
90
|
+
const height = (0, _react.useMemo)(() => new _reactNative.Animated.Value(0), []);
|
|
91
|
+
const progressSV = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
92
|
+
const heightSV = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
93
|
+
const context = (0, _react.useMemo)(() => ({
|
|
94
|
+
animated: {
|
|
95
|
+
progress: progress,
|
|
96
|
+
height: height
|
|
97
|
+
},
|
|
98
|
+
reanimated: {
|
|
99
|
+
progress: progressSV,
|
|
100
|
+
height: heightSV
|
|
101
|
+
}
|
|
102
|
+
}), []);
|
|
103
|
+
const onKeyboardMove = (0, _react.useMemo)(() => _reactNative.Animated.event([{
|
|
104
|
+
nativeEvent: {
|
|
105
|
+
progress,
|
|
106
|
+
height
|
|
107
|
+
}
|
|
108
|
+
}], {
|
|
109
|
+
useNativeDriver: true
|
|
110
|
+
}), []);
|
|
111
|
+
const handler = useAnimatedKeyboardHandler({
|
|
112
|
+
onKeyboardMove: event => {
|
|
113
|
+
'worklet';
|
|
114
|
+
|
|
115
|
+
progressSV.value = event.progress;
|
|
116
|
+
heightSV.value = event.height;
|
|
117
|
+
}
|
|
118
|
+
}, []);
|
|
119
|
+
return /*#__PURE__*/_react.default.createElement(KeyboardContext.Provider, {
|
|
120
|
+
value: context
|
|
121
|
+
}, /*#__PURE__*/_react.default.createElement(KeyboardControllerViewAnimated, {
|
|
122
|
+
onKeyboardMoveReanimated: handler,
|
|
123
|
+
onKeyboardMove: onKeyboardMove,
|
|
124
|
+
style: styles.container
|
|
125
|
+
}, /*#__PURE__*/_react.default.createElement(_reactNative.Animated.View, {
|
|
126
|
+
style: [// we are using this small hack, because if the component (where
|
|
127
|
+
// animated value has been used) is unmounted, then animation will
|
|
128
|
+
// stop receiving events (seems like it's react-native optimization).
|
|
129
|
+
// So we need to keep a reference to the animated value, to keep it's
|
|
130
|
+
// always mounted (keep a reference to an animated value).
|
|
131
|
+
//
|
|
132
|
+
// To test why it's needed, try to open screen which consumes Animated.Value
|
|
133
|
+
// then close it and open it again (for example 'Animated transition').
|
|
134
|
+
styles.hidden, {
|
|
135
|
+
transform: [{
|
|
136
|
+
translateX: height
|
|
137
|
+
}, {
|
|
138
|
+
translateY: progress
|
|
139
|
+
}]
|
|
140
|
+
}]
|
|
141
|
+
}), children));
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
exports.KeyboardProvider = KeyboardProvider;
|
|
145
|
+
//# sourceMappingURL=animated.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["animated.tsx"],"names":["KeyboardControllerViewAnimated","Reanimated","createAnimatedComponent","Animated","KeyboardControllerView","defaultContext","animated","progress","Value","height","reanimated","value","KeyboardContext","React","createContext","useKeyboardAnimation","context","useReanimatedKeyboardAnimation","useAnimatedKeyboardHandler","handlers","dependencies","doDependenciesDiffer","event","onKeyboardMove","eventName","endsWith","styles","StyleSheet","create","container","flex","hidden","display","position","KeyboardProvider","children","progressSV","heightSV","nativeEvent","useNativeDriver","handler","transform","translateX","translateY"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAKA;;;;;;AAQA,MAAMA,8BAA8B,GAAGC,+BAAWC,uBAAX,CACrCC,sBAASD,uBAAT,CACEE,8BADF,CADqC,CAAvC;;AAkBA,MAAMC,cAAwC,GAAG;AAC/CC,EAAAA,QAAQ,EAAE;AACRC,IAAAA,QAAQ,EAAE,IAAIJ,sBAASK,KAAb,CAAmB,CAAnB,CADF;AAERC,IAAAA,MAAM,EAAE,IAAIN,sBAASK,KAAb,CAAmB,CAAnB;AAFA,GADqC;AAK/CE,EAAAA,UAAU,EAAE;AACVH,IAAAA,QAAQ,EAAE;AAAEI,MAAAA,KAAK,EAAE;AAAT,KADA;AAEVF,IAAAA,MAAM,EAAE;AAAEE,MAAAA,KAAK,EAAE;AAAT;AAFE;AALmC,CAAjD;;AAUA,MAAMC,eAAe,gBAAGC,eAAMC,aAAN,CAAoBT,cAApB,CAAxB;;AAEO,MAAMU,oBAAoB,GAAG,MAAuB;AACzD;AACA,QAAMC,OAAO,GAAG,uBAAWJ,eAAX,CAAhB;AAEA,SAAOI,OAAO,CAACV,QAAf;AACD,CALM;;;;AAOA,MAAMW,8BAA8B,GAAG,MAAyB;AACrE;AACA,QAAMD,OAAO,GAAG,uBAAWJ,eAAX,CAAhB;AAEA,SAAOI,OAAO,CAACN,UAAf;AACD,CALM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,EAAE6B,UAAZ;AAAwB3B,MAAAA,MAAM,EAAE4B;AAAhC;AAFP,GAAP,CADc,EAKd,EALc,CAAhB;AAQA,QAAMd,cAAc,GAAG,oBACrB,MACEpB,sBAASmB,KAAT,CACE,CACE;AACEgB,IAAAA,WAAW,EAAE;AACX/B,MAAAA,QADW;AAEXE,MAAAA;AAFW;AADf,GADF,CADF,EASE;AAAE8B,IAAAA,eAAe,EAAE;AAAnB,GATF,CAFmB,EAarB,EAbqB,CAAvB;AAgBA,QAAMC,OAAO,GAAGtB,0BAA0B,CACxC;AACEK,IAAAA,cAAc,EAAGD,KAAD,IAAwB;AACtC;;AACAc,MAAAA,UAAU,CAACzB,KAAX,GAAmBW,KAAK,CAACf,QAAzB;AACA8B,MAAAA,QAAQ,CAAC1B,KAAT,GAAiBW,KAAK,CAACb,MAAvB;AACD;AALH,GADwC,EAQxC,EARwC,CAA1C;AAWA,sBACE,6BAAC,eAAD,CAAiB,QAAjB;AAA0B,IAAA,KAAK,EAAEO;AAAjC,kBACE,6BAAC,8BAAD;AACE,IAAA,wBAAwB,EAAEwB,OAD5B;AAEE,IAAA,cAAc,EAAEjB,cAFlB;AAGE,IAAA,KAAK,EAAEG,MAAM,CAACG;AAHhB,kBAKE,6BAAC,qBAAD,CAAU,IAAV;AACE,IAAA,KAAK,EAAE,CACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACAH,IAAAA,MAAM,CAACK,MATF,EAUL;AAAEU,MAAAA,SAAS,EAAE,CAAC;AAAEC,QAAAA,UAAU,EAAEjC;AAAd,OAAD,EAAyB;AAAEkC,QAAAA,UAAU,EAAEpC;AAAd,OAAzB;AAAb,KAVK;AADT,IALF,EAmBG4B,QAnBH,CADF,CADF;AAyBD,CArEM","sourcesContent":["import React, { useContext, useMemo } from 'react';\nimport { Animated, StyleSheet, ViewStyle } from 'react-native';\nimport Reanimated, {\n useEvent,\n useHandler,\n useSharedValue,\n} from 'react-native-reanimated';\nimport {\n EventWithName,\n KeyboardControllerProps,\n KeyboardControllerView,\n NativeEvent,\n useResizeMode,\n} from './native';\n\nconst KeyboardControllerViewAnimated = Reanimated.createAnimatedComponent(\n Animated.createAnimatedComponent(\n KeyboardControllerView\n ) as React.FC<KeyboardControllerProps>\n);\n\ntype AnimatedContext = {\n progress: Animated.Value;\n height: Animated.Value;\n};\ntype ReanimatedContext = {\n progress: Reanimated.SharedValue<number>;\n height: Reanimated.SharedValue<number>;\n};\ntype KeyboardAnimationContext = {\n animated: AnimatedContext;\n reanimated: ReanimatedContext;\n};\nconst defaultContext: KeyboardAnimationContext = {\n animated: {\n progress: new Animated.Value(0),\n height: new Animated.Value(0),\n },\n reanimated: {\n progress: { value: 0 },\n height: { value: 0 },\n },\n};\nconst KeyboardContext = React.createContext(defaultContext);\n\nexport const useKeyboardAnimation = (): AnimatedContext => {\n useResizeMode();\n const context = useContext(KeyboardContext);\n\n return context.animated;\n};\n\nexport const useReanimatedKeyboardAnimation = (): ReanimatedContext => {\n useResizeMode();\n const context = useContext(KeyboardContext);\n\n return context.reanimated;\n};\n\nfunction useAnimatedKeyboardHandler<TContext extends Record<string, unknown>>(\n handlers: {\n onKeyboardMove?: (e: NativeEvent, context: TContext) => void;\n },\n dependencies?: ReadonlyArray<unknown>\n) {\n const { context, doDependenciesDiffer } = useHandler(handlers, dependencies);\n\n return useEvent(\n (event: EventWithName<NativeEvent>) => {\n 'worklet';\n const { onKeyboardMove } = handlers;\n\n if (onKeyboardMove && event.eventName.endsWith('onKeyboardMove')) {\n onKeyboardMove(event, context);\n }\n },\n ['onKeyboardMove'],\n doDependenciesDiffer\n );\n}\n\ntype Styles = {\n container: ViewStyle;\n hidden: ViewStyle;\n};\n\nexport const styles = StyleSheet.create<Styles>({\n container: {\n flex: 1,\n },\n hidden: {\n display: 'none',\n position: 'absolute',\n },\n});\n\nexport const KeyboardProvider = ({\n children,\n}: {\n children: React.ReactNode;\n}) => {\n const progress = useMemo(() => new Animated.Value(0), []);\n const height = useMemo(() => new Animated.Value(0), []);\n const progressSV = useSharedValue(0);\n const heightSV = useSharedValue(0);\n const context = useMemo(\n () => ({\n animated: { progress: progress, height: height },\n reanimated: { progress: progressSV, height: heightSV },\n }),\n []\n );\n\n const onKeyboardMove = useMemo(\n () =>\n Animated.event(\n [\n {\n nativeEvent: {\n progress,\n height,\n },\n },\n ],\n { useNativeDriver: true }\n ),\n []\n );\n\n const handler = useAnimatedKeyboardHandler(\n {\n onKeyboardMove: (event: NativeEvent) => {\n 'worklet';\n progressSV.value = event.progress;\n heightSV.value = event.height;\n },\n },\n []\n );\n\n return (\n <KeyboardContext.Provider value={context}>\n <KeyboardControllerViewAnimated\n onKeyboardMoveReanimated={handler}\n onKeyboardMove={onKeyboardMove}\n style={styles.container}\n >\n <Animated.View\n style={[\n // we are using this small hack, because if the component (where\n // animated value has been used) is unmounted, then animation will\n // stop receiving events (seems like it's react-native optimization).\n // So we need to keep a reference to the animated value, to keep it's\n // always mounted (keep a reference to an animated value).\n //\n // To test why it's needed, try to open screen which consumes Animated.Value\n // then close it and open it again (for example 'Animated transition').\n styles.hidden,\n { transform: [{ translateX: height }, { translateY: progress }] },\n ]}\n />\n {children}\n </KeyboardControllerViewAnimated>\n </KeyboardContext.Provider>\n );\n};\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _native = require("./native");
|
|
8
|
+
|
|
9
|
+
Object.keys(_native).forEach(function (key) {
|
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
|
11
|
+
if (key in exports && exports[key] === _native[key]) return;
|
|
12
|
+
Object.defineProperty(exports, key, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _native[key];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
var _animated = require("./animated");
|
|
21
|
+
|
|
22
|
+
Object.keys(_animated).forEach(function (key) {
|
|
23
|
+
if (key === "default" || key === "__esModule") return;
|
|
24
|
+
if (key in exports && exports[key] === _animated[key]) return;
|
|
25
|
+
Object.defineProperty(exports, key, {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return _animated[key];
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
var _replicas = require("./replicas");
|
|
34
|
+
|
|
35
|
+
Object.keys(_replicas).forEach(function (key) {
|
|
36
|
+
if (key === "default" || key === "__esModule") return;
|
|
37
|
+
if (key in exports && exports[key] === _replicas[key]) return;
|
|
38
|
+
Object.defineProperty(exports, key, {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
get: function () {
|
|
41
|
+
return _replicas[key];
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './native';\nexport * from './animated';\nexport * from './replicas';\n"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useResizeMode = exports.KeyboardEvents = exports.KeyboardControllerView = exports.KeyboardController = exports.AndroidSoftInputModes = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
|
|
10
|
+
var _reactNative = require("react-native");
|
|
11
|
+
|
|
12
|
+
const LINKING_ERROR = `The package 'react-native-keyboard-controller' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({
|
|
13
|
+
ios: "- You have run 'pod install'\n",
|
|
14
|
+
default: ''
|
|
15
|
+
}) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo managed workflow\n';
|
|
16
|
+
let AndroidSoftInputModes;
|
|
17
|
+
exports.AndroidSoftInputModes = AndroidSoftInputModes;
|
|
18
|
+
|
|
19
|
+
(function (AndroidSoftInputModes) {
|
|
20
|
+
AndroidSoftInputModes[AndroidSoftInputModes["SOFT_INPUT_ADJUST_NOTHING"] = 48] = "SOFT_INPUT_ADJUST_NOTHING";
|
|
21
|
+
AndroidSoftInputModes[AndroidSoftInputModes["SOFT_INPUT_ADJUST_PAN"] = 32] = "SOFT_INPUT_ADJUST_PAN";
|
|
22
|
+
AndroidSoftInputModes[AndroidSoftInputModes["SOFT_INPUT_ADJUST_RESIZE"] = 16] = "SOFT_INPUT_ADJUST_RESIZE";
|
|
23
|
+
AndroidSoftInputModes[AndroidSoftInputModes["SOFT_INPUT_ADJUST_UNSPECIFIED"] = 0] = "SOFT_INPUT_ADJUST_UNSPECIFIED";
|
|
24
|
+
})(AndroidSoftInputModes || (exports.AndroidSoftInputModes = AndroidSoftInputModes = {}));
|
|
25
|
+
|
|
26
|
+
const ComponentName = 'KeyboardControllerView';
|
|
27
|
+
const RCTKeyboardController = _reactNative.NativeModules.KeyboardController;
|
|
28
|
+
const KeyboardController = RCTKeyboardController;
|
|
29
|
+
exports.KeyboardController = KeyboardController;
|
|
30
|
+
const eventEmitter = new _reactNative.NativeEventEmitter(RCTKeyboardController);
|
|
31
|
+
const KeyboardEvents = {
|
|
32
|
+
addListener: (name, cb) => eventEmitter.addListener('KeyboardController::' + name, cb)
|
|
33
|
+
};
|
|
34
|
+
exports.KeyboardEvents = KeyboardEvents;
|
|
35
|
+
const KeyboardControllerView = _reactNative.UIManager.getViewManagerConfig(ComponentName) != null ? (0, _reactNative.requireNativeComponent)(ComponentName) : () => {
|
|
36
|
+
throw new Error(LINKING_ERROR);
|
|
37
|
+
};
|
|
38
|
+
exports.KeyboardControllerView = KeyboardControllerView;
|
|
39
|
+
|
|
40
|
+
const useResizeMode = () => {
|
|
41
|
+
(0, _react.useEffect)(() => {
|
|
42
|
+
KeyboardController.setInputMode(AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE);
|
|
43
|
+
return () => KeyboardController.setDefaultMode();
|
|
44
|
+
}, []);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
exports.useResizeMode = useResizeMode;
|
|
48
|
+
//# sourceMappingURL=native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["native.ts"],"names":["LINKING_ERROR","Platform","select","ios","default","AndroidSoftInputModes","ComponentName","RCTKeyboardController","NativeModules","KeyboardController","eventEmitter","NativeEventEmitter","KeyboardEvents","addListener","name","cb","KeyboardControllerView","UIManager","getViewManagerConfig","Error","useResizeMode","setInputMode","SOFT_INPUT_ADJUST_RESIZE","setDefaultMode"],"mappings":";;;;;;;AAAA;;AACA;;AAUA,MAAMA,aAAa,GAChB,2FAAD,GACAC,sBAASC,MAAT,CAAgB;AAAEC,EAAAA,GAAG,EAAE,gCAAP;AAAyCC,EAAAA,OAAO,EAAE;AAAlD,CAAhB,CADA,GAEA,sDAFA,GAGA,6CAJF;IAMYC,qB;;;WAAAA,qB;AAAAA,EAAAA,qB,CAAAA,qB;AAAAA,EAAAA,qB,CAAAA,qB;AAAAA,EAAAA,qB,CAAAA,qB;AAAAA,EAAAA,qB,CAAAA,qB;GAAAA,qB,qCAAAA,qB;;AA6BZ,MAAMC,aAAa,GAAG,wBAAtB;AAEA,MAAMC,qBAAqB,GAAGC,2BAAcC,kBAA5C;AACO,MAAMA,kBAAkB,GAAGF,qBAA3B;;AAEP,MAAMG,YAAY,GAAG,IAAIC,+BAAJ,CAAuBJ,qBAAvB,CAArB;AASO,MAAMK,cAAc,GAAG;AAC5BC,EAAAA,WAAW,EAAE,CACXC,IADW,EAEXC,EAFW,KAGRL,YAAY,CAACG,WAAb,CAAyB,yBAAyBC,IAAlD,EAAwDC,EAAxD;AAJuB,CAAvB;;AAMA,MAAMC,sBAAsB,GACjCC,uBAAUC,oBAAV,CAA+BZ,aAA/B,KAAiD,IAAjD,GACI,yCAAgDA,aAAhD,CADJ,GAEI,MAAM;AACJ,QAAM,IAAIa,KAAJ,CAAUnB,aAAV,CAAN;AACD,CALA;;;AAOA,MAAMoB,aAAa,GAAG,MAAM;AACjC,wBAAU,MAAM;AACdX,IAAAA,kBAAkB,CAACY,YAAnB,CACEhB,qBAAqB,CAACiB,wBADxB;AAIA,WAAO,MAAMb,kBAAkB,CAACc,cAAnB,EAAb;AACD,GAND,EAMG,EANH;AAOD,CARM","sourcesContent":["import React, { useEffect } from 'react';\nimport {\n requireNativeComponent,\n UIManager,\n Platform,\n ViewStyle,\n NativeModules,\n NativeEventEmitter,\n NativeSyntheticEvent,\n} from 'react-native';\n\nconst LINKING_ERROR =\n `The package 'react-native-keyboard-controller' doesn't seem to be linked. Make sure: \\n\\n` +\n Platform.select({ ios: \"- You have run 'pod install'\\n\", default: '' }) +\n '- You rebuilt the app after installing the package\\n' +\n '- You are not using Expo managed workflow\\n';\n\nexport enum AndroidSoftInputModes {\n SOFT_INPUT_ADJUST_NOTHING = 48,\n SOFT_INPUT_ADJUST_PAN = 32,\n SOFT_INPUT_ADJUST_RESIZE = 16,\n SOFT_INPUT_ADJUST_UNSPECIFIED = 0,\n}\n\nexport type NativeEvent = {\n progress: number;\n height: number;\n};\nexport type EventWithName<T> = {\n eventName: string;\n} & T;\nexport type KeyboardControllerProps = {\n style?: ViewStyle;\n children: React.ReactNode;\n onKeyboardMove: (e: NativeSyntheticEvent<EventWithName<NativeEvent>>) => void;\n // fake prop used to activate reanimated bindings\n onKeyboardMoveReanimated: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n};\ntype KeyboardController = {\n // android only\n setDefaultMode: () => void;\n setInputMode: (mode: AndroidSoftInputModes) => void;\n};\n\nconst ComponentName = 'KeyboardControllerView';\n\nconst RCTKeyboardController = NativeModules.KeyboardController;\nexport const KeyboardController = RCTKeyboardController as KeyboardController;\n\nconst eventEmitter = new NativeEventEmitter(RCTKeyboardController);\ntype KeyboardControllerEvents =\n | 'keyboardWillShow'\n | 'keyboardDidShow'\n | 'keyboardWillHide'\n | 'keyboardDidHide';\ntype KeyboardEvent = {\n height: number;\n};\nexport const KeyboardEvents = {\n addListener: (\n name: KeyboardControllerEvents,\n cb: (e: KeyboardEvent) => void\n ) => eventEmitter.addListener('KeyboardController::' + name, cb),\n};\nexport const KeyboardControllerView =\n UIManager.getViewManagerConfig(ComponentName) != null\n ? requireNativeComponent<KeyboardControllerProps>(ComponentName)\n : () => {\n throw new Error(LINKING_ERROR);\n };\n\nexport const useResizeMode = () => {\n useEffect(() => {\n KeyboardController.setInputMode(\n AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE\n );\n\n return () => KeyboardController.setDefaultMode();\n }, []);\n};\n"]}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useReanimatedKeyboardAnimationReplica = exports.useKeyboardAnimationReplica = exports.useGradualKeyboardAnimation = exports.defaultAndroidEasing = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
|
|
10
|
+
var _reactNative = require("react-native");
|
|
11
|
+
|
|
12
|
+
var _reactNativeReanimated = require("react-native-reanimated");
|
|
13
|
+
|
|
14
|
+
var _animated = require("./animated");
|
|
15
|
+
|
|
16
|
+
var _native = require("./native");
|
|
17
|
+
|
|
18
|
+
const availableOSEventType = _reactNative.Platform.OS === 'ios' ? 'Will' : 'Did'; // cubic-bezier(.17,.67,.34,.94)
|
|
19
|
+
|
|
20
|
+
const defaultAndroidEasing = _reactNative.Easing.bezier(0.4, 0.0, 0.2, 1);
|
|
21
|
+
|
|
22
|
+
exports.defaultAndroidEasing = defaultAndroidEasing;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* An experimental implementation of tracing keyboard appearance.
|
|
26
|
+
* Switch an input mode to adjust resize mode. In this case all did* events
|
|
27
|
+
* are triggering before keyboard appears, and using some approximations
|
|
28
|
+
* it tries to mimicries a native transition.
|
|
29
|
+
*
|
|
30
|
+
* @returns {Animated.Value}
|
|
31
|
+
*/
|
|
32
|
+
const useKeyboardAnimationReplica = () => {
|
|
33
|
+
const height = (0, _react.useRef)(new _reactNative.Animated.Value(0));
|
|
34
|
+
const progress = (0, _react.useRef)(new _reactNative.Animated.Value(0));
|
|
35
|
+
const animation = (0, _react.useMemo)(() => ({
|
|
36
|
+
height: height.current,
|
|
37
|
+
progress: progress.current
|
|
38
|
+
}), []);
|
|
39
|
+
(0, _react.useEffect)(() => {
|
|
40
|
+
_native.KeyboardController.setInputMode(_native.AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE);
|
|
41
|
+
|
|
42
|
+
return () => _native.KeyboardController.setDefaultMode();
|
|
43
|
+
}, []);
|
|
44
|
+
(0, _react.useEffect)(() => {
|
|
45
|
+
const listener = _reactNative.Keyboard.addListener(`keyboard${availableOSEventType}Show`, e => {
|
|
46
|
+
_reactNative.Animated.timing(height.current, {
|
|
47
|
+
toValue: -e.endCoordinates.height,
|
|
48
|
+
duration: e.duration !== 0 ? e.duration : 300,
|
|
49
|
+
easing: _reactNative.Easing.bezier(0.4, 0.0, 0.2, 1),
|
|
50
|
+
useNativeDriver: true
|
|
51
|
+
}).start();
|
|
52
|
+
|
|
53
|
+
return () => listener.remove();
|
|
54
|
+
});
|
|
55
|
+
}, []);
|
|
56
|
+
(0, _react.useEffect)(() => {
|
|
57
|
+
const listener = _reactNative.Keyboard.addListener(`keyboard${availableOSEventType}Hide`, e => {
|
|
58
|
+
_reactNative.Animated.timing(height.current, {
|
|
59
|
+
toValue: 0,
|
|
60
|
+
duration: e.duration !== 0 ? e.duration : 300,
|
|
61
|
+
easing: _reactNative.Easing.bezier(0.4, 0.0, 0.2, 1),
|
|
62
|
+
useNativeDriver: true
|
|
63
|
+
}).start();
|
|
64
|
+
|
|
65
|
+
return () => listener.remove();
|
|
66
|
+
});
|
|
67
|
+
}, []);
|
|
68
|
+
return animation;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
exports.useKeyboardAnimationReplica = useKeyboardAnimationReplica;
|
|
72
|
+
const IOS_SPRING_CONFIG = {
|
|
73
|
+
damping: 500,
|
|
74
|
+
stiffness: 1000,
|
|
75
|
+
mass: 3,
|
|
76
|
+
overshootClamping: true,
|
|
77
|
+
restDisplacementThreshold: 10,
|
|
78
|
+
restSpeedThreshold: 10
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* A close replica to native iOS keyboard animation. The problem is that
|
|
82
|
+
* iOS (unlike Android) can not fire events for each keyboard frame movement.
|
|
83
|
+
* As a result we can not get gradual values (for example, for progress it always
|
|
84
|
+
* will be 1 or 0). So if you want to rely on gradual values you will need to use
|
|
85
|
+
* this replica.
|
|
86
|
+
*
|
|
87
|
+
* The transition is hardcoded and may vary from one to another OS versions. But it
|
|
88
|
+
* seems like last time it has been changed in iOS 7. Since RN supports at least iOS
|
|
89
|
+
* 11 it doesn't make sense to replicate iOS 7 behavior. If it changes in next OS
|
|
90
|
+
* versions, then this implementation should be revisited and reflect necessary changes.
|
|
91
|
+
*
|
|
92
|
+
* @returns {height, progress} - animated values
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
const useReanimatedKeyboardAnimationReplica = () => {
|
|
96
|
+
const height = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
97
|
+
const heightEvent = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
98
|
+
const progress = (0, _reactNativeReanimated.useDerivedValue)(() => height.value / heightEvent.value);
|
|
99
|
+
const handler = (0, _reactNativeReanimated.useWorkletCallback)(_height => {
|
|
100
|
+
heightEvent.value = _height;
|
|
101
|
+
}, []);
|
|
102
|
+
(0, _reactNativeReanimated.useAnimatedReaction)(() => ({
|
|
103
|
+
_keyboardHeight: heightEvent.value
|
|
104
|
+
}), (result, _previousResult) => {
|
|
105
|
+
const {
|
|
106
|
+
_keyboardHeight
|
|
107
|
+
} = result;
|
|
108
|
+
|
|
109
|
+
const _previousKeyboardHeight = _previousResult === null || _previousResult === void 0 ? void 0 : _previousResult._keyboardHeight;
|
|
110
|
+
|
|
111
|
+
if (_keyboardHeight !== _previousKeyboardHeight) {
|
|
112
|
+
height.value = (0, _reactNativeReanimated.withSpring)(_keyboardHeight, IOS_SPRING_CONFIG);
|
|
113
|
+
}
|
|
114
|
+
}, []);
|
|
115
|
+
(0, _react.useEffect)(() => {
|
|
116
|
+
const show = _reactNative.Keyboard.addListener('keyboardWillShow', e => {
|
|
117
|
+
(0, _reactNativeReanimated.runOnUI)(handler)(-e.endCoordinates.height);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const hide = _reactNative.Keyboard.addListener('keyboardWillHide', () => {
|
|
121
|
+
(0, _reactNativeReanimated.runOnUI)(handler)(0);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
return () => {
|
|
125
|
+
show.remove();
|
|
126
|
+
hide.remove();
|
|
127
|
+
};
|
|
128
|
+
}, []);
|
|
129
|
+
return {
|
|
130
|
+
height,
|
|
131
|
+
progress
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
exports.useReanimatedKeyboardAnimationReplica = useReanimatedKeyboardAnimationReplica;
|
|
136
|
+
const useGradualKeyboardAnimation = _reactNative.Platform.OS === 'ios' ? useReanimatedKeyboardAnimationReplica : _animated.useReanimatedKeyboardAnimation;
|
|
137
|
+
exports.useGradualKeyboardAnimation = useGradualKeyboardAnimation;
|
|
138
|
+
//# sourceMappingURL=replicas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["replicas.ts"],"names":["availableOSEventType","Platform","OS","defaultAndroidEasing","Easing","bezier","useKeyboardAnimationReplica","height","Animated","Value","progress","animation","current","KeyboardController","setInputMode","AndroidSoftInputModes","SOFT_INPUT_ADJUST_RESIZE","setDefaultMode","listener","Keyboard","addListener","e","timing","toValue","endCoordinates","duration","easing","useNativeDriver","start","remove","IOS_SPRING_CONFIG","damping","stiffness","mass","overshootClamping","restDisplacementThreshold","restSpeedThreshold","useReanimatedKeyboardAnimationReplica","heightEvent","value","handler","_height","_keyboardHeight","result","_previousResult","_previousKeyboardHeight","show","hide","useGradualKeyboardAnimation","useReanimatedKeyboardAnimation"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAQA;;AAEA;;AAEA,MAAMA,oBAAoB,GAAGC,sBAASC,EAAT,KAAgB,KAAhB,GAAwB,MAAxB,GAAiC,KAA9D,C,CAEA;;AACO,MAAMC,oBAAoB,GAAGC,oBAAOC,MAAP,CAAc,GAAd,EAAmB,GAAnB,EAAwB,GAAxB,EAA6B,CAA7B,CAA7B;;;;AAMP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,2BAA2B,GAAG,MAAyB;AAClE,QAAMC,MAAM,GAAG,mBAAO,IAAIC,sBAASC,KAAb,CAAmB,CAAnB,CAAP,CAAf;AACA,QAAMC,QAAQ,GAAG,mBAAO,IAAIF,sBAASC,KAAb,CAAmB,CAAnB,CAAP,CAAjB;AACA,QAAME,SAAS,GAAG,oBAChB,OAAO;AACLJ,IAAAA,MAAM,EAAEA,MAAM,CAACK,OADV;AAELF,IAAAA,QAAQ,EAAEA,QAAQ,CAACE;AAFd,GAAP,CADgB,EAKhB,EALgB,CAAlB;AAQA,wBAAU,MAAM;AACdC,+BAAmBC,YAAnB,CACEC,8BAAsBC,wBADxB;;AAIA,WAAO,MAAMH,2BAAmBI,cAAnB,EAAb;AACD,GAND,EAMG,EANH;AAOA,wBAAU,MAAM;AACd,UAAMC,QAAQ,GAAGC,sBAAS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Ab;;AAIA,WAAO,MAAM;AACXM,MAAAA,IAAI,CAACjB,MAAL;AACAkB,MAAAA,IAAI,CAAClB,MAAL;AACD,KAHD;AAID,GAZD,EAYG,EAZH;AAcA,SAAO;AAAEtB,IAAAA,MAAF;AAAUG,IAAAA;AAAV,GAAP;AACD,CAxCM;;;AA0CA,MAAMsC,2BAA2B,GACtC/C,sBAASC,EAAT,KAAgB,KAAhB,GACImC,qCADJ,GAEIY,wCAHC","sourcesContent":["import { useRef, useEffect, useMemo } from 'react';\nimport { Animated, Easing, Keyboard, Platform } from 'react-native';\nimport {\n runOnUI,\n useAnimatedReaction,\n useDerivedValue,\n useSharedValue,\n useWorkletCallback,\n withSpring,\n} from 'react-native-reanimated';\nimport { useReanimatedKeyboardAnimation } from './animated';\n\nimport { AndroidSoftInputModes, KeyboardController } from './native';\n\nconst availableOSEventType = Platform.OS === 'ios' ? 'Will' : 'Did';\n\n// cubic-bezier(.17,.67,.34,.94)\nexport const defaultAndroidEasing = Easing.bezier(0.4, 0.0, 0.2, 1);\ntype KeyboardAnimation = {\n progress: Animated.Value;\n height: Animated.Value;\n};\n\n/**\n * An experimental implementation of tracing keyboard appearance.\n * Switch an input mode to adjust resize mode. In this case all did* events\n * are triggering before keyboard appears, and using some approximations\n * it tries to mimicries a native transition.\n *\n * @returns {Animated.Value}\n */\nexport const useKeyboardAnimationReplica = (): KeyboardAnimation => {\n const height = useRef(new Animated.Value(0));\n const progress = useRef(new Animated.Value(0));\n const animation = useMemo(\n () => ({\n height: height.current,\n progress: progress.current,\n }),\n []\n );\n\n useEffect(() => {\n KeyboardController.setInputMode(\n AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE\n );\n\n return () => KeyboardController.setDefaultMode();\n }, []);\n useEffect(() => {\n const listener = Keyboard.addListener(\n `keyboard${availableOSEventType}Show`,\n (e) => {\n Animated.timing(height.current, {\n toValue: -e.endCoordinates.height,\n duration: e.duration !== 0 ? e.duration : 300,\n easing: Easing.bezier(0.4, 0.0, 0.2, 1),\n useNativeDriver: true,\n }).start();\n\n return () => listener.remove();\n }\n );\n }, []);\n useEffect(() => {\n const listener = Keyboard.addListener(\n `keyboard${availableOSEventType}Hide`,\n (e) => {\n Animated.timing(height.current, {\n toValue: 0,\n duration: e.duration !== 0 ? e.duration : 300,\n easing: Easing.bezier(0.4, 0.0, 0.2, 1),\n useNativeDriver: true,\n }).start();\n\n return () => listener.remove();\n }\n );\n }, []);\n\n return animation;\n};\n\nconst IOS_SPRING_CONFIG = {\n damping: 500,\n stiffness: 1000,\n mass: 3,\n overshootClamping: true,\n restDisplacementThreshold: 10,\n restSpeedThreshold: 10,\n};\n\n/**\n * A close replica to native iOS keyboard animation. The problem is that\n * iOS (unlike Android) can not fire events for each keyboard frame movement.\n * As a result we can not get gradual values (for example, for progress it always\n * will be 1 or 0). So if you want to rely on gradual values you will need to use\n * this replica.\n *\n * The transition is hardcoded and may vary from one to another OS versions. But it\n * seems like last time it has been changed in iOS 7. Since RN supports at least iOS\n * 11 it doesn't make sense to replicate iOS 7 behavior. If it changes in next OS\n * versions, then this implementation should be revisited and reflect necessary changes.\n *\n * @returns {height, progress} - animated values\n */\nexport const useReanimatedKeyboardAnimationReplica = () => {\n const height = useSharedValue(0);\n const heightEvent = useSharedValue(0);\n\n const progress = useDerivedValue(() => height.value / heightEvent.value);\n\n const handler = useWorkletCallback((_height: number) => {\n heightEvent.value = _height;\n }, []);\n\n useAnimatedReaction(\n () => ({\n _keyboardHeight: heightEvent.value,\n }),\n (result, _previousResult) => {\n const { _keyboardHeight } = result;\n const _previousKeyboardHeight = _previousResult?._keyboardHeight;\n\n if (_keyboardHeight !== _previousKeyboardHeight) {\n height.value = withSpring(_keyboardHeight, IOS_SPRING_CONFIG);\n }\n },\n []\n );\n\n useEffect(() => {\n const show = Keyboard.addListener('keyboardWillShow', (e) => {\n runOnUI(handler)(-e.endCoordinates.height);\n });\n const hide = Keyboard.addListener('keyboardWillHide', () => {\n runOnUI(handler)(0);\n });\n\n return () => {\n show.remove();\n hide.remove();\n };\n }, []);\n\n return { height, progress };\n};\n\nexport const useGradualKeyboardAnimation =\n Platform.OS === 'ios'\n ? useReanimatedKeyboardAnimationReplica\n : useReanimatedKeyboardAnimation;\n"]}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import React, { useContext, useMemo } from 'react';
|
|
2
|
+
import { Animated, StyleSheet } from 'react-native';
|
|
3
|
+
import Reanimated, { useEvent, useHandler, useSharedValue } from 'react-native-reanimated';
|
|
4
|
+
import { KeyboardControllerView, useResizeMode } from './native';
|
|
5
|
+
const KeyboardControllerViewAnimated = Reanimated.createAnimatedComponent(Animated.createAnimatedComponent(KeyboardControllerView));
|
|
6
|
+
const defaultContext = {
|
|
7
|
+
animated: {
|
|
8
|
+
progress: new Animated.Value(0),
|
|
9
|
+
height: new Animated.Value(0)
|
|
10
|
+
},
|
|
11
|
+
reanimated: {
|
|
12
|
+
progress: {
|
|
13
|
+
value: 0
|
|
14
|
+
},
|
|
15
|
+
height: {
|
|
16
|
+
value: 0
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const KeyboardContext = /*#__PURE__*/React.createContext(defaultContext);
|
|
21
|
+
export const useKeyboardAnimation = () => {
|
|
22
|
+
useResizeMode();
|
|
23
|
+
const context = useContext(KeyboardContext);
|
|
24
|
+
return context.animated;
|
|
25
|
+
};
|
|
26
|
+
export const useReanimatedKeyboardAnimation = () => {
|
|
27
|
+
useResizeMode();
|
|
28
|
+
const context = useContext(KeyboardContext);
|
|
29
|
+
return context.reanimated;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
function useAnimatedKeyboardHandler(handlers, dependencies) {
|
|
33
|
+
const {
|
|
34
|
+
context,
|
|
35
|
+
doDependenciesDiffer
|
|
36
|
+
} = useHandler(handlers, dependencies);
|
|
37
|
+
return useEvent(event => {
|
|
38
|
+
'worklet';
|
|
39
|
+
|
|
40
|
+
const {
|
|
41
|
+
onKeyboardMove
|
|
42
|
+
} = handlers;
|
|
43
|
+
|
|
44
|
+
if (onKeyboardMove && event.eventName.endsWith('onKeyboardMove')) {
|
|
45
|
+
onKeyboardMove(event, context);
|
|
46
|
+
}
|
|
47
|
+
}, ['onKeyboardMove'], doDependenciesDiffer);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const styles = StyleSheet.create({
|
|
51
|
+
container: {
|
|
52
|
+
flex: 1
|
|
53
|
+
},
|
|
54
|
+
hidden: {
|
|
55
|
+
display: 'none',
|
|
56
|
+
position: 'absolute'
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
export const KeyboardProvider = _ref => {
|
|
60
|
+
let {
|
|
61
|
+
children
|
|
62
|
+
} = _ref;
|
|
63
|
+
const progress = useMemo(() => new Animated.Value(0), []);
|
|
64
|
+
const height = useMemo(() => new Animated.Value(0), []);
|
|
65
|
+
const progressSV = useSharedValue(0);
|
|
66
|
+
const heightSV = useSharedValue(0);
|
|
67
|
+
const context = useMemo(() => ({
|
|
68
|
+
animated: {
|
|
69
|
+
progress: progress,
|
|
70
|
+
height: height
|
|
71
|
+
},
|
|
72
|
+
reanimated: {
|
|
73
|
+
progress: progressSV,
|
|
74
|
+
height: heightSV
|
|
75
|
+
}
|
|
76
|
+
}), []);
|
|
77
|
+
const onKeyboardMove = useMemo(() => Animated.event([{
|
|
78
|
+
nativeEvent: {
|
|
79
|
+
progress,
|
|
80
|
+
height
|
|
81
|
+
}
|
|
82
|
+
}], {
|
|
83
|
+
useNativeDriver: true
|
|
84
|
+
}), []);
|
|
85
|
+
const handler = useAnimatedKeyboardHandler({
|
|
86
|
+
onKeyboardMove: event => {
|
|
87
|
+
'worklet';
|
|
88
|
+
|
|
89
|
+
progressSV.value = event.progress;
|
|
90
|
+
heightSV.value = event.height;
|
|
91
|
+
}
|
|
92
|
+
}, []);
|
|
93
|
+
return /*#__PURE__*/React.createElement(KeyboardContext.Provider, {
|
|
94
|
+
value: context
|
|
95
|
+
}, /*#__PURE__*/React.createElement(KeyboardControllerViewAnimated, {
|
|
96
|
+
onKeyboardMoveReanimated: handler,
|
|
97
|
+
onKeyboardMove: onKeyboardMove,
|
|
98
|
+
style: styles.container
|
|
99
|
+
}, /*#__PURE__*/React.createElement(Animated.View, {
|
|
100
|
+
style: [// we are using this small hack, because if the component (where
|
|
101
|
+
// animated value has been used) is unmounted, then animation will
|
|
102
|
+
// stop receiving events (seems like it's react-native optimization).
|
|
103
|
+
// So we need to keep a reference to the animated value, to keep it's
|
|
104
|
+
// always mounted (keep a reference to an animated value).
|
|
105
|
+
//
|
|
106
|
+
// To test why it's needed, try to open screen which consumes Animated.Value
|
|
107
|
+
// then close it and open it again (for example 'Animated transition').
|
|
108
|
+
styles.hidden, {
|
|
109
|
+
transform: [{
|
|
110
|
+
translateX: height
|
|
111
|
+
}, {
|
|
112
|
+
translateY: progress
|
|
113
|
+
}]
|
|
114
|
+
}]
|
|
115
|
+
}), children));
|
|
116
|
+
};
|
|
117
|
+
//# sourceMappingURL=animated.js.map
|