import * as React from 'react';
import { Keyboard, View, Platform, KeyboardAvoidingView } from 'react-native';
const KeyboardViewSpacer = ({ children, }) => {
    const [keyboardHeight, setKeyboardHeight] = React.useState(0);
    const keyboardDidShowSub = React.useRef(null);
    const keyboardDidHideSub = React.useRef(null);
    const keyboardShow = (e) => {
        setKeyboardHeight(e.endCoordinates ? e.endCoordinates.height : e.end.height);
    };
    const hideKeyboard = (e) => {
        setKeyboardHeight(0);
    };
    React.useEffect(() => {
        // trigger this after component have mounted
        keyboardDidShowSub.current = Keyboard.addListener('keyboardDidShow', keyboardShow);
        keyboardDidHideSub.current = Keyboard.addListener('keyboardDidHide', hideKeyboard);
        // Clearing the events ont
        return () => {
            keyboardDidShowSub.current = null;
            keyboardDidHideSub.current = null;
        };
    }, []);
    //Gifted Chat keyboard works fine in iOS so not changing anything on iOS side
    // This is hacky way
    if (Platform.OS === 'android') {
        return (<View style={{
            bottom: keyboardHeight ? -(keyboardHeight / 2) + 25 : keyboardHeight
        }}>
        {children}
        <KeyboardAvoidingView behavior={'padding'} keyboardVerticalOffset={-(keyboardHeight / 2)}/>
      </View>);
    }
    else {
        return (<>
      {children}
      </>);
    }
};
export default KeyboardViewSpacer;
//# sourceMappingURL=index.js.map