mattermost-mobile/app/hooks/android_adjust_soft_keyboard/index.ts
Mattermost Build 2499e487f9
Fix android keyboard area when switching apps (#8554) (#8559)
(cherry picked from commit 762bbabfa0)

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
2025-02-05 08:40:05 +02:00

39 lines
1.2 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import RNUtils from '@mattermost/rnutils';
import {useEffect, useRef} from 'react';
import {Keyboard} from 'react-native';
import {Navigation, type EventSubscription} from 'react-native-navigation';
import type {AvailableScreens} from '@typings/screens/navigation';
export function useAndroidAdjustSoftKeyboard(screen?: AvailableScreens) {
const timeout = useRef<NodeJS.Timeout>();
useEffect(() => {
let unsubscribe: EventSubscription;
const listener = {
componentDidAppear: () => {
if (Keyboard.isVisible()) {
Keyboard.dismiss();
}
timeout.current = setTimeout(() => {
RNUtils.setSoftKeyboardToAdjustNothing();
}, 10);
},
componentDidDisappear: () => {
RNUtils.setSoftKeyboardToAdjustResize();
},
};
if (screen) {
unsubscribe = Navigation.events().registerComponentListener(listener, screen);
}
return () => {
clearTimeout(timeout.current);
unsubscribe?.remove();
};
}, []);
}