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