"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
// @ts-nocheck
const React = __importStar(require("react"));
const react_native_1 = require("react-native");
const KeyboardViewSpacer = ({ children, useNativeDriver = false, }) => {
    const [keyboardHeight, setKeyboardHeight] = React.useState(react_native_1.Platform.OS === 'android' ? 0 : new react_native_1.Animated.Value(0));
    const keyboardDidShowSub = React.useRef(null);
    const keyboardDidHideSub = React.useRef(null);
    const keyboardShow = (event) => {
        if (react_native_1.Platform.OS === 'android') {
            setKeyboardHeight(event.endCoordinates
                ? event.endCoordinates.height
                : event.end.height);
        }
        else {
            react_native_1.Animated.parallel([
                react_native_1.Animated.timing(keyboardHeight, {
                    duration: event.duration,
                    toValue: event.endCoordinates.height,
                    useNativeDriver,
                }),
            ]).start();
        }
    };
    const hideKeyboard = (event) => {
        if (react_native_1.Platform.OS === 'android') {
            setKeyboardHeight(0);
        }
        else {
            react_native_1.Animated.parallel([
                react_native_1.Animated.timing(keyboardHeight, {
                    duration: event.duration,
                    toValue: 0,
                    useNativeDriver,
                }),
            ]).start();
        }
    };
    React.useEffect(() => {
        // trigger this after component have mounted
        keyboardDidShowSub.current = react_native_1.Keyboard.addListener(react_native_1.Platform.OS === 'android' ? 'keyboardDidShow' : 'keyboardWillShow', keyboardShow);
        keyboardDidHideSub.current = react_native_1.Keyboard.addListener(react_native_1.Platform.OS === 'android' ? 'keyboardDidHide' : 'keyboardWillHide', hideKeyboard);
        // Clearing the events ont
        return () => {
            var _a, _b;
            (_a = keyboardDidShowSub.current) === null || _a === void 0 ? void 0 : _a.remove();
            (_b = keyboardDidHideSub.current) === null || _b === void 0 ? void 0 : _b.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 (react_native_1.Platform.OS === 'android') {
        return (React.createElement(react_native_1.View, { style: {
                bottom: keyboardHeight ? 50 : keyboardHeight,
            } },
            children,
            React.createElement(react_native_1.KeyboardAvoidingView, { behavior: "padding", keyboardVerticalOffset: -(keyboardHeight / 2) })));
    }
    return (React.createElement(react_native_1.Animated.View, { style: { paddingBottom: keyboardHeight, flex: 1 } }, children));
};
exports.default = KeyboardViewSpacer;
//# sourceMappingURL=index.js.map