Skip to content

Commit

Permalink
Merge pull request #54634 from huult/54609-offline-workspace-save
Browse files Browse the repository at this point in the history
fix offline workspace save
  • Loading branch information
mountiny authored Jan 1, 2025
2 parents 8b56d93 + 2a65b3e commit 6e78dd4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6501,6 +6501,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

0 comments on commit 6e78dd4

Please sign in to comment.