Ipad focus Issue

let isTouching = false;
let lastFocusedInput = null;

document.addEventListener('touchstart', (event) => {
    if ((event.target.matches('input[type="text"]') || event.target.matches('textarea')) && (!event.target.classList.contains('dc-field-alert-flag'))) {
        isTouching = true;
        if (lastFocusedInput !== event.target && lastFocusedInput !== null) {
            lastFocusedInput.blur();
        }
        lastFocusedInput = event.target;
        event.target.focus();
    } else {
        isTouching = false;
    }
});

document.addEventListener('touchend', (event) => {
    isTouching = false;
});

document.addEventListener('focusout', (event) => {
    if (isTouching && (event.target.matches('input[type="text"]') || event.target.matches('textarea')) && (!event.target.classList.contains('dc-field-alert-flag'))) {
        event.preventDefault();
        event.target.focus();
    }
});

this code is blocking the keyboard to come and going when the textare is moved to bottom and touch means but when we move the textarea to up and touch means the keyboard is coming correctly