UNPKG

taro-hooks

Version:
25 lines 761 B
import { useEffect, useState } from '@taro-hooks/core'; import { hideKeyboard, onKeyboardHeightChange, offKeyboardHeightChange, getSelectedTextRange } from '@tarojs/taro'; import usePromise from '../usePromise'; function useKeyboard() { var _useState = useState(0), height = _useState[0], setHeight = _useState[1]; useEffect(function () { var handle = function handle(e) { setHeight(e.height); }; onKeyboardHeightChange(handle); return function () { offKeyboardHeightChange(handle); }; }); var handleClose = usePromise(hideKeyboard); var getSelectedRange = usePromise(getSelectedTextRange); return { height: height, close: handleClose, getRange: getSelectedRange }; } export default useKeyboard;