react-native-earl-accessory-view 1.0.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 +453 -0
- package/dist/AccessoryView.d.ts +33 -0
- package/dist/AccessoryView.d.ts.map +1 -0
- package/dist/AccessoryView.js +321 -0
- package/dist/AccessoryView.js.map +1 -0
- package/dist/ActionButton.d.ts +22 -0
- package/dist/ActionButton.d.ts.map +1 -0
- package/dist/ActionButton.js +81 -0
- package/dist/ActionButton.js.map +1 -0
- package/dist/CharacterCounter.d.ts +8 -0
- package/dist/CharacterCounter.d.ts.map +1 -0
- package/dist/CharacterCounter.js +78 -0
- package/dist/CharacterCounter.js.map +1 -0
- package/dist/DismissButton.d.ts +10 -0
- package/dist/DismissButton.d.ts.map +1 -0
- package/dist/DismissButton.js +73 -0
- package/dist/DismissButton.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.d.ts +173 -0
- package/dist/styles.d.ts.map +1 -0
- package/dist/styles.js +184 -0
- package/dist/styles.js.map +1 -0
- package/dist/types.d.ts +229 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/useKeyboardAccessory.d.ts +18 -0
- package/dist/useKeyboardAccessory.d.ts.map +1 -0
- package/dist/useKeyboardAccessory.js +102 -0
- package/dist/useKeyboardAccessory.js.map +1 -0
- package/package.json +51 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { UseKeyboardAccessoryOptions, KeyboardAccessoryState } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Hook that manages keyboard visibility and height.
|
|
4
|
+
*
|
|
5
|
+
* Cross-platform:
|
|
6
|
+
* - iOS: uses `keyboardWillShow` / `keyboardWillHide` for pre-animation sync.
|
|
7
|
+
* - Android: uses `keyboardDidShow` / `keyboardDidHide`.
|
|
8
|
+
* - Web: falls back to `resize` event via React Native's Keyboard API.
|
|
9
|
+
*
|
|
10
|
+
* Initializes with the current global keyboard state so that mounting
|
|
11
|
+
* while the keyboard is already visible works correctly (e.g. when
|
|
12
|
+
* switching between input fields).
|
|
13
|
+
*
|
|
14
|
+
* @param options - Configuration for callbacks.
|
|
15
|
+
* @returns Current keyboard state.
|
|
16
|
+
*/
|
|
17
|
+
export declare const useKeyboardAccessory: (options?: UseKeyboardAccessoryOptions) => KeyboardAccessoryState;
|
|
18
|
+
//# sourceMappingURL=useKeyboardAccessory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useKeyboardAccessory.d.ts","sourceRoot":"","sources":["../src/useKeyboardAccessory.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,2BAA2B,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAyC9E;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,oBAAoB,GAChC,UAAS,2BAAgC,KACvC,sBAyDF,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useKeyboardAccessory = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const react_native_1 = require("react-native");
|
|
6
|
+
// ─── Global keyboard state tracker ─────────────────────────────────
|
|
7
|
+
// Tracks keyboard state at module level so that newly mounted hooks
|
|
8
|
+
// (e.g. when switching between inputs without closing the keyboard)
|
|
9
|
+
// can immediately know whether the keyboard is already visible.
|
|
10
|
+
let _globalKeyboardVisible = false;
|
|
11
|
+
let _globalKeyboardHeight = 0;
|
|
12
|
+
let _globalListenerCount = 0;
|
|
13
|
+
let _globalShowSub = null;
|
|
14
|
+
let _globalHideSub = null;
|
|
15
|
+
function _startGlobalTracking() {
|
|
16
|
+
if (_globalListenerCount === 0) {
|
|
17
|
+
const showEvent = react_native_1.Platform.OS === "ios" ? "keyboardWillShow" : "keyboardDidShow";
|
|
18
|
+
const hideEvent = react_native_1.Platform.OS === "ios" ? "keyboardWillHide" : "keyboardDidHide";
|
|
19
|
+
_globalShowSub = react_native_1.Keyboard.addListener(showEvent, (e) => {
|
|
20
|
+
_globalKeyboardVisible = true;
|
|
21
|
+
_globalKeyboardHeight = e.endCoordinates.height;
|
|
22
|
+
});
|
|
23
|
+
_globalHideSub = react_native_1.Keyboard.addListener(hideEvent, () => {
|
|
24
|
+
_globalKeyboardVisible = false;
|
|
25
|
+
_globalKeyboardHeight = 0;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
_globalListenerCount++;
|
|
29
|
+
}
|
|
30
|
+
function _stopGlobalTracking() {
|
|
31
|
+
_globalListenerCount--;
|
|
32
|
+
if (_globalListenerCount === 0) {
|
|
33
|
+
_globalShowSub === null || _globalShowSub === void 0 ? void 0 : _globalShowSub.remove();
|
|
34
|
+
_globalHideSub === null || _globalHideSub === void 0 ? void 0 : _globalHideSub.remove();
|
|
35
|
+
_globalShowSub = null;
|
|
36
|
+
_globalHideSub = null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Hook that manages keyboard visibility and height.
|
|
41
|
+
*
|
|
42
|
+
* Cross-platform:
|
|
43
|
+
* - iOS: uses `keyboardWillShow` / `keyboardWillHide` for pre-animation sync.
|
|
44
|
+
* - Android: uses `keyboardDidShow` / `keyboardDidHide`.
|
|
45
|
+
* - Web: falls back to `resize` event via React Native's Keyboard API.
|
|
46
|
+
*
|
|
47
|
+
* Initializes with the current global keyboard state so that mounting
|
|
48
|
+
* while the keyboard is already visible works correctly (e.g. when
|
|
49
|
+
* switching between input fields).
|
|
50
|
+
*
|
|
51
|
+
* @param options - Configuration for callbacks.
|
|
52
|
+
* @returns Current keyboard state.
|
|
53
|
+
*/
|
|
54
|
+
const useKeyboardAccessory = (options = {}) => {
|
|
55
|
+
const { onKeyboardShow, onKeyboardHide } = options;
|
|
56
|
+
// Use refs for callbacks so the effect never re-subscribes listeners
|
|
57
|
+
const onShowRef = (0, react_1.useRef)(onKeyboardShow);
|
|
58
|
+
const onHideRef = (0, react_1.useRef)(onKeyboardHide);
|
|
59
|
+
onShowRef.current = onKeyboardShow;
|
|
60
|
+
onHideRef.current = onKeyboardHide;
|
|
61
|
+
const [keyboardVisible, setKeyboardVisible] = (0, react_1.useState)(_globalKeyboardVisible);
|
|
62
|
+
const [keyboardHeight, setKeyboardHeight] = (0, react_1.useState)(_globalKeyboardHeight);
|
|
63
|
+
(0, react_1.useEffect)(() => {
|
|
64
|
+
var _a;
|
|
65
|
+
_startGlobalTracking();
|
|
66
|
+
// Sync if keyboard was already visible when this hook mounted
|
|
67
|
+
if (_globalKeyboardVisible) {
|
|
68
|
+
setKeyboardVisible(true);
|
|
69
|
+
setKeyboardHeight(_globalKeyboardHeight);
|
|
70
|
+
(_a = onShowRef.current) === null || _a === void 0 ? void 0 : _a.call(onShowRef, _globalKeyboardHeight);
|
|
71
|
+
}
|
|
72
|
+
const showEvent = react_native_1.Platform.OS === "ios" ? "keyboardWillShow" : "keyboardDidShow";
|
|
73
|
+
const hideEvent = react_native_1.Platform.OS === "ios" ? "keyboardWillHide" : "keyboardDidHide";
|
|
74
|
+
const handleShow = (event) => {
|
|
75
|
+
var _a;
|
|
76
|
+
const h = event.endCoordinates.height;
|
|
77
|
+
setKeyboardVisible(true);
|
|
78
|
+
setKeyboardHeight(h);
|
|
79
|
+
(_a = onShowRef.current) === null || _a === void 0 ? void 0 : _a.call(onShowRef, h);
|
|
80
|
+
};
|
|
81
|
+
const handleHide = () => {
|
|
82
|
+
var _a;
|
|
83
|
+
setKeyboardVisible(false);
|
|
84
|
+
setKeyboardHeight(0);
|
|
85
|
+
(_a = onHideRef.current) === null || _a === void 0 ? void 0 : _a.call(onHideRef);
|
|
86
|
+
};
|
|
87
|
+
const showSub = react_native_1.Keyboard.addListener(showEvent, handleShow);
|
|
88
|
+
const hideSub = react_native_1.Keyboard.addListener(hideEvent, handleHide);
|
|
89
|
+
return () => {
|
|
90
|
+
showSub.remove();
|
|
91
|
+
hideSub.remove();
|
|
92
|
+
_stopGlobalTracking();
|
|
93
|
+
};
|
|
94
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
95
|
+
}, []);
|
|
96
|
+
return {
|
|
97
|
+
keyboardVisible,
|
|
98
|
+
keyboardHeight,
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
exports.useKeyboardAccessory = useKeyboardAccessory;
|
|
102
|
+
//# sourceMappingURL=useKeyboardAccessory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useKeyboardAccessory.js","sourceRoot":"","sources":["../src/useKeyboardAccessory.ts"],"names":[],"mappings":";;;AAAA,iCAAoD;AACpD,+CAAiE;AAGjE,sEAAsE;AACtE,oEAAoE;AACpE,oEAAoE;AACpE,gEAAgE;AAChE,IAAI,sBAAsB,GAAG,KAAK,CAAC;AACnC,IAAI,qBAAqB,GAAG,CAAC,CAAC;AAC9B,IAAI,oBAAoB,GAAG,CAAC,CAAC;AAC7B,IAAI,cAAc,GAAkC,IAAI,CAAC;AACzD,IAAI,cAAc,GAAkC,IAAI,CAAC;AAEzD,SAAS,oBAAoB;IAC5B,IAAI,oBAAoB,KAAK,CAAC,EAAE,CAAC;QAChC,MAAM,SAAS,GACd,uBAAQ,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,iBAAiB,CAAC;QAChE,MAAM,SAAS,GACd,uBAAQ,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,iBAAiB,CAAC;QAEhE,cAAc,GAAG,uBAAQ,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC,CAAgB,EAAE,EAAE;YACrE,sBAAsB,GAAG,IAAI,CAAC;YAC9B,qBAAqB,GAAG,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC;QACj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ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-native-earl-accessory-view",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A fully customizable React Native keyboard accessory view that appears above the keyboard. Supports text positioning, dismiss button, character counter, animations, and custom content. Works on Android, iOS, and Web.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist/",
|
|
9
|
+
"README.md",
|
|
10
|
+
"LICENSE"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"prepare": "tsc",
|
|
15
|
+
"clean": "rimraf dist"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"react-native",
|
|
19
|
+
"keyboard",
|
|
20
|
+
"accessory",
|
|
21
|
+
"accessory-view",
|
|
22
|
+
"keyboard-accessory",
|
|
23
|
+
"input-accessory",
|
|
24
|
+
"keyboard-toolbar",
|
|
25
|
+
"keyboard-bar",
|
|
26
|
+
"customizable",
|
|
27
|
+
"ios",
|
|
28
|
+
"android",
|
|
29
|
+
"web",
|
|
30
|
+
"cross-platform"
|
|
31
|
+
],
|
|
32
|
+
"author": "ORDOVEZ, E,R",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "https://github.com/ordovez-er/react-native-earl-accessory-view"
|
|
37
|
+
},
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/ordovez-er/react-native-earl-accessory-view/issues"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://github.com/ordovez-er/react-native-earl-accessory-view#readme",
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"react": ">=16.8.0",
|
|
44
|
+
"react-native": ">=0.60.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/react": "^18.2.0",
|
|
48
|
+
"@types/react-native": "^0.72.0",
|
|
49
|
+
"typescript": "^5.3.0"
|
|
50
|
+
}
|
|
51
|
+
}
|