Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6455,6 +6455,7 @@ const CONST = {
LHN_WORKSPACE_CHAT_TOOLTIP: 'workspaceChatLHNTooltip',
GLOBAL_CREATE_TOOLTIP: 'globalCreateTooltip',
},
SMART_BANNER_HEIGHT: 152,
} as const;

type Country = keyof typeof CONST.ALL_COUNTRIES;
Expand Down
26 changes: 15 additions & 11 deletions src/utils/keyboard/index.website.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import {Keyboard} from 'react-native';
import CONST from '@src/CONST';

let isVisible = false;
const initialViewportHeight = window?.visualViewport?.height;

const handleResize = () => {
const currentHeight = window?.visualViewport?.height;
const viewportHeight = window?.visualViewport?.height;

if (!currentHeight || !initialViewportHeight) {
if (!viewportHeight || !initialViewportHeight) {
return;
}

if (currentHeight < initialViewportHeight) {
isVisible = true;
return;
}

if (currentHeight === initialViewportHeight) {
isVisible = false;
}
// Determine if the keyboard is visible by checking if the height difference exceeds 152px.
// The 152px threshold accounts for UI elements such as smart banners on iOS Retina (max ~152px)
// and smaller overlays like offline indicators on Android. Height differences > 152px reliably indicate keyboard visibility.
isVisible = initialViewportHeight - viewportHeight > CONST.SMART_BANNER_HEIGHT;
};

window.visualViewport?.addEventListener('resize', handleResize);
Expand All @@ -30,7 +27,14 @@ const dismiss = (): Promise<void> => {
}

const handleDismissResize = () => {
if (window.visualViewport?.height !== initialViewportHeight) {
const viewportHeight = window?.visualViewport?.height;

if (!viewportHeight || !initialViewportHeight) {
return;
}

const isKeyboardVisible = initialViewportHeight - viewportHeight > CONST.SMART_BANNER_HEIGHT;
if (isKeyboardVisible) {
return;
}

Expand Down