react-native-reanimated
Version:
More powerful alternative to Animated library for React Native.
57 lines (46 loc) • 1.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useAnimatedKeyboard = useAnimatedKeyboard;
var _react = require("react");
var _core = require("../core");
var _commonTypes = require("../commonTypes");
function useAnimatedKeyboard() {
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
isStatusBarTranslucentAndroid: false
};
const ref = (0, _react.useRef)(null);
const listenerId = (0, _react.useRef)(-1);
const isSubscribed = (0, _react.useRef)(false);
if (ref.current === null) {
const keyboardEventData = {
state: (0, _core.makeMutable)(_commonTypes.KeyboardState.UNKNOWN),
height: (0, _core.makeMutable)(0)
};
listenerId.current = (0, _core.subscribeForKeyboardEvents)((state, height) => {
'worklet';
keyboardEventData.state.value = state;
keyboardEventData.height.value = height;
}, options);
ref.current = keyboardEventData;
isSubscribed.current = true;
}
(0, _react.useEffect)(() => {
if (isSubscribed.current === false && ref.current !== null) {
const keyboardEventData = ref.current; // subscribe again after Fast Refresh
listenerId.current = (0, _core.subscribeForKeyboardEvents)((state, height) => {
'worklet';
keyboardEventData.state.value = state;
keyboardEventData.height.value = height;
}, options);
isSubscribed.current = true;
}
return () => {
(0, _core.unsubscribeFromKeyboardEvents)(listenerId.current);
isSubscribed.current = false;
};
}, []);
return ref.current;
}
//# sourceMappingURL=useAnimatedKeyboard.js.map