// @ts-nocheck
import * as React from 'react';
import { Keyboard, View, Platform, Animated, KeyboardAvoidingView, } from 'react-native';
const KeyboardViewSpacer = ({ children, useNativeDriver = false, }) => {
    const [keyboardHeight, setKeyboardHeight] = React.useState(Platform.OS === 'android' ? 0 : new Animated.Value(0));
    const keyboardDidShowSub = React.useRef(null);
    const keyboardDidHideSub = React.useRef(null);
    const keyboardShow = (event) => {
        if (Platform.OS === 'android') {
            setKeyboardHeight(event.endCoordinates ? event.endCoordinates.height : event.end.height);
        }
        else {
            Animated.parallel([
                Animated.timing(keyboardHeight, {
                    duration: event.duration,
                    toValue: event.endCoordinates.height,
                    useNativeDriver,
                }),
            ]).start();
        }
    };
    const hideKeyboard = (event) => {
        if (Platform.OS === 'android') {
            setKeyboardHeight(0);
        }
        else {
            Animated.parallel([
                Animated.timing(keyboardHeight, {
                    duration: event.duration,
                    toValue: 0,
                    useNativeDriver,
                }),
            ]).start();
        }
    };
    React.useEffect(() => {
        // trigger this after component have mounted
        keyboardDidShowSub.current = Keyboard.addListener(Platform.OS === 'android' ? 'keyboardDidShow' : 'keyboardWillShow', keyboardShow);
        keyboardDidHideSub.current = Keyboard.addListener(Platform.OS === 'android' ? 'keyboardDidHide' : 'keyboardWillHide', hideKeyboard);
        // Clearing the events ont
        return () => {
            keyboardDidShowSub.current?.remove();
            keyboardDidHideSub.current?.remove();
            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 ? 50 : keyboardHeight,
        }}>
				{children}
				<KeyboardAvoidingView behavior="padding" keyboardVerticalOffset={-(keyboardHeight / 2)}/>
			</View>);
    }
    return (<Animated.View style={{ paddingBottom: keyboardHeight, flex: 1 }}>
			{children}
		</Animated.View>);
};
export default KeyboardViewSpacer;
//# sourceMappingURL=index.js.map