diff --git a/src/components/ApproverSelectionList.tsx b/src/components/ApproverSelectionList.tsx index 833e9a64baec..784eab25857d 100644 --- a/src/components/ApproverSelectionList.tsx +++ b/src/components/ApproverSelectionList.tsx @@ -3,6 +3,7 @@ import useInitialSelection from '@hooks/useInitialSelection'; import {useMemoizedLazyIllustrations} from '@hooks/useLazyAsset'; import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; +import useShouldFooterBeInsideList from '@hooks/useShouldFooterBeInsideList'; import useThemeStyles from '@hooks/useThemeStyles'; import {canUseTouchScreen} from '@libs/DeviceCapabilities'; @@ -25,6 +26,7 @@ import type {ListItem} from './SelectionList/types'; import BlockingView from './BlockingViews/BlockingView'; import FullPageNotFoundView from './BlockingViews/FullPageNotFoundView'; +import CollapsibleHeaderOnKeyboard from './CollapsibleHeaderOnKeyboard'; import HeaderWithBackButton from './HeaderWithBackButton'; import ScreenWrapper from './ScreenWrapper'; import SelectionList from './SelectionList'; @@ -85,6 +87,7 @@ function ApproverSelectionList({ const [countryCode = CONST.DEFAULT_COUNTRY_CODE] = useOnyx(ONYXKEYS.COUNTRY_CODE); const shouldShowTextInput = shouldShowTextInputProp ?? allApprovers?.length >= CONST.STANDARD_LIST_ITEM_LIMIT; const lazyIllustrations = useMemoizedLazyIllustrations(['TurtleInShell']); + const shouldFooterBeInsideList = useShouldFooterBeInsideList(); const handleSearchChange = useCallback( (term: string) => { @@ -169,11 +172,13 @@ function ApproverSelectionList({ onLinkPress={goBackFromInvalidPolicy} addBottomSafeAreaPadding > - - {subtitle} + + + {subtitle} + ; + + /** Reports a member's natural (expanded) height, so the group can decide from the combined total of its members. */ + setMemberNaturalHeight: (memberID: string, height: number) => void; + + /** Drops a member's contribution to the total when it unmounts. */ + unregisterMember: (memberID: string) => void; +}; + +const CollapsibleHeaderOnKeyboardGroupContext = createContext(undefined); + +function useCollapsibleHeaderOnKeyboardGroup() { + return useContext(CollapsibleHeaderOnKeyboardGroupContext); +} + +export default CollapsibleHeaderOnKeyboardGroupContext; +export {useCollapsibleHeaderOnKeyboardGroup}; diff --git a/src/components/CollapsibleHeaderOnKeyboard/CollapsibleHeaderView.tsx b/src/components/CollapsibleHeaderOnKeyboard/CollapsibleHeaderView.tsx new file mode 100644 index 000000000000..923783ef28e4 --- /dev/null +++ b/src/components/CollapsibleHeaderOnKeyboard/CollapsibleHeaderView.tsx @@ -0,0 +1,26 @@ +import React from 'react'; +import Reanimated from 'react-native-reanimated'; + +import type {CollapsibleHeader} from './useCollapsibleHeader'; + +type CollapsibleHeaderViewProps = { + children: React.ReactNode; + + /** The state returned by `useCollapsibleHeader`. */ + collapsibleHeader: CollapsibleHeader; +}; + +function CollapsibleHeaderView({children, collapsibleHeader}: CollapsibleHeaderViewProps) { + return ( + + + {children} + + + ); +} + +export default CollapsibleHeaderView; diff --git a/src/components/CollapsibleHeaderOnKeyboard/Group/index.native.tsx b/src/components/CollapsibleHeaderOnKeyboard/Group/index.native.tsx new file mode 100644 index 000000000000..370a34756dcd --- /dev/null +++ b/src/components/CollapsibleHeaderOnKeyboard/Group/index.native.tsx @@ -0,0 +1,93 @@ +import CollapsibleHeaderOnKeyboardGroupContext from '@components/CollapsibleHeaderOnKeyboard/CollapsibleHeaderOnKeyboardGroupContext'; +import {getAvailableHeightForCollapsibleContent, getKeyboardCollapseState} from '@components/CollapsibleHeaderOnKeyboard/constants'; +import type {CollapsibleHeaderOnKeyboardGroupProps} from '@components/CollapsibleHeaderOnKeyboard/types'; +import useCollapsibleScreenState from '@components/CollapsibleHeaderOnKeyboard/useCollapsibleScreenState'; +import useKeyboardCollapseMetrics from '@components/CollapsibleHeaderOnKeyboard/useKeyboardCollapseMetrics'; + +import React, {useEffect, useRef} from 'react'; +import {useAnimatedReaction, useSharedValue} from 'react-native-reanimated'; + +/** + * Makes a single collapse decision for several `CollapsibleHeaderOnKeyboardGroupMember` instances + * that cannot share one wrapper because their JSX lives in different subtrees + */ +function CollapsibleHeaderOnKeyboardGroup({children, collapsibleHeaderOffset = 0}: CollapsibleHeaderOnKeyboardGroupProps) { + const shouldCollapse = useSharedValue(false); + const memberNaturalHeightsRef = useRef>({}); + const totalNaturalHeight = useSharedValue(0); + + const {isFocused, isInLandscapeMode, isFocusedSV, isInLandscapeModeSV} = useCollapsibleScreenState(); + const {keyboardHeightSV, keyboardProgressSV, availableWindowHeightSV, collapsibleHeaderOffsetSV} = useKeyboardCollapseMetrics(collapsibleHeaderOffset); + + // Collapsing only applies to a focused screen in landscape. Clear the flag on the way out so the members restore + // and a later reaction never acts on a decision that was made for a layout that no longer exists. + useEffect(() => { + if (isInLandscapeMode && isFocused) { + return; + } + shouldCollapse.set(false); + }, [isInLandscapeMode, isFocused, shouldCollapse]); + + const updateTotalMembersNaturalHeight = () => { + totalNaturalHeight.set(Object.values(memberNaturalHeightsRef.current).reduce((total, height) => total + height, 0)); + }; + + const setMemberNaturalHeight = (memberID: string, height: number) => { + if (memberNaturalHeightsRef.current[memberID] === height) { + return; + } + memberNaturalHeightsRef.current[memberID] = height; + updateTotalMembersNaturalHeight(); + }; + + const unregisterMember = (memberID: string) => { + if (!(memberID in memberNaturalHeightsRef.current)) { + return; + } + delete memberNaturalHeightsRef.current[memberID]; + updateTotalMembersNaturalHeight(); + }; + + // Mirrors the single-instance reaction in `CollapsibleHeaderOnKeyboard`, except that it compares the combined + // natural height of every member instead of one header's height, and publishes a boolean the members follow. + useAnimatedReaction( + () => ({ + keyboardHeight: keyboardHeightSV.get(), + keyboardProgress: keyboardProgressSV.get(), + availableWindowHeightValue: availableWindowHeightSV.get(), + totalNaturalHeightValue: totalNaturalHeight.get(), + }), + ({keyboardHeight, keyboardProgress, availableWindowHeightValue, totalNaturalHeightValue}, previous) => { + // If the screen is not focused, bail out + if (!isFocusedSV.get() || !isInLandscapeModeSV.get()) { + return; + } + + const {isKeyboardClosed, shouldReact} = getKeyboardCollapseState(keyboardProgress, previous?.keyboardProgress ?? 0, keyboardHeight); + + // If the keyboard is closed, restore the members + if (isKeyboardClosed) { + shouldCollapse.set(false); + return; + } + + if (!shouldReact) { + return; + } + + // Nothing has been measured yet, so there is no total to compare against. + if (totalNaturalHeightValue <= 0) { + return; + } + + // The members share what is left once the focused input and everything outside the group have their space. + const availableHeightForMembers = getAvailableHeightForCollapsibleContent(availableWindowHeightValue, keyboardHeight, collapsibleHeaderOffsetSV.get()); + + shouldCollapse.set(availableHeightForMembers < totalNaturalHeightValue); + }, + ); + + return {children}; +} + +export default CollapsibleHeaderOnKeyboardGroup; diff --git a/src/components/CollapsibleHeaderOnKeyboard/Group/index.tsx b/src/components/CollapsibleHeaderOnKeyboard/Group/index.tsx new file mode 100644 index 000000000000..3870582b8363 --- /dev/null +++ b/src/components/CollapsibleHeaderOnKeyboard/Group/index.tsx @@ -0,0 +1,11 @@ +import type {CollapsibleHeaderOnKeyboardGroupProps} from '@components/CollapsibleHeaderOnKeyboard/types'; + +/** + * Web no-op that renders children as-is, matching `CollapsibleHeaderOnKeyboard`. The collapsing behaviour is only needed + * on native where the software keyboard reduces the visible viewport height. + */ +function CollapsibleHeaderOnKeyboardGroup({children}: CollapsibleHeaderOnKeyboardGroupProps) { + return children; +} + +export default CollapsibleHeaderOnKeyboardGroup; diff --git a/src/components/CollapsibleHeaderOnKeyboard/GroupMember/index.native.tsx b/src/components/CollapsibleHeaderOnKeyboard/GroupMember/index.native.tsx new file mode 100644 index 000000000000..66f627414c83 --- /dev/null +++ b/src/components/CollapsibleHeaderOnKeyboard/GroupMember/index.native.tsx @@ -0,0 +1,61 @@ +import {useCollapsibleHeaderOnKeyboardGroup} from '@components/CollapsibleHeaderOnKeyboard/CollapsibleHeaderOnKeyboardGroupContext'; +import CollapsibleHeaderView from '@components/CollapsibleHeaderOnKeyboard/CollapsibleHeaderView'; +import {MIN_HEADER_HEIGHT_ON_COLLAPSE} from '@components/CollapsibleHeaderOnKeyboard/constants'; +import type {CollapsibleHeaderOnKeyboardGroupMemberProps} from '@components/CollapsibleHeaderOnKeyboard/types'; +import useCollapsibleHeader, {collapseHeaderTo, restoreHeaderTo} from '@components/CollapsibleHeaderOnKeyboard/useCollapsibleHeader'; + +import React, {useEffect, useId, useRef} from 'react'; +import {useAnimatedReaction, useSharedValue} from 'react-native-reanimated'; + +/** + * One element of a `CollapsibleHeaderOnKeyboardGroup`. Reports its measured height to the group and then follows the + * group's single decision, collapsing fully together with the group's other members. + * + * Use this instead of `CollapsibleHeaderOnKeyboard` whenever several collapsing elements stack on top of each other, + * so the space above the keyboard is weighed once against all of them rather than once per element. + */ +function CollapsibleHeaderOnKeyboardGroupMember({children}: CollapsibleHeaderOnKeyboardGroupMemberProps) { + const group = useCollapsibleHeaderOnKeyboardGroup(); + const memberID = useId(); + // `onLayout` only reports a height when it changes, so the last reported one is kept here to re-register with. + const reportedNaturalHeightRef = useRef(-1); + const collapsibleHeader = useCollapsibleHeader((height) => { + reportedNaturalHeightRef.current = height; + group?.setMemberNaturalHeight(memberID, height); + }); + const {naturalHeight, animatedHeight, isFocusedSV, isInLandscapeModeSV} = collapsibleHeader; + + const ungroupedShouldCollapse = useSharedValue(false); + const shouldCollapseSV = group?.shouldCollapse ?? ungroupedShouldCollapse; + + // The cleanup drops this member's contribution to the group total. It runs on unmount, but also whenever the + // context value gets a new identity, so the height has to be put back on every run. + useEffect(() => { + if (!group) { + return; + } + if (reportedNaturalHeightRef.current !== -1) { + group.setMemberNaturalHeight(memberID, reportedNaturalHeightRef.current); + } + return () => group.unregisterMember(memberID); + }, [group, memberID]); + + useAnimatedReaction( + () => ({shouldCollapse: shouldCollapseSV.get(), naturalHeightValue: naturalHeight.get()}), + ({shouldCollapse, naturalHeightValue}) => { + if (!isFocusedSV.get() || !isInLandscapeModeSV.get() || naturalHeightValue === -1) { + return; + } + + if (shouldCollapse) { + collapseHeaderTo(animatedHeight, MIN_HEADER_HEIGHT_ON_COLLAPSE); + return; + } + restoreHeaderTo(animatedHeight, naturalHeightValue); + }, + ); + + return {children}; +} + +export default CollapsibleHeaderOnKeyboardGroupMember; diff --git a/src/components/CollapsibleHeaderOnKeyboard/GroupMember/index.tsx b/src/components/CollapsibleHeaderOnKeyboard/GroupMember/index.tsx new file mode 100644 index 000000000000..b77006b0ce6b --- /dev/null +++ b/src/components/CollapsibleHeaderOnKeyboard/GroupMember/index.tsx @@ -0,0 +1,11 @@ +import type {CollapsibleHeaderOnKeyboardGroupMemberProps} from '@components/CollapsibleHeaderOnKeyboard/types'; + +/** + * Web no-op that renders children as-is, matching `CollapsibleHeaderOnKeyboard`. The collapsing behaviour is only needed + * on native where the software keyboard reduces the visible viewport height. + */ +function CollapsibleHeaderOnKeyboardGroupMember({children}: CollapsibleHeaderOnKeyboardGroupMemberProps) { + return children; +} + +export default CollapsibleHeaderOnKeyboardGroupMember; diff --git a/src/components/CollapsibleHeaderOnKeyboard/constants.ts b/src/components/CollapsibleHeaderOnKeyboard/constants.ts new file mode 100644 index 000000000000..08a3e018ae62 --- /dev/null +++ b/src/components/CollapsibleHeaderOnKeyboard/constants.ts @@ -0,0 +1,51 @@ +import variables from '@styles/variables'; + +const COLLAPSE_DURATION = 100; +const RESTORE_DURATION = 300; +// Assumed vertical space for the focused input field that is used to reserve space above the keyboard. +const VERTICAL_SPACE_FOR_FOCUSED_INPUT = variables.inputHeight + variables.inputPaddingBottom + variables.inputPaddingTop; +const KEYBOARD_OPENING_PROGRESS_THRESHOLDS = [0.5, 0.7, 0.8, 0.85, 0.9, 0.95, 0.99]; +const MIN_HEADER_HEIGHT_ON_COLLAPSE = 8; + +function isKeyboardOpeningAtGivenProgress(keyboardProgress: number, prevKeyboardProgress: number, requiredProgress: number[]): boolean { + 'worklet'; + + return requiredProgress.some((progress) => keyboardProgress > progress && prevKeyboardProgress <= progress); +} + +/** + * Tells a keyboard frame apart from the ones worth acting on, so that `CollapsibleHeaderOnKeyboard` and + * `CollapsibleHeaderOnKeyboardGroup` cannot drift apart on when they collapse. + */ +function getKeyboardCollapseState(keyboardProgress: number, prevKeyboardProgress: number, keyboardHeight: number): {isKeyboardClosed: boolean; shouldReact: boolean} { + 'worklet'; + + if (keyboardProgress === 0 && keyboardHeight === 0) { + return {isKeyboardClosed: true, shouldReact: false}; + } + + // The keyboard is closing + if (prevKeyboardProgress > keyboardProgress) { + return {isKeyboardClosed: false, shouldReact: false}; + } + + const isKeyboardStartingOpening = prevKeyboardProgress === 0 && keyboardProgress > 0; + const isKeyboardOpeningAndReachingThreshold = isKeyboardOpeningAtGivenProgress(keyboardProgress, prevKeyboardProgress, KEYBOARD_OPENING_PROGRESS_THRESHOLDS); + const isKeyboardFullyOpen = keyboardProgress === 1; + + return {isKeyboardClosed: false, shouldReact: isKeyboardStartingOpening || isKeyboardOpeningAndReachingThreshold || isKeyboardFullyOpen}; +} + +/** + * Vertical space the collapsing content can take once the keyboard, the focused input and everything accounted for by + * `collapsibleHeaderOffset` have taken theirs. Shared so the single-header and the group maths cannot diverge. + */ +function getAvailableHeightForCollapsibleContent(availableWindowHeight: number, keyboardHeight: number, collapsibleHeaderOffset: number): number { + 'worklet'; + + // keyboardHeight is negative when open (e.g. -291), so keyboardTop = availableWindowHeight + keyboardHeight. + const keyboardTop = availableWindowHeight + keyboardHeight; + return keyboardTop - VERTICAL_SPACE_FOR_FOCUSED_INPUT - collapsibleHeaderOffset; +} + +export {COLLAPSE_DURATION, RESTORE_DURATION, MIN_HEADER_HEIGHT_ON_COLLAPSE, getKeyboardCollapseState, getAvailableHeightForCollapsibleContent}; diff --git a/src/components/CollapsibleHeaderOnKeyboard/index.native.tsx b/src/components/CollapsibleHeaderOnKeyboard/index.native.tsx index b51a2c6fff63..134c682e1a6d 100644 --- a/src/components/CollapsibleHeaderOnKeyboard/index.native.tsx +++ b/src/components/CollapsibleHeaderOnKeyboard/index.native.tsx @@ -1,32 +1,12 @@ -import usePrevious from '@hooks/usePrevious'; -import useSafeAreaInsets from '@hooks/useSafeAreaInsets'; -import useWindowDimensions from '@hooks/useWindowDimensions'; - -import isInLandscapeModeUtil from '@libs/isInLandscapeMode'; - -import variables from '@styles/variables'; - -import type {LayoutChangeEvent} from 'react-native'; - -import {useIsFocused} from '@react-navigation/native'; -import React, {useEffect, useRef} from 'react'; -import {useReanimatedKeyboardAnimation} from 'react-native-keyboard-controller'; -import Reanimated, {Easing, useAnimatedReaction, useAnimatedStyle, useSharedValue, withTiming} from 'react-native-reanimated'; +import React from 'react'; +import {useAnimatedReaction} from 'react-native-reanimated'; import type {CollapsibleHeaderOnKeyboardProps} from './types'; -const COLLAPSE_DURATION = 100; -const RESTORE_DURATION = 300; -// Assumed vertical space for the focused input field — used to reserve space above the keyboard. -const VERTICAL_SPACE_FOR_FOCUSED_INPUT = variables.inputHeight + variables.inputPaddingBottom + variables.inputPaddingTop; -const KEYBOARD_OPENING_PROGRESS_THRESHOLDS = [0.5, 0.7, 0.8, 0.85, 0.9, 0.95, 0.99]; -const MIN_HEADER_HEIGHT_ON_COLLAPSE = 8; - -function isKeyboardOpeningAtGivenProgress(keyboardProgress: number, prevKeyboardProgress: number, requiredProgress: number[]): boolean { - 'worklet'; - - return requiredProgress.some((progress) => keyboardProgress > progress && prevKeyboardProgress <= progress); -} +import CollapsibleHeaderView from './CollapsibleHeaderView'; +import {getAvailableHeightForCollapsibleContent, getKeyboardCollapseState, MIN_HEADER_HEIGHT_ON_COLLAPSE} from './constants'; +import useCollapsibleHeader, {collapseHeaderTo, restoreHeaderTo} from './useCollapsibleHeader'; +import useKeyboardCollapseMetrics from './useKeyboardCollapseMetrics'; /** * Wraps a header and collapses it upward when the keyboard is open and there is not enough @@ -37,95 +17,13 @@ function isKeyboardOpeningAtGivenProgress(keyboardProgress: number, prevKeyboard * Uses height animation (not translateY) so the freed space is reclaimed by the layout below. */ function CollapsibleHeaderOnKeyboard({children, collapsibleHeaderOffset = 0, alwaysCollapseHeaderOnKeyboard = false}: CollapsibleHeaderOnKeyboardProps) { - const isFocused = useIsFocused(); - const prevIsFocused = usePrevious(isFocused); - // JS ref guards against re-measurement when the Reanimated.View fires onLayout with height=0 - const naturalHeightRef = useRef(-1); - // Worklet-accessible mirror of naturalHeightRef. -1 signals "not yet measured". - const naturalHeight = useSharedValue(-1); - // Drives the animated style - const animatedHeight = useSharedValue(0); - - const {height: keyboardHeightSV, progress: keyboardProgressSV} = useReanimatedKeyboardAnimation(); - - const {windowWidth, windowHeight} = useWindowDimensions(); - const {top: topSafeAreaInset} = useSafeAreaInsets(); - const availableWindowHeight = windowHeight - topSafeAreaInset; - const isInLandscapeMode = isInLandscapeModeUtil(windowWidth, windowHeight); - // Keep window dimensions and offset accessible on the UI thread. Stable refs, excluded from deps. - const availableWindowHeightSV = useSharedValue(availableWindowHeight); - const collapsibleHeaderOffsetSV = useSharedValue(collapsibleHeaderOffset); - const isFocusedSV = useSharedValue(isFocused); - const isInLandscapeModeSV = useSharedValue(isInLandscapeMode); - useEffect(() => { - availableWindowHeightSV.set(availableWindowHeight); - }, [availableWindowHeight, availableWindowHeightSV]); - useEffect(() => { - collapsibleHeaderOffsetSV.set(collapsibleHeaderOffset); - }, [collapsibleHeaderOffset, collapsibleHeaderOffsetSV]); - useEffect(() => { - isFocusedSV.set(isFocused); - }, [isFocused, isFocusedSV]); - useEffect(() => { - isInLandscapeModeSV.set(isInLandscapeMode); - }, [isInLandscapeMode, isInLandscapeModeSV]); - - const onLayout = (e: LayoutChangeEvent) => { - const height = e.nativeEvent.layout.height; - - if (height <= 0) { - return; - } - - // Portrait: always sync height immediately in both directions (e.g. next step appears, or - // Submit shows beside More after Retract). Avoids stale clipped height from the collapse animation. - if (!isInLandscapeMode) { - naturalHeightRef.current = height; - naturalHeight.set(height); - animatedHeight.set(height); - return; - } - - // First measurement, or content changed while keyboard is fully open - // (to skip onLayout calls triggered by our own height animation collapsing the view to 0) - if (naturalHeightRef.current === -1 || (animatedHeight.get() >= naturalHeightRef.current && height !== naturalHeightRef.current)) { - naturalHeightRef.current = height; - naturalHeight.set(height); - animatedHeight.set(height); - } - }; + const collapsibleHeader = useCollapsibleHeader(); + const {naturalHeight, animatedHeight, isFocusedSV, isInLandscapeModeSV} = collapsibleHeader; - // Restores the header when the screen goes from landscape to portrait mode. - useEffect(() => { - const naturalHeightValue = naturalHeight.get(); - if (!isInLandscapeMode && isFocused && naturalHeightValue !== -1) { - animatedHeight.set(withTiming(naturalHeightValue, {duration: RESTORE_DURATION})); - } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [isInLandscapeMode]); + const {keyboardHeightSV, keyboardProgressSV, availableWindowHeightSV, collapsibleHeaderOffsetSV} = useKeyboardCollapseMetrics(collapsibleHeaderOffset); - // Restores the header when the screen loses focus - useEffect(() => { - if (!prevIsFocused || isFocused) { - return; - } - - const naturalHeightValue = naturalHeight.get(); - if (naturalHeightValue === -1) { - return; - } - animatedHeight.set(withTiming(naturalHeightValue, {duration: RESTORE_DURATION})); - // eslint-disable-next-line react-hooks/exhaustive-deps -- we only want to run this effect when the screen loses focus - }, [isFocused]); - - // Runs on the UI thread whenever keyboard state changes. - // Fires at two key moments: - // 1. When keyboard just starts opening: on iOS keyboardHeight is already at its final value - // (set by onKeyboardMoveStart), so the collapse begins before the list scrolls the - // input into place — preventing the input from ending up behind the collapsed header. - // 2. When keyboard is reaching a threshold while opening: on Android keyboardHeight - // reaches its final value when fully open (set by onKeyboardMoveEnd), so we check at thresholds - // to smoothly collapse the header. + // Runs on the UI thread whenever keyboard state changes. `getKeyboardCollapseState` picks the frames worth + // reacting to, everything below only decides what this single header does with them. useAnimatedReaction( () => ({ keyboardHeight: keyboardHeightSV.get(), @@ -138,79 +36,34 @@ function CollapsibleHeaderOnKeyboard({children, collapsibleHeaderOffset = 0, alw return; } + const {isKeyboardClosed, shouldReact} = getKeyboardCollapseState(keyboardProgress, previous?.keyboardProgress ?? 0, keyboardHeight); + // If the keyboard is closed, restore the header - const isKeyboardClosed = keyboardProgress === 0 && keyboardHeight === 0; if (isKeyboardClosed) { - animatedHeight.set(withTiming(naturalHeight.get(), {duration: RESTORE_DURATION})); - return; - } - - // If the keyboard is closing, bail out - const prevKeyboardProgress = previous?.keyboardProgress ?? 0; - if (prevKeyboardProgress > keyboardProgress) { + restoreHeaderTo(animatedHeight, naturalHeight.get()); return; } - // Only act when the keyboard is starting to open, reaching a threshold or fully open, not on every intermediate frame. - const isKeyboardStartingOpening = prevKeyboardProgress === 0 && keyboardProgress > 0; - const isKeyboardOpeningAndReachingThreshold = isKeyboardOpeningAtGivenProgress(keyboardProgress, prevKeyboardProgress, KEYBOARD_OPENING_PROGRESS_THRESHOLDS); - const isKeyboardFullyOpen = keyboardProgress === 1; - - if (!isKeyboardStartingOpening && !isKeyboardOpeningAndReachingThreshold && !isKeyboardFullyOpen) { + if (!shouldReact) { return; } - // keyboardHeight is negative when open (e.g. -291), so keyboardTop = availableWindowHeightValue + keyboardHeight. // Target header height: give the input exactly the space it needs above the keyboard, // the header gets what remains. Clamped to [MIN_HEADER_HEIGHT_ON_COLLAPSE, naturalHeight]. - const keyboardTop = availableWindowHeightValue + keyboardHeight; - const targetHeight = alwaysCollapseHeaderOnKeyboard - ? MIN_HEADER_HEIGHT_ON_COLLAPSE - : Math.max(MIN_HEADER_HEIGHT_ON_COLLAPSE, keyboardTop - VERTICAL_SPACE_FOR_FOCUSED_INPUT - collapsibleHeaderOffsetSV.get()); + const availableHeightForHeader = getAvailableHeightForCollapsibleContent(availableWindowHeightValue, keyboardHeight, collapsibleHeaderOffsetSV.get()); + const targetHeight = alwaysCollapseHeaderOnKeyboard ? MIN_HEADER_HEIGHT_ON_COLLAPSE : Math.max(MIN_HEADER_HEIGHT_ON_COLLAPSE, availableHeightForHeader); const naturalHeightValue = naturalHeight.get(); if (targetHeight >= naturalHeightValue) { // Enough space for the full header plus the input — restore or keep. - animatedHeight.set(withTiming(naturalHeightValue, {duration: RESTORE_DURATION})); + restoreHeaderTo(animatedHeight, naturalHeightValue); } else { - animatedHeight.set(withTiming(targetHeight, {duration: COLLAPSE_DURATION, easing: Easing.out(Easing.cubic)})); + collapseHeaderTo(animatedHeight, targetHeight); } }, ); - // Outer wrapper controls layout space (height collapses to 0, clips overflowing content). - const outerStyle = useAnimatedStyle(() => { - // When fully open, leave height undefined so the view sizes itself naturally. - // This avoids fighting the layout engine during orientation changes. - if (animatedHeight.get() >= naturalHeight.get()) { - return {overflow: 'hidden', height: 'auto'}; - } - return {height: animatedHeight.get(), overflow: 'hidden'}; - }); - - // Inner wrapper slides the content upward during landscape keyboard collapse only. - const innerStyle = useAnimatedStyle(() => { - if (animatedHeight.get() >= naturalHeight.get()) { - return {transform: [{translateY: 0}]}; - } - - if (!isInLandscapeModeSV.get()) { - return {transform: [{translateY: 0}]}; - } - - return {transform: [{translateY: animatedHeight.get() - naturalHeight.get()}]}; - }); - - return ( - - - {children} - - - ); + return {children}; } export default CollapsibleHeaderOnKeyboard; diff --git a/src/components/CollapsibleHeaderOnKeyboard/index.tsx b/src/components/CollapsibleHeaderOnKeyboard/index.tsx index e3ed2ec67e6a..f60e10aab88d 100644 --- a/src/components/CollapsibleHeaderOnKeyboard/index.tsx +++ b/src/components/CollapsibleHeaderOnKeyboard/index.tsx @@ -1,7 +1,7 @@ import type {CollapsibleHeaderOnKeyboardProps} from './types'; /** - * Web no-op — renders children as-is. The collapsing behaviour is only needed on native + * Web no-op that renders children as-is. The collapsing behaviour is only needed on native * where the software keyboard reduces the visible viewport height. */ function CollapsibleHeaderOnKeyboard({children}: CollapsibleHeaderOnKeyboardProps) { diff --git a/src/components/CollapsibleHeaderOnKeyboard/types.ts b/src/components/CollapsibleHeaderOnKeyboard/types.ts index 7734ac5eb062..3188a14fad39 100644 --- a/src/components/CollapsibleHeaderOnKeyboard/types.ts +++ b/src/components/CollapsibleHeaderOnKeyboard/types.ts @@ -1,8 +1,9 @@ type CollapsibleHeaderOnKeyboardProps = { children: React.ReactNode; - /** Additional vertical space (in px) occupied on screen by elements other than the wrapped - * component, keyboard, and focused input — e.g. a tab bar below the list. - * The collapse target is reduced by this amount so those elements are not counted twice. */ + /** + * Additional vertical space (in px) occupied on screen by elements other than the wrapped + * component, keyboard, and focused input. + */ collapsibleHeaderOffset?: number; /** @@ -12,5 +13,18 @@ type CollapsibleHeaderOnKeyboardProps = { alwaysCollapseHeaderOnKeyboard?: boolean; }; -// eslint-disable-next-line import/prefer-default-export -export type {CollapsibleHeaderOnKeyboardProps}; +type CollapsibleHeaderOnKeyboardGroupProps = { + children: React.ReactNode; + + /** + * Additional vertical space (in px) occupied on screen by elements that are neither members of this group, + * the keyboard, nor the focused input. + */ + collapsibleHeaderOffset?: number; +}; + +type CollapsibleHeaderOnKeyboardGroupMemberProps = { + children: React.ReactNode; +}; + +export type {CollapsibleHeaderOnKeyboardProps, CollapsibleHeaderOnKeyboardGroupProps, CollapsibleHeaderOnKeyboardGroupMemberProps}; diff --git a/src/components/CollapsibleHeaderOnKeyboard/useCollapsibleHeader.ts b/src/components/CollapsibleHeaderOnKeyboard/useCollapsibleHeader.ts new file mode 100644 index 000000000000..7a9f685d7955 --- /dev/null +++ b/src/components/CollapsibleHeaderOnKeyboard/useCollapsibleHeader.ts @@ -0,0 +1,136 @@ +import usePrevious from '@hooks/usePrevious'; + +import type {LayoutChangeEvent, ViewStyle} from 'react-native'; +import type {AnimatedStyle, SharedValue} from 'react-native-reanimated'; + +import {useEffect, useRef} from 'react'; +import {Easing, useAnimatedStyle, useSharedValue, withTiming} from 'react-native-reanimated'; + +import {COLLAPSE_DURATION, RESTORE_DURATION} from './constants'; +import useCollapsibleScreenState from './useCollapsibleScreenState'; + +type CollapsibleHeader = { + /** Measured height of the wrapped content. -1 signals "not yet measured". */ + naturalHeight: SharedValue; + + /** Height the wrapper is currently animated to. Callers drive the collapse by writing to it. */ + animatedHeight: SharedValue; + + /** UI-thread mirror of the screen's focus state. */ + isFocusedSV: SharedValue; + + /** UI-thread mirror of whether the window is in landscape. */ + isInLandscapeModeSV: SharedValue; + + /** To be spread onto `CollapsibleHeaderView`, which owns the two animated wrappers. */ + onLayout: (e: LayoutChangeEvent) => void; + outerStyle: AnimatedStyle; + innerStyle: AnimatedStyle; +}; + +/** Collapses the wrapped content to `targetHeight`. Quick, so the header is out of the way before the input lands. */ +function collapseHeaderTo(animatedHeight: SharedValue, targetHeight: number) { + 'worklet'; + + animatedHeight.set(withTiming(targetHeight, {duration: COLLAPSE_DURATION, easing: Easing.out(Easing.cubic)})); +} + +/** Gives the wrapped content its measured height back. */ +function restoreHeaderTo(animatedHeight: SharedValue, naturalHeight: number) { + 'worklet'; + + animatedHeight.set(withTiming(naturalHeight, {duration: RESTORE_DURATION})); +} + +/** + * Measurement and animated styles shared by `CollapsibleHeaderOnKeyboard` and `CollapsibleHeaderOnKeyboardGroupMember`. + */ +function useCollapsibleHeader(onNaturalHeightChange?: (height: number) => void): CollapsibleHeader { + const {isFocused, isInLandscapeMode, isFocusedSV, isInLandscapeModeSV} = useCollapsibleScreenState(); + const prevIsFocused = usePrevious(isFocused); + // JS ref guards against re-measurement when the Reanimated.View fires onLayout with height=0 + const naturalHeightRef = useRef(-1); + // Worklet-accessible mirror of naturalHeightRef. -1 signals "not yet measured". + const naturalHeight = useSharedValue(-1); + // Drives the animated style + const animatedHeight = useSharedValue(0); + + const onLayout = (e: LayoutChangeEvent) => { + const height = e.nativeEvent.layout.height; + + if (height <= 0) { + return; + } + + // Portrait: always sync height immediately in both directions (e.g. next step appears, or + // Submit shows beside More after Retract). Avoids stale clipped height from the collapse animation. + if (!isInLandscapeMode) { + naturalHeightRef.current = height; + naturalHeight.set(height); + animatedHeight.set(height); + onNaturalHeightChange?.(height); + return; + } + + // First measurement, or content changed while keyboard is fully open + // (to skip onLayout calls triggered by our own height animation collapsing the view to 0) + if (naturalHeightRef.current === -1 || (animatedHeight.get() >= naturalHeightRef.current && height !== naturalHeightRef.current)) { + naturalHeightRef.current = height; + naturalHeight.set(height); + animatedHeight.set(height); + onNaturalHeightChange?.(height); + } + }; + + // Restores the header when the screen goes from landscape to portrait mode. + useEffect(() => { + const naturalHeightValue = naturalHeight.get(); + if (!isInLandscapeMode && isFocused && naturalHeightValue !== -1) { + animatedHeight.set(withTiming(naturalHeightValue, {duration: RESTORE_DURATION})); + } + // eslint-disable-next-line react-hooks/exhaustive-deps -- we only want to run this effect when the screen orientation changes + }, [isInLandscapeMode]); + + // Restores the header when the screen loses focus + useEffect(() => { + if (!prevIsFocused || isFocused) { + return; + } + + const naturalHeightValue = naturalHeight.get(); + if (naturalHeightValue === -1) { + return; + } + animatedHeight.set(withTiming(naturalHeightValue, {duration: RESTORE_DURATION})); + // eslint-disable-next-line react-hooks/exhaustive-deps -- we only want to run this effect when the screen loses focus + }, [isFocused]); + + // Outer wrapper controls layout space (height collapses to 0, clips overflowing content). + const outerStyle = useAnimatedStyle(() => { + // When fully open, leave height undefined so the view sizes itself naturally. + // This avoids fighting the layout engine during orientation changes. + if (animatedHeight.get() >= naturalHeight.get()) { + return {overflow: 'hidden', height: 'auto'}; + } + return {height: animatedHeight.get(), overflow: 'hidden'}; + }); + + // Inner wrapper slides the content upward during landscape keyboard collapse only. + const innerStyle = useAnimatedStyle(() => { + if (animatedHeight.get() >= naturalHeight.get()) { + return {transform: [{translateY: 0}]}; + } + + if (!isInLandscapeModeSV.get()) { + return {transform: [{translateY: 0}]}; + } + + return {transform: [{translateY: animatedHeight.get() - naturalHeight.get()}]}; + }); + + return {naturalHeight, animatedHeight, isFocusedSV, isInLandscapeModeSV, onLayout, outerStyle, innerStyle}; +} + +export default useCollapsibleHeader; +export {collapseHeaderTo, restoreHeaderTo}; +export type {CollapsibleHeader}; diff --git a/src/components/CollapsibleHeaderOnKeyboard/useCollapsibleScreenState.ts b/src/components/CollapsibleHeaderOnKeyboard/useCollapsibleScreenState.ts new file mode 100644 index 000000000000..be04faa4100c --- /dev/null +++ b/src/components/CollapsibleHeaderOnKeyboard/useCollapsibleScreenState.ts @@ -0,0 +1,36 @@ +import useWindowDimensions from '@hooks/useWindowDimensions'; + +import isInLandscapeModeUtil from '@libs/isInLandscapeMode'; + +import type {SharedValue} from 'react-native-reanimated'; + +import {useIsFocused} from '@react-navigation/native'; +import {useEffect} from 'react'; +import {useSharedValue} from 'react-native-reanimated'; + +type CollapsibleScreenState = { + isFocused: boolean; + isInLandscapeMode: boolean; + isFocusedSV: SharedValue; + isInLandscapeModeSV: SharedValue; +}; + +function useCollapsibleScreenState(): CollapsibleScreenState { + const isFocused = useIsFocused(); + + const {windowWidth, windowHeight} = useWindowDimensions(); + const isInLandscapeMode = isInLandscapeModeUtil(windowWidth, windowHeight); + + const isFocusedSV = useSharedValue(isFocused); + const isInLandscapeModeSV = useSharedValue(isInLandscapeMode); + useEffect(() => { + isFocusedSV.set(isFocused); + }, [isFocused, isFocusedSV]); + useEffect(() => { + isInLandscapeModeSV.set(isInLandscapeMode); + }, [isInLandscapeMode, isInLandscapeModeSV]); + + return {isFocused, isInLandscapeMode, isFocusedSV, isInLandscapeModeSV}; +} + +export default useCollapsibleScreenState; diff --git a/src/components/CollapsibleHeaderOnKeyboard/useKeyboardCollapseMetrics.ts b/src/components/CollapsibleHeaderOnKeyboard/useKeyboardCollapseMetrics.ts new file mode 100644 index 000000000000..79c2934d21d7 --- /dev/null +++ b/src/components/CollapsibleHeaderOnKeyboard/useKeyboardCollapseMetrics.ts @@ -0,0 +1,43 @@ +import useSafeAreaInsets from '@hooks/useSafeAreaInsets'; +import useWindowDimensions from '@hooks/useWindowDimensions'; + +import type {SharedValue} from 'react-native-reanimated'; + +import {useEffect} from 'react'; +import {useReanimatedKeyboardAnimation} from 'react-native-keyboard-controller'; +import {useSharedValue} from 'react-native-reanimated'; + +type KeyboardCollapseMetrics = { + /** Keyboard offset from the bottom of the window. Negative while the keyboard is open. */ + keyboardHeightSV: SharedValue; + + /** Keyboard animation progress, 0 when closed and 1 when fully open. */ + keyboardProgressSV: SharedValue; + + /** Window height minus the top safe area inset, i.e. the height the content is laid out in. */ + availableWindowHeightSV: SharedValue; + + /** UI-thread mirror of the caller's `collapsibleHeaderOffset` prop. */ + collapsibleHeaderOffsetSV: SharedValue; +}; + +function useKeyboardCollapseMetrics(collapsibleHeaderOffset: number): KeyboardCollapseMetrics { + const {height: keyboardHeightSV, progress: keyboardProgressSV} = useReanimatedKeyboardAnimation(); + + const {windowHeight} = useWindowDimensions(); + const {top: topSafeAreaInset} = useSafeAreaInsets(); + const availableWindowHeight = windowHeight - topSafeAreaInset; + + const availableWindowHeightSV = useSharedValue(availableWindowHeight); + const collapsibleHeaderOffsetSV = useSharedValue(collapsibleHeaderOffset); + useEffect(() => { + availableWindowHeightSV.set(availableWindowHeight); + }, [availableWindowHeight, availableWindowHeightSV]); + useEffect(() => { + collapsibleHeaderOffsetSV.set(collapsibleHeaderOffset); + }, [collapsibleHeaderOffset, collapsibleHeaderOffsetSV]); + + return {keyboardHeightSV, keyboardProgressSV, availableWindowHeightSV, collapsibleHeaderOffsetSV}; +} + +export default useKeyboardCollapseMetrics; diff --git a/src/components/MoneyRequestConfirmationList/ConfirmationListLayout.tsx b/src/components/MoneyRequestConfirmationList/ConfirmationListLayout.tsx index 6cd1fded52f8..c6f061d5c1ef 100644 --- a/src/components/MoneyRequestConfirmationList/ConfirmationListLayout.tsx +++ b/src/components/MoneyRequestConfirmationList/ConfirmationListLayout.tsx @@ -5,6 +5,7 @@ import SelectionListWithSections from '@components/SelectionList/SelectionListWi import type {Section, SelectionListWithSectionsHandle} from '@components/SelectionList/SelectionListWithSections/types'; import {MouseProvider} from '@hooks/useMouseContext'; +import useShouldFooterBeInsideList from '@hooks/useShouldFooterBeInsideList'; import useThemeStyles from '@hooks/useThemeStyles'; import type {ReactNode, RefObject} from 'react'; @@ -82,6 +83,7 @@ function ConfirmationListLayout({ footerContentProps, }: ConfirmationListLayoutProps) { const styles = useThemeStyles(); + const shouldFooterBeInsideList = useShouldFooterBeInsideList(); // The list drops its bottom safe-area padding only when there is no footer, so the read-only case must pass // `undefined` rather than a footer that renders nothing. @@ -116,6 +118,7 @@ function ConfirmationListLayout({ shouldPreventDefaultFocusOnSelectRow shouldShowListEmptyContent={false} footerContent={footerContent} + shouldFooterBeInsideList={shouldFooterBeInsideList} listFooterContent={fieldsContent} style={selectionListStyle} keyboardShouldPersistTaps="handled" diff --git a/src/components/Search/SearchPageHeader/SearchPageHeaderNarrow.tsx b/src/components/Search/SearchPageHeader/SearchPageHeaderNarrow.tsx index 50204db4e5ae..f70e24860246 100644 --- a/src/components/Search/SearchPageHeader/SearchPageHeaderNarrow.tsx +++ b/src/components/Search/SearchPageHeader/SearchPageHeaderNarrow.tsx @@ -1,3 +1,4 @@ +import CollapsibleHeaderOnKeyboardGroupMember from '@components/CollapsibleHeaderOnKeyboard/GroupMember'; import TopBar from '@components/Navigation/TopBar'; import type {SearchQueryJSON} from '@components/Search/types'; @@ -23,11 +24,13 @@ function SearchPageHeaderNarrow({queryJSON, shouldShowLoadingBar = false, isMobi // The narrow header is the top-level page title, so it stays a static "Spend". The tab selector rendered directly // below it already names the current view, and repeating that name here would show the same label twice. return ( - + + + ); } diff --git a/src/pages/Search/SearchPageNarrow/index.tsx b/src/pages/Search/SearchPageNarrow/index.tsx index 5d12dda25a3d..3092bb405f2a 100644 --- a/src/pages/Search/SearchPageNarrow/index.tsx +++ b/src/pages/Search/SearchPageNarrow/index.tsx @@ -1,4 +1,6 @@ import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; +import CollapsibleHeaderOnKeyboardGroup from '@components/CollapsibleHeaderOnKeyboard/Group'; +import CollapsibleHeaderOnKeyboardGroupMember from '@components/CollapsibleHeaderOnKeyboard/GroupMember'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import NAVIGATION_TABS from '@components/Navigation/NavigationTabBar/NAVIGATION_TABS'; import TabBarBottomContent from '@components/Navigation/TabBarBottomContent'; @@ -272,44 +274,48 @@ function SearchPageNarrow({ {!isMobileSelectionModeEnabled ? ( - - - - - - - - - topBarOffset.set(StyleUtils.searchHeaderDefaultOffset)} - /> - + + + + + + + + + + + topBarOffset.set(StyleUtils.searchHeaderDefaultOffset)} + /> + + + - - - - - + + + + ) : ( <> diff --git a/src/pages/iou/request/IOURequestStartPage.tsx b/src/pages/iou/request/IOURequestStartPage.tsx index 20f0b613d8f9..8799dfbf82e5 100644 --- a/src/pages/iou/request/IOURequestStartPage.tsx +++ b/src/pages/iou/request/IOURequestStartPage.tsx @@ -1,4 +1,6 @@ import ActivityIndicator from '@components/ActivityIndicator'; +import CollapsibleHeaderOnKeyboardGroup from '@components/CollapsibleHeaderOnKeyboard/Group'; +import CollapsibleHeaderOnKeyboardGroupMember from '@components/CollapsibleHeaderOnKeyboard/GroupMember'; import DragAndDropProvider from '@components/DragAndDrop/Provider'; import FocusTrapContainerElement from '@components/FocusTrap/FocusTrapContainerElement'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; @@ -6,6 +8,7 @@ import ParticipantPickerOverlayHost from '@components/ParticipantPicker/OverlayH import type {AnimatedTextInputRef} from '@components/RNTextInput'; import ScreenWrapper from '@components/ScreenWrapper'; import TabSelector from '@components/TabSelector/TabSelector'; +import type {TabSelectorProps} from '@components/TabSelector/types'; import useAndroidBackButtonHandler from '@hooks/useAndroidBackButtonHandler'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; @@ -58,6 +61,14 @@ type IOURequestStartPageProps = WithWritableReportOrNotFoundProps + + + ); +} + function IOURequestStartPage({ route, route: { @@ -290,105 +301,109 @@ function IOURequestStartPage({ bar, instead of stopping at the top of the form it is declared in. */} - - - - - - {shouldUseTab ? ( - - {() => {manualContent}} - - {() => ( - - - - )} - - {iouType === CONST.IOU.TYPE.SPLIT && ( - + + + + + + + + + {shouldUseTab ? ( + + {() => {manualContent}} + {() => ( - )} - )} - {!!shouldShowPerDiemOption && ( - - {() => ( - - {shouldShowWorkspaceSelectForPerDiem ? ( - - ) : ( - - )} - - )} - - )} - {shouldShowTimeOption && ( - - {() => ( - - {isFromGlobalCreate && iouRequestStartPolicies?.hasMultipleTimePolicies ? ( - - ) : ( - + {() => ( + + - )} - - )} - - )} - - ) : ( - - {manualContent} - - )} - + + )} + + )} + {!!shouldShowPerDiemOption && ( + + {() => ( + + {shouldShowWorkspaceSelectForPerDiem ? ( + + ) : ( + + )} + + )} + + )} + {shouldShowTimeOption && ( + + {() => ( + + {isFromGlobalCreate && iouRequestStartPolicies?.hasMultipleTimePolicies ? ( + + ) : ( + + )} + + )} + + )} + + ) : ( + + {manualContent} + + )} + + diff --git a/src/pages/settings/Wallet/BankAccountPurposePage/index.tsx b/src/pages/settings/Wallet/BankAccountPurposePage/index.tsx index 378c31d389e7..e7a9e1d369dd 100644 --- a/src/pages/settings/Wallet/BankAccountPurposePage/index.tsx +++ b/src/pages/settings/Wallet/BankAccountPurposePage/index.tsx @@ -1,3 +1,5 @@ +import CollapsibleHeaderOnKeyboardGroup from '@components/CollapsibleHeaderOnKeyboard/Group'; +import CollapsibleHeaderOnKeyboardGroupMember from '@components/CollapsibleHeaderOnKeyboard/GroupMember'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; @@ -32,12 +34,16 @@ function BankAccountPurposePage() { shouldShowOfflineIndicator={false} testID={BankAccountPurposePage.displayName} > - - {showCountrySelection ? : } + + + + + {showCountrySelection ? : } + ); } diff --git a/src/pages/settings/Wallet/CollectDepositAccount/index.tsx b/src/pages/settings/Wallet/CollectDepositAccount/index.tsx index cf5e36fa62eb..7584ba52f012 100644 --- a/src/pages/settings/Wallet/CollectDepositAccount/index.tsx +++ b/src/pages/settings/Wallet/CollectDepositAccount/index.tsx @@ -1,4 +1,6 @@ import ActivityIndicator from '@components/ActivityIndicator'; +import CollapsibleHeaderOnKeyboardGroup from '@components/CollapsibleHeaderOnKeyboard/Group'; +import CollapsibleHeaderOnKeyboardGroupMember from '@components/CollapsibleHeaderOnKeyboard/GroupMember'; import HeaderWithBackButtonAndTitle from '@components/Header/composed/HeaderWithBackButtonAndTitle'; import ScreenWrapper from '@components/ScreenWrapper'; @@ -112,24 +114,28 @@ function CollectDepositAccount() { shouldEnableMaxHeight testID="CollectDepositAccount" > - - {isRedirecting || shouldReturnToCountryStep || (isLoadingCountries && pageIndex !== STEP_INDEXES.COUNTRY_SELECTOR) ? ( - - - - ) : ( - - )} + + + + + {isRedirecting || shouldReturnToCountryStep || (isLoadingCountries && pageIndex !== STEP_INDEXES.COUNTRY_SELECTOR) ? ( + + + + ) : ( + + )} + ); } diff --git a/src/pages/settings/Wallet/CountrySelectionList.tsx b/src/pages/settings/Wallet/CountrySelectionList.tsx index 91d91350a199..d0c8ee3b1503 100644 --- a/src/pages/settings/Wallet/CountrySelectionList.tsx +++ b/src/pages/settings/Wallet/CountrySelectionList.tsx @@ -1,4 +1,5 @@ import FullPageOfflineBlockingView from '@components/BlockingViews/FullPageOfflineBlockingView'; +import CollapsibleHeaderOnKeyboardGroupMember from '@components/CollapsibleHeaderOnKeyboard/GroupMember'; import SelectionList from '@components/SelectionList'; import SingleSelectListItem from '@components/SelectionList/ListItem/SingleSelectListItem'; @@ -6,6 +7,7 @@ import useDebouncedState from '@hooks/useDebouncedState'; import useInitialSelection from '@hooks/useInitialSelection'; import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; +import useShouldFooterBeInsideList from '@hooks/useShouldFooterBeInsideList'; import useThemeStyles from '@hooks/useThemeStyles'; import searchOptions from '@libs/searchOptions'; @@ -45,6 +47,8 @@ function CountrySelectionList({isEditing, selectedCountry, countries, onCountryS const initialSelectedValue = useInitialSelection(selectedCountry ?? undefined, {resetOnFocus: true}); const initialSelectedValues = initialSelectedValue ? [initialSelectedValue] : []; + const shouldFooterBeInsideList = useShouldFooterBeInsideList(); + const onSelectionChange = (country: Option) => { onCountrySelected(country.value); }; @@ -80,9 +84,11 @@ function CountrySelectionList({isEditing, selectedCountry, countries, onCountryS return ( - - {translate('addPersonalBankAccount.countrySelectionStepHeader')} - + + + {translate('addPersonalBankAccount.countrySelectionStepHeader')} + + diff --git a/src/pages/settings/Wallet/InternationalDepositAccount/InternationalDepositAccountContent.tsx b/src/pages/settings/Wallet/InternationalDepositAccount/InternationalDepositAccountContent.tsx index 348694401463..2b4485eb2159 100644 --- a/src/pages/settings/Wallet/InternationalDepositAccount/InternationalDepositAccountContent.tsx +++ b/src/pages/settings/Wallet/InternationalDepositAccount/InternationalDepositAccountContent.tsx @@ -1,3 +1,5 @@ +import CollapsibleHeaderOnKeyboardGroup from '@components/CollapsibleHeaderOnKeyboard/Group'; +import CollapsibleHeaderOnKeyboardGroupMember from '@components/CollapsibleHeaderOnKeyboard/GroupMember'; import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; @@ -174,12 +176,14 @@ function InternationalDepositAccountContent({ {isRedirecting || isAccountLoading ? ( ) : ( - <> - + + + + - + )} ); diff --git a/src/pages/settings/Wallet/InternationalDepositAccount/subPages/AccountHolderInformation.tsx b/src/pages/settings/Wallet/InternationalDepositAccount/subPages/AccountHolderInformation.tsx index 2b4323f18a2f..b9e00704debf 100644 --- a/src/pages/settings/Wallet/InternationalDepositAccount/subPages/AccountHolderInformation.tsx +++ b/src/pages/settings/Wallet/InternationalDepositAccount/subPages/AccountHolderInformation.tsx @@ -1,4 +1,5 @@ import AddressSearch from '@components/AddressSearch'; +import CollapsibleHeaderOnKeyboardGroupMember from '@components/CollapsibleHeaderOnKeyboard/GroupMember'; import FormProvider from '@components/Form/FormProvider'; import InputWrapper from '@components/Form/InputWrapper'; import type {FormInputErrors, FormOnyxValues} from '@components/Form/types'; @@ -94,7 +95,9 @@ function AccountHolderInformation({isEditing, onNext, formValues, fieldsMap}: Cu enabledWhenOffline > - {translate('addPersonalBankAccount.accountHolderInformationStepHeader')} + + {translate('addPersonalBankAccount.accountHolderInformationStepHeader')} + {Object.values(fieldsMap[CONST.CORPAY_FIELDS.PAGE_NAME.ACCOUNT_HOLDER_DETAILS] ?? {}) .sort((a, b) => CONST.CORPAY_FIELDS.ACCOUNT_HOLDER_FIELDS.indexOf(a.id) - CONST.CORPAY_FIELDS.ACCOUNT_HOLDER_FIELDS.indexOf(b.id)) .map((field, index) => { diff --git a/src/pages/settings/Wallet/InternationalDepositAccount/subPages/AccountType.tsx b/src/pages/settings/Wallet/InternationalDepositAccount/subPages/AccountType.tsx index 4bdd471b5518..3e5431d75cb4 100644 --- a/src/pages/settings/Wallet/InternationalDepositAccount/subPages/AccountType.tsx +++ b/src/pages/settings/Wallet/InternationalDepositAccount/subPages/AccountType.tsx @@ -1,3 +1,4 @@ +import CollapsibleHeaderOnKeyboardGroupMember from '@components/CollapsibleHeaderOnKeyboard/GroupMember'; import FormProvider from '@components/Form/FormProvider'; import InputWrapper from '@components/Form/InputWrapper'; import type {FormInputErrors, FormOnyxValues, FormRef} from '@components/Form/types'; @@ -64,9 +65,11 @@ function AccountType({isEditing, onNext, fieldsMap}: CustomSubPageProps) { ref={formRef} isSubmitButtonVisible={!isEditing} > - - {translate('addPersonalBankAccount.accountTypeStepHeader')} - + + + {translate('addPersonalBankAccount.accountTypeStepHeader')} + + - {translate('addPersonalBankAccount.accountDetailsStepHeader')} + + {translate('addPersonalBankAccount.accountDetailsStepHeader')} + - {translate('addPersonalBankAccount.bankInformationStepHeader')} + + {translate('addPersonalBankAccount.bankInformationStepHeader')} + {Object.values(fieldsMap[CONST.CORPAY_FIELDS.PAGE_NAME.BANK_INFORMATION] ?? {}) .sort((a, b) => CONST.CORPAY_FIELDS.BANK_INFORMATION_FIELDS.indexOf(a.id) - CONST.CORPAY_FIELDS.BANK_INFORMATION_FIELDS.indexOf(b.id)) .map((field, index) => { diff --git a/src/pages/settings/Wallet/InternationalDepositAccount/subPages/Confirmation.tsx b/src/pages/settings/Wallet/InternationalDepositAccount/subPages/Confirmation.tsx index fcb1abea6420..47deed59b454 100644 --- a/src/pages/settings/Wallet/InternationalDepositAccount/subPages/Confirmation.tsx +++ b/src/pages/settings/Wallet/InternationalDepositAccount/subPages/Confirmation.tsx @@ -1,4 +1,5 @@ import CheckboxWithLabel from '@components/CheckboxWithLabel'; +import CollapsibleHeaderOnKeyboardGroupMember from '@components/CollapsibleHeaderOnKeyboard/GroupMember'; import FormProvider from '@components/Form/FormProvider'; import InputWrapper from '@components/Form/InputWrapper'; import type {FormInputErrors, FormOnyxValues} from '@components/Form/types'; @@ -174,8 +175,10 @@ function Confirmation({onNext, onMove, formValues, fieldsMap}: CustomSubPageProp return ( - {translate('addPersonalBankAccount.confirmationStepHeader')} - {translate('addPersonalBankAccount.confirmationStepSubHeader')} + + {translate('addPersonalBankAccount.confirmationStepHeader')} + {translate('addPersonalBankAccount.confirmationStepSubHeader')} + {summaryItems.map(({id, description, title, interactive, disabled, onPress}) => ( - - - {translate('workspace.moreFeatures.companyCards.setFeedNameDescription')} - + + + + {translate('workspace.moreFeatures.companyCards.setFeedNameDescription')} + + - { - setAssignCardStepAndData({isEditing: false}); - Navigation.goBack(); - }} - /> - {translate('workspace.moreFeatures.companyCards.giveItNameInstruction')} + + { + setAssignCardStepAndData({isEditing: false}); + Navigation.goBack(); + }} + /> + {translate('workspace.moreFeatures.companyCards.giveItNameInstruction')} + ); + const footer = ( + + {!!inlineError && ( + + )} + + + ); + const isHomeAndOfficeSelected = selectedKey === CONST.POLICY.COMMUTER_EXCLUSION_METHOD.HOME_AND_OFFICE; const workArrangementFooter = ( @@ -264,10 +285,12 @@ function PolicyCommuterExclusionsPage({route}: PolicyCommuterExclusionsPageProps testID="PolicyCommuterExclusionsPage" shouldEnableMaxHeight > - + + + - - {!!inlineError && ( - - )} - - + {!shouldFooterBeInsideList && footer} ); diff --git a/tests/ui/ApproverSelectionListTest.tsx b/tests/ui/ApproverSelectionListTest.tsx index da8f60fc7595..00157079cfd1 100644 --- a/tests/ui/ApproverSelectionListTest.tsx +++ b/tests/ui/ApproverSelectionListTest.tsx @@ -20,6 +20,7 @@ jest.mock('@react-navigation/native', () => { return { ...actualNavigation, + useIsFocused: jest.fn(() => mockIsFocused), useFocusEffect: jest.fn((callback: () => void) => { ReactMock.useEffect(() => { if (!mockIsFocused) { diff --git a/tests/ui/CountrySelectionListTest.tsx b/tests/ui/CountrySelectionListTest.tsx index 9c362eb2c9c1..4a3b6977ddc3 100644 --- a/tests/ui/CountrySelectionListTest.tsx +++ b/tests/ui/CountrySelectionListTest.tsx @@ -25,6 +25,7 @@ jest.mock('@react-navigation/native', () => { return { ...actualNavigation, + useIsFocused: jest.fn(() => true), useFocusEffect: jest.fn((callback: () => void) => { mockFocusEffectCallbacks.push(callback); }),