UNPKG

@100mslive/react-native-room-kit

Version:

100ms Room Kit provides simple & easy to use UI components to build Live Streaming & Video Conferencing experiences in your apps.

33 lines 1.28 kB
import * as React from 'react'; import Animated, { KeyboardState, useAnimatedKeyboard, useAnimatedStyle, useDerivedValue } from 'react-native-reanimated'; import { useKeyboardState } from '../hooks-util'; export const HMSKeyboardAvoidingView = ({ children, style, styleWhenInactive, styleWhenActive, bottomOffset = 0 }) => { const animatedKeyboard = useAnimatedKeyboard(); const { keyboardState } = useKeyboardState(); const initialPageY = useDerivedValue(() => { return typeof bottomOffset === 'number' ? bottomOffset : bottomOffset.value; }, [bottomOffset]); const keyboardAvoidStyle = useAnimatedStyle(() => { const keyboardHeight = animatedKeyboard.height.value; const keyboardHidden = keyboardHeight <= initialPageY.value || keyboardState.value === KeyboardState.CLOSED; return { ...(keyboardHidden ? styleWhenInactive : styleWhenActive), transform: [{ translateY: keyboardHidden ? 0 // Keep element at original `pageY` till and when keyboard height is less than `pageY` : -(keyboardHeight - initialPageY.value) }] }; }); return /*#__PURE__*/React.createElement(Animated.View, { style: [style, keyboardAvoidStyle] }, children); }; //# sourceMappingURL=HMSKeyboardAvoidingView.js.map