replyke-rn
Version:
Replyke React Native components: Build interactive apps with social features like comments, votes, feeds, user lists, notifications, and more.
24 lines • 1.18 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = useTextInputCursorIndicator;
var react_1 = require("react");
function useTextInputCursorIndicator() {
var _a = (0, react_1.useState)(0), cursorPosition = _a[0], setCursorPosition = _a[1];
var _b = (0, react_1.useState)(false), isSelectionActive = _b[0], setIsSelectionActive = _b[1];
var handleSelectionChange = (0, react_1.useCallback)(function (event) {
var selection = event.nativeEvent.selection;
setCursorPosition(selection.start); // Keeps cursor position in sync
setIsSelectionActive(selection.start !== selection.end);
}, []);
var handleTextChange = (0, react_1.useCallback)(function (text) {
setIsSelectionActive(false); // Reset selection state if typing
// No need to modify cursorPosition, as onSelectionChange will update it automatically
}, []);
return {
cursorPosition: cursorPosition,
isSelectionActive: isSelectionActive,
handleSelectionChange: handleSelectionChange,
handleTextChange: handleTextChange,
};
}
//# sourceMappingURL=useTextInputCursorIndicator.js.map
;