Skip to content

Commit 09a5925

Browse files
authored
Merge pull request #90128 from software-mansion-labs/@GCyganek/landscape-mode/restore-header-on-screen-focus-loss
Fix Chat - Claim offer banner is partially visible when keyboard is closed in landscape mode
2 parents aa9ad78 + 1677b5e commit 09a5925

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/components/CollapsibleHeaderOnKeyboard/index.native.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React, {useEffect, useRef} from 'react';
33
import type {LayoutChangeEvent} from 'react-native';
44
import {useReanimatedKeyboardAnimation} from 'react-native-keyboard-controller';
55
import Reanimated, {Easing, useAnimatedReaction, useAnimatedStyle, useSharedValue, withTiming} from 'react-native-reanimated';
6+
import usePrevious from '@hooks/usePrevious';
67
import useWindowDimensions from '@hooks/useWindowDimensions';
78
import isInLandscapeModeUtil from '@libs/isInLandscapeMode';
89
import type {CollapsibleHeaderOnKeyboardProps} from './types';
@@ -29,6 +30,7 @@ function isKeyboardOpeningAtGivenProgress(keyboardProgress: number, prevKeyboard
2930
*/
3031
function CollapsibleHeaderOnKeyboard({children, collapsibleHeaderOffset = 0}: CollapsibleHeaderOnKeyboardProps) {
3132
const isFocused = useIsFocused();
33+
const prevIsFocused = usePrevious(isFocused);
3234
// JS ref guards against re-measurement when the Reanimated.View fires onLayout with height=0
3335
const naturalHeightRef = useRef(-1);
3436
// Worklet-accessible mirror of naturalHeightRef. -1 signals "not yet measured".
@@ -81,6 +83,20 @@ function CollapsibleHeaderOnKeyboard({children, collapsibleHeaderOffset = 0}: Co
8183
}
8284
}, [isInLandscapeMode, isFocused, animatedHeight]);
8385

86+
// Restores the header when the screen loses focus
87+
useEffect(() => {
88+
if (!prevIsFocused || isFocused) {
89+
return;
90+
}
91+
92+
const naturalHeightValue = naturalHeightRef.current;
93+
if (naturalHeightValue === -1) {
94+
return;
95+
}
96+
animatedHeight.set(withTiming(naturalHeightValue, {duration: RESTORE_DURATION}));
97+
// eslint-disable-next-line react-hooks/exhaustive-deps -- we only want to run this effect when the screen loses focus
98+
}, [isFocused]);
99+
84100
// Runs on the UI thread whenever keyboard state changes.
85101
// Fires at two key moments:
86102
// 1. When keyboard just starts opening: on iOS keyboardHeight is already at its final value

0 commit comments

Comments
 (0)