Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix offline workspace save #54634

Merged
merged 9 commits into from
Jan 1, 2025
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
Loading