Skip to content

[$175] Describe Rule obscured after dismissing keyboard using Android navigation bar #106343

Open

Description

@applause-bot

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: v9.5.34-0
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #105662
Email or phone of affected tester (no customers): setowskiw+70@gmail.com
Issue reported by: Applause Internal Team
Bug source: Pull Request QA execution
Device used: Samsung Galaxy S21 FE/Android 16
App Component: Other

Action Performed:

  1. Launch Expensify app
  2. Navigate to a Control workspace
  3. Select Rules and tap Add rule
  4. Tap the Describe field under Or just describe it below
  5. Dismiss the keyboard using the downward chevron in the Android navigation bar
  6. Tap the Describe field again

Expected Result:

The page scrolls to position the entire Describe field and Next button above the keyboard

Actual Result:

The page doesn't scroll properly when the keyboard is reopened. The Describe field is partially obscured by the keyboard, and the Next button isn't visible.

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome Safari

Screenshots/Videos

Bug7308245_1794135533128.Recording_2026-11-08_115112.mp4

View all open jobs on GitHub

Applause Internal Information
Exported by: Julia Ponikarchuk
Bug ID: 7308245

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @deetergp

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Nov 9, 2026
  2. applause-bot commented on Nov 9, 2026

    @applause-bot
    Author

    While Applause doesn't embed attachments for this bug, here are the links for quick view:
    https://platform.applause.com/services/links/v1/external/e2af6c73e0e6acde6fe09e7b549f97c319eb74b645a2effdcc5a621af6008442

  3. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Nov 9, 2026
  4. melvin-bot commented on Nov 9, 2026

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @dmkt9 (External)

  5. changed the title [-]Describe Rule obscured after dismissing keyboard using Android navigation bar[/-] [+][$175] Describe Rule obscured after dismissing keyboard using Android navigation bar[/+] on Nov 9, 2026
  6. melvin-bot commented on Nov 9, 2026

    @melvin-bot
  7. MelvinBot commented on Nov 9, 2026

    @MelvinBot
    Contributor

    🤖 Web test steps verification results: ⚠️ partial

    Verified signed-in dev NewDot web. Describe-field checks were blocked by the Control-plan upgrade gate; no upgrade was approved and no rule was submitted. Android-specific behavior remains unverified.

    Web Control-plan upgrade gate

    Step Status
    Launch signed-in AppHome, Workspaces, and Account navigation were visible.
    ✅
    Navigate to Control workspaceSelecting Control opened a paid Upgrade confirmation; testing stopped without approving it.
    Web Control-plan upgrade gate
    ⚠️
    Open Rules > Add ruleBlocked by the Control-plan prerequisite.
    ⚠️
    Focus Describe and inspect field/Next visibilityAdd rule was not reached.
    ⚠️
    Dismiss keyboard using Android navigation-bar chevronThis native Android control is unavailable on web.
    ⚠️
    Refocus Describe and inspect visibilityAdd rule was not reached; no visibility conclusion was established.
    ⚠️

    Proposal

    What is the root cause of that problem?

    Likely cause — medium confidence: The Describe field scrolls into view on input focus, not when the keyboard reopens. Android can hide the keyboard without clearing input focus. If that happens here, tapping the already-focused field reopens the keyboard without repeating the corrective scroll, leaving the field and Next obscured.

    Code evidence

    These references match the reported release. The missing second focus event has not been observed on the affected device.

    What changes do you think we should make in order to solve the problem?

    First verify whether chevron dismissal leaves the input focused and whether the second tap omits onFocus.

    If confirmed, the smallest supported candidate is to reuse the existing Android-specific blur-on-keyboard-hide hook locally in DescribeRuleForm. Keep automatic focus scrolling disabled to preserve the earlier double-scroll fix.

    Validate normal and rapid dismissal/reopening on Android before accepting this candidate as the solution.

    What alternative solutions did you explore? (Optional)

    If the second tap does fire onFocus, retained focus is not the explanation. Investigate whether the delayed scroll runs before keyboard/layout changes finish. Increasing the delay or restoring native scrolling is not justified without that evidence.

    Discovery during QA of Stop the New rule page from scrolling twice on Android does not establish that PR as the cause.

    Potentially related issues: Description bar is not correctly centered after refocusing and New rule page still has a janky keyboard jump. Neither is a confirmed duplicate.


    Next Steps for Contributor+ team:
    Confirm the Android focus-event sequence before accepting this fix.
    To accept: @MelvinBot implement [this](hyperlink) to create a draft PR.
    To refine: @MelvinBot <your feedback>
    To reject: Explain why you are rejecting Melvin's proposal.


    view run

  8. khizzcr7 commented on Nov 9, 2026

    @khizzcr7

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    On Android, in a Control workspace, Rules > Add rule: tap the Describe field, dismiss the keyboard with the downward chevron in the Android navigation bar, then tap the Describe field again. The page does not scroll, so the Describe field stays partly obscured by the reopened keyboard and the Next button is not visible.

    What is the root cause of that problem?

    The only thing that scrolls this form to the input is the focus handler. In src/pages/workspace/rules/DescribeRuleForm.tsx, the input has onFocus={scrollToInput} (line ~365), which calls formRef.current?.scrollTo(inputTopOffsetRef.current) (line ~301), and shouldScrollChildToFocus={false} is set deliberately (line ~320, with the comment that if Android also moves the box, the page moves two times). So nothing else ever scrolls the input into view.

    On Android, dismissing the keyboard with the nav-bar chevron hides the keyboard WITHOUT blurring the TextInput - the input keeps focus. When the keyboard hides, the form's scroll position resets, but re-tapping the field fires no onFocus event (focus never left), so scrollToInput never re-runs and the field stays under the reopened keyboard.

    What changes do you think we should make in order to solve the problem?

    Re-run the scroll when the keyboard reappears while the input is already focused: in DescribeRuleForm, subscribe to keyboardDidShow and, if inputRef.current?.isFocused(), call scrollToInput() (which scrolls to the already-measured inputTopOffsetRef.current, set in the input container's onLayout). This leaves the first-focus path untouched, so there is no double-scroll on first focus, and iOS behavior is unchanged.

    What alternative solutions did you explore? (Optional)

    Blurring the input when the keyboard hides, so a fresh focus event fires on re-tap. I prefer the keyboardDidShow route: it does not fight the focus state the user expects (the cursor stays in the field) and it cannot introduce a blur/focus flicker on other screens that reuse this form.

    What tests will you run to verify the fix works?

    1. Reproduce on Android (Samsung Galaxy S21 FE / Android 16, as reported): open Add rule, tap Describe, dismiss the keyboard with the nav-bar chevron, re-tap Describe - the field and the Next button must both sit fully above the keyboard.
    2. First-focus regression: fresh open, tap Describe once - the form must scroll exactly once (no double jump; see the two-jump precedent in [Due for payment 2026-11-16] [$175] Android - Rules - New rule scrolls in two jumps when the describe box gets focus #105661).
    3. iOS spot-check: first focus and keyboard dismiss/reopen on the same screen must behave exactly as before.
  9. Enes2553 commented on Nov 9, 2026

    @Enes2553

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    On Android, in a Control workspace, navigating to Rules > Add rule, tapping the Describe field under "Or just describe it below", dismissing the software keyboard using the downward chevron in the Android navigation bar, and then tapping the Describe field again causes the keyboard to reopen without scrolling the field into view. The Describe field remains partially obscured and the Next button is hidden beneath the keyboard.

    What is the root cause of that problem?

    In PR #105662 (Stop the New rule page from scrolling twice on Android), shouldScrollChildToFocus={false} was introduced on FormProvider in src/pages/workspace/rules/DescribeRuleForm.tsx (line 320) to prevent Android's native scrollsChildToFocus from producing a jarring double-scroll jump on first focus, delegating the corrective scroll exclusively to onFocus={scrollToInput} (line 365).

    However, on Android, dismissing the software keyboard via the downward navigation-bar chevron or system back gesture dismisses the keyboard window without clearing focus on the native EditText (as documented in src/hooks/useBlurOnKeyboardHide/index.android.ts). Because JS never receives an onBlur event, the input retains focus in the component tree. When the user taps the Describe field a second time to bring back the keyboard, React Native does not fire a new onFocus event because focus never left. Consequently, scrollToInput is never called, and because shouldScrollChildToFocus is false, no scrolling occurs—leaving the input and Next button obscured beneath the keyboard.

    What changes do you think we should make in order to solve the problem?

    Utilize Expensify's canonical Android hook useBlurOnKeyboardHide inside src/pages/workspace/rules/DescribeRuleForm.tsx:

    1. Import useBlurOnKeyboardHide from @hooks/useBlurOnKeyboardHide:
    --- a/src/pages/workspace/rules/DescribeRuleForm.tsx
    +++ b/src/pages/workspace/rules/DescribeRuleForm.tsx
    @@ -12,6 +12,7 @@ import useLocalize from '@hooks/useLocalize';
     import useNetwork from '@hooks/useNetwork';
     import useOnyx from '@hooks/useOnyx';
     import useThemeStyles from '@hooks/useThemeStyles';
    +import useBlurOnKeyboardHide from '@hooks/useBlurOnKeyboardHide';
    1. Pass inputRef to useBlurOnKeyboardHide inside DescribeRuleForm:
    --- a/src/pages/workspace/rules/DescribeRuleForm.tsx
    +++ b/src/pages/workspace/rules/DescribeRuleForm.tsx
    @@ -154,6 +155,8 @@ function DescribeRuleForm({
         const formRef = useRef<FormRef>(null);
         const inputRef = useRef<AnimatedTextInputRef>(null);
         const inputTopOffsetRef = useRef(0);
    +
    +    useBlurOnKeyboardHide(inputRef);

    Why this is the optimal and clean fix:

    • useBlurOnKeyboardHide was architected specifically for this Android behavior in src/hooks/useBlurOnKeyboardHide/index.android.ts. It already handles device rotation delays, window width changes, and AppState background transitions cleanly.
    • When the keyboard hides via the Android navigation bar chevron, useBlurOnKeyboardHide explicitly blurs inputRef.
    • When the user taps the Describe field again, a standard onFocus event fires and invokes scrollToInput(), smoothly scrolling the Describe field and the Next button above the keyboard.
    • It is a clean no-op on non-Android platforms (src/hooks/useBlurOnKeyboardHide/index.ts).

    What alternative solutions did you explore? (Optional)

    • Adding a keyboardDidShow event listener: Subscribing to keyboardDidShow inside DescribeRuleForm fires on every keyboard appearance, including initial mount/focus. This creates duplicate scroll invocations that fight the initial onFocus={scrollToInput} and risks re-introducing the double-scroll jump that PR Stop the New rule page from scrolling twice on Android #105662 specifically eliminated. Furthermore, leaving the input focused while the keyboard is dismissed causes inconsistent cursor/selection behavior on Android.
    • Re-enabling shouldScrollChildToFocus={true}: Reverts PR Stop the New rule page from scrolling twice on Android #105662 and re-introduces the double-jump on first focus.

    What automated tests can you add to prevent this from re-occurring?

    In tests/unit/pages/workspace/rules/DescribeRuleFormTest.tsx:

    • Add a test verifying that useBlurOnKeyboardHide is called with inputRef.

    Contributor details
    Your Expensify account email: enesbilalolgun0@gmail.com
    Upwork Profile Link: https://www.upwork.com/freelancers/~010415b62c29eb990f

  10. melvin-bot commented on Nov 9, 2026

    @melvin-bot

    ⚠️ Invalid email. Please make sure to create an Expensify account with this email first here.

  11. Enes2553 commented on Nov 9, 2026

    @Enes2553

    Contributor details
    Your Expensify account email: enesbilalolgun0@gmail.com
    Upwork Profile Link: https://www.upwork.com/freelancers/~010415b62c29eb990f

  12. melvin-bot commented on Nov 9, 2026

    @melvin-bot

    ✅ Contributor details stored successfully. Thank you for contributing to Expensify!

  13. 10 remaining items

  14. dmkt9 commented on Nov 13, 2026

    @dmkt9
    Contributor

    @MelvinBot create a patch.diff for this #106343 (comment)

  15. MelvinBot commented on Nov 13, 2026

    @MelvinBot
    Contributor

    Created the patch below. File upload was denied, so save the expanded contents as patch.diff.

    • Passed: 38 tests, lint, typecheck, spelling, and per-file React Compiler checks.
    • Not verified: Android keyboard timing. The compiler’s changed-file comparison failed because its base reference resolved to origin/.
    • No PR created.

    Apply from the App repository root: git apply --check patch.diff && git apply patch.diff

    patch.diff — based on commit f966d70
    diff --git a/src/CONST/SENTRY_LABEL.ts b/src/CONST/SENTRY_LABEL.ts
    index 398101f139..62fcff39ed 100644
    --- a/src/CONST/SENTRY_LABEL.ts
    +++ b/src/CONST/SENTRY_LABEL.ts
    @@ -2649,6 +2649,7 @@ const SENTRY_LABEL = {
                 SPEND_RULE_SAVE: 'WorkspaceRules-SpendRuleSave',
                 SPEND_RULE_DESCRIBE: 'WorkspaceRules-SpendRuleDescribe',
                 DESCRIBE_RULE_TRY_SUGGESTION: 'WorkspaceRules-DescribeRuleTrySuggestion',
    +            DESCRIBE_RULE_INPUT: 'WorkspaceRules-DescribeRuleInput',
                 SPEND_RULE_DELETE: 'WorkspaceRules-SpendRuleDelete',
                 SPEND_RULE_RESTRICTION_TYPE: 'WorkspaceRules-SpendRuleRestrictionType',
                 AGENT_RULE_ITEM: 'WorkspaceRules-AgentRuleItem',
    diff --git a/src/hooks/useScrollOnKeyboardReopen/index.android.ts b/src/hooks/useScrollOnKeyboardReopen/index.android.ts
    new file mode 100644
    index 0000000000..e381de4115
    --- /dev/null
    +++ b/src/hooks/useScrollOnKeyboardReopen/index.android.ts
    @@ -0,0 +1,64 @@
    +/** Restore the input's scroll position after Android reopens the keyboard with input focus retained. */
    +import {useIsFocused} from '@react-navigation/native';
    +import {useEffect, useRef} from 'react';
    +import {AppState} from 'react-native';
    +import {KeyboardEvents} from 'react-native-keyboard-controller';
    +
    +import type UseScrollOnKeyboardReopen from './types';
    +
    +const useScrollOnKeyboardReopen: UseScrollOnKeyboardReopen = (ref, scrollToInput, isActive) => {
    +    const isScreenFocused = useIsFocused();
    +    const shouldScrollOnReopen = useRef(false);
    +    const shouldSkipNextHide = useRef(false);
    +
    +    const resetScrollOnReopen = () => {
    +        shouldScrollOnReopen.current = false;
    +    };
    +
    +    useEffect(() => {
    +        if (!isActive || !isScreenFocused) {
    +            resetScrollOnReopen();
    +            return;
    +        }
    +
    +        const canScrollToInput = () => AppState.currentState === 'active' && !!ref.current?.isFocused();
    +        const appStateSubscription = AppState.addEventListener('change', (state) => {
    +            if (state === 'active') {
    +                return;
    +            }
    +            // Android can send the background hide again after the app returns to the foreground.
    +            shouldSkipNextHide.current = true;
    +            resetScrollOnReopen();
    +        });
    +
    +        const hideSubscription = KeyboardEvents.addListener('keyboardDidHide', (event) => {
    +            // A partially completed dismissal can be cancelled without actually closing the keyboard.
    +            if (event.height !== 0) {
    +                return;
    +            }
    +            shouldScrollOnReopen.current = !shouldSkipNextHide.current && canScrollToInput();
    +            shouldSkipNextHide.current = false;
    +        });
    +
    +        const showSubscription = KeyboardEvents.addListener('keyboardDidShow', (event) => {
    +            const shouldScroll = shouldScrollOnReopen.current;
    +            resetScrollOnReopen();
    +            shouldSkipNextHide.current = false;
    +            if (!shouldScroll || event.height <= 0 || !canScrollToInput()) {
    +                return;
    +            }
    +            scrollToInput();
    +        });
    +
    +        return () => {
    +            resetScrollOnReopen();
    +            appStateSubscription.remove();
    +            hideSubscription.remove();
    +            showSubscription.remove();
    +        };
    +    }, [isActive, isScreenFocused, ref, resetScrollOnReopen, scrollToInput]);
    +
    +    return resetScrollOnReopen;
    +};
    +
    +export default useScrollOnKeyboardReopen;
    diff --git a/src/hooks/useScrollOnKeyboardReopen/index.ts b/src/hooks/useScrollOnKeyboardReopen/index.ts
    new file mode 100644
    index 0000000000..ea566a176c
    --- /dev/null
    +++ b/src/hooks/useScrollOnKeyboardReopen/index.ts
    @@ -0,0 +1,8 @@
    +/** Only Android needs a separate scroll when the keyboard reopens without a new input focus event. */
    +import noop from 'lodash/noop';
    +
    +import type UseScrollOnKeyboardReopen from './types';
    +
    +const useScrollOnKeyboardReopen: UseScrollOnKeyboardReopen = () => noop;
    +
    +export default useScrollOnKeyboardReopen;
    diff --git a/src/hooks/useScrollOnKeyboardReopen/types.ts b/src/hooks/useScrollOnKeyboardReopen/types.ts
    new file mode 100644
    index 0000000000..f423cb66e5
    --- /dev/null
    +++ b/src/hooks/useScrollOnKeyboardReopen/types.ts
    @@ -0,0 +1,6 @@
    +import type {RefObject} from 'react';
    +
    +/** Returns a reset callback for the input's focus and blur handlers. */
    +type UseScrollOnKeyboardReopen = (ref: RefObject<{isFocused: () => boolean} | null>, scrollToInput: () => void, isActive: boolean) => () => void;
    +
    +export default UseScrollOnKeyboardReopen;
    diff --git a/src/pages/workspace/rules/DescribeRuleForm.tsx b/src/pages/workspace/rules/DescribeRuleForm.tsx
    index 07dd73856b..5b8ab250ac 100644
    --- a/src/pages/workspace/rules/DescribeRuleForm.tsx
    +++ b/src/pages/workspace/rules/DescribeRuleForm.tsx
    @@ -9,6 +9,7 @@ import TextInput from '@components/TextInput';
     
     import useLocalize from '@hooks/useLocalize';
     import useOnyx from '@hooks/useOnyx';
    +import useScrollOnKeyboardReopen from '@hooks/useScrollOnKeyboardReopen';
     import useThemeStyles from '@hooks/useThemeStyles';
     
     import {getDecodedCategoryName} from '@libs/CategoryUtils';
    @@ -284,6 +285,13 @@ function DescribeRuleForm({
         // On iOS and Android, the keyboard covers the focused input unless the form scrolls to it. The scroll stops at the end of
         // the content, therefore the submit button below the input also stays in view when it fits.
         const scrollToInput = () => formRef.current?.scrollTo(inputTopOffsetRef.current);
    +    const resetScrollOnKeyboardReopen = useScrollOnKeyboardReopen(inputRef, scrollToInput, isActive);
    +
    +    const scrollToFocusedInput = () => {
    +        // A genuine focus event already scrolls, so the corresponding keyboard show must not scroll again.
    +        resetScrollOnKeyboardReopen();
    +        scrollToInput();
    +    };
     
         const describeSuggestedRule = (suggestedPrompt: string) => {
             Log.info('[GenerateRule] Tried the suggested description', false, {policyID, generationID: refusal?.generationID, reason: refusal?.reason});
    @@ -333,7 +341,9 @@ function DescribeRuleForm({
                         accessibilityLabel={inputLabel}
                         role={CONST.ROLE.PRESENTATION}
                         onKeyPress={submitFormOnModEnter}
    -                    onFocus={scrollToInput}
    +                    onFocus={scrollToFocusedInput}
    +                    onBlur={resetScrollOnKeyboardReopen}
    +                    sentryLabel={CONST.SENTRY_LABEL.WORKSPACE.RULES.DESCRIBE_RULE_INPUT}
                         maxLength={CONST.GENERATED_RULE.PROMPT_MAX_LENGTH}
                         multiline
                         shouldSaveDraft
    diff --git a/tests/unit/hooks/useScrollOnKeyboardReopen.test.ts b/tests/unit/hooks/useScrollOnKeyboardReopen.test.ts
    new file mode 100644
    index 0000000000..5545c3d1ae
    --- /dev/null
    +++ b/tests/unit/hooks/useScrollOnKeyboardReopen.test.ts
    @@ -0,0 +1,195 @@
    +import {act, renderHook} from '@testing-library/react-native';
    +
    +import useScrollOnKeyboardReopen from '@hooks/useScrollOnKeyboardReopen/index.android';
    +import useScrollOnKeyboardReopenDefault from '@hooks/useScrollOnKeyboardReopen/index';
    +
    +import type {AppStateStatus} from 'react-native';
    +import type {KeyboardEventData} from 'react-native-keyboard-controller';
    +
    +import {AppState} from 'react-native';
    +
    +const mockKeyboardListeners: Record<string, Set<(event: KeyboardEventData) => void>> = {};
    +let mockIsScreenFocused = true;
    +const mockRemove = jest.fn();
    +const appStateListeners = new Set<(state: AppStateStatus) => void>();
    +const mockAppStateRemove = jest.fn();
    +
    +jest.mock('@react-navigation/native', () => ({useIsFocused: () => mockIsScreenFocused}));
    +jest.mock('react-native-keyboard-controller', () => ({
    +    KeyboardEvents: {
    +        addListener: jest.fn((event: string, listener: (data: KeyboardEventData) => void) => {
    +            (mockKeyboardListeners[event] ??= new Set()).add(listener);
    +            return {
    +                remove: () => {
    +                    mockKeyboardListeners[event].delete(listener);
    +                    mockRemove();
    +                },
    +            };
    +        }),
    +    },
    +}));
    +
    +function emitKeyboardEvent(event: 'keyboardDidShow' | 'keyboardDidHide', height: number) {
    +    const data: KeyboardEventData = {height, duration: 250, timestamp: 0, target: -1, type: 'default', appearance: 'light'};
    +    act(() => {
    +        for (const listener of mockKeyboardListeners[event] ?? []) {
    +            listener(data);
    +        }
    +    });
    +}
    +
    +function setAppState(state: AppStateStatus) {
    +    (AppState as {currentState: AppStateStatus}).currentState = state;
    +    act(() => {
    +        for (const listener of appStateListeners) {
    +            listener(state);
    +        }
    +    });
    +}
    +
    +type Step = 'hide' | 'partialHide' | 'show' | 'zeroShow' | 'blur' | 'focus' | 'background' | 'foreground';
    +
    +describe('useScrollOnKeyboardReopen', () => {
    +    beforeEach(() => {
    +        jest.clearAllMocks();
    +        mockIsScreenFocused = true;
    +        for (const key of Object.keys(mockKeyboardListeners)) {
    +            delete mockKeyboardListeners[key];
    +        }
    +        appStateListeners.clear();
    +        setAppState('active');
    +        jest.spyOn(AppState, 'addEventListener').mockImplementation((_event, listener) => {
    +            appStateListeners.add(listener);
    +            return {
    +                remove: () => {
    +                    appStateListeners.delete(listener);
    +                    mockAppStateRemove();
    +                },
    +            };
    +        });
    +    });
    +
    +    it.each<[string, Step[], number]>([
    +        ['does not add a scroll on first focus', ['focus', 'show'], 0],
    +        ['scrolls when the keyboard reopens with focus retained', ['show', 'hide', 'show'], 1],
    +        ['consumes the flag before a repeated show', ['hide', 'show', 'show'], 1],
    +        ['supports repeated dismiss and reopen cycles', ['hide', 'show', 'hide', 'show'], 2],
    +        ['ignores a cancelled partial dismissal', ['partialHide', 'show'], 0],
    +        ['clears the flag on actual blur', ['hide', 'blur', 'show'], 0],
    +        ['leaves fresh focus scrolling to the focus handler', ['hide', 'blur', 'focus', 'show'], 0],
    +        ['does not arm for an unfocused input', ['blur', 'hide', 'show'], 0],
    +        ['does not scroll for a zero-height show', ['hide', 'zeroShow', 'show'], 0],
    +        ['clears the flag on backgrounding', ['hide', 'background', 'foreground', 'show'], 0],
    +        ['ignores a foreground resynchronization hide', ['background', 'foreground', 'hide', 'show'], 0],
    +        ['does not consume background suppression on a partial hide', ['background', 'foreground', 'partialHide', 'hide', 'show'], 0],
    +        ['supports reopening after returning from the background', ['background', 'foreground', 'show', 'hide', 'show'], 1],
    +    ])('%s', (_name, steps, expectedScrolls) => {
    +        // Given an input whose native focus is preserved unless an actual blur event occurs
    +        let isInputFocused = true;
    +        const ref = {current: {isFocused: () => isInputFocused, blur: jest.fn(), focus: jest.fn()}};
    +        const scrollToInput = jest.fn();
    +        const {result} = renderHook(() => useScrollOnKeyboardReopen(ref, scrollToInput, true));
    +
    +        // When keyboard, focus and app events arrive in the specified order
    +        for (const step of steps) {
    +            if (step === 'focus' || step === 'blur') {
    +                isInputFocused = step === 'focus';
    +                act(() => result.current());
    +            } else if (step === 'background' || step === 'foreground') {
    +                setAppState(step === 'background' ? 'background' : 'active');
    +            } else {
    +                let height = 0;
    +                if (step === 'show') {
    +                    height = 300;
    +                } else if (step === 'partialHide') {
    +                    height = 100;
    +                }
    +                emitKeyboardEvent(step === 'hide' || step === 'partialHide' ? 'keyboardDidHide' : 'keyboardDidShow', height);
    +            }
    +        }
    +
    +        // Then only retained-focus reopenings request an extra scroll, without issuing native focus commands
    +        expect(scrollToInput).toHaveBeenCalledTimes(expectedScrolls);
    +        expect(ref.current.blur).not.toHaveBeenCalled();
    +        expect(ref.current.focus).not.toHaveBeenCalled();
    +    });
    +
    +    it.each(['form', 'route'] as const)('clears a pending scroll when the %s becomes inactive', (target) => {
    +        // Given a dismissed keyboard with input focus retained
    +        const ref = {current: {isFocused: () => true}};
    +        const scrollToInput = jest.fn();
    +        const {rerender} = renderHook(({isActive}) => useScrollOnKeyboardReopen(ref, scrollToInput, isActive), {initialProps: {isActive: true}});
    +        emitKeyboardEvent('keyboardDidHide', 0);
    +
    +        // When this form loses activity or route focus, then becomes active again
    +        mockIsScreenFocused = target !== 'route';
    +        rerender({isActive: target !== 'form'});
    +        mockIsScreenFocused = true;
    +        rerender({isActive: true});
    +        emitKeyboardEvent('keyboardDidShow', 300);
    +
    +        // Then the old dismissal cannot trigger a scroll on the newly active screen
    +        expect(scrollToInput).not.toHaveBeenCalled();
    +    });
    +
    +    it('preserves a pending reopen across an unrelated rerender', () => {
    +        // Given a dismissed keyboard while the input retains focus
    +        const ref = {current: {isFocused: () => true}};
    +        const scrollToInput = jest.fn();
    +        const {rerender} = renderHook(() => useScrollOnKeyboardReopen(ref, scrollToInput, true));
    +        emitKeyboardEvent('keyboardDidHide', 0);
    +
    +        // When the parent rerenders before the keyboard reopens
    +        rerender({});
    +        emitKeyboardEvent('keyboardDidShow', 300);
    +
    +        // Then the pending scroll still runs exactly once
    +        expect(scrollToInput).toHaveBeenCalledTimes(1);
    +    });
    +
    +    it('does not scroll after the input ref is cleared', () => {
    +        // Given a dismissed keyboard with a focused input
    +        const ref: {current: {isFocused: () => boolean} | null} = {current: {isFocused: () => true}};
    +        const scrollToInput = jest.fn();
    +        renderHook(() => useScrollOnKeyboardReopen(ref, scrollToInput, true));
    +        emitKeyboardEvent('keyboardDidHide', 0);
    +
    +        // When the input disappears before the keyboard show notification
    +        ref.current = null;
    +        emitKeyboardEvent('keyboardDidShow', 300);
    +
    +        // Then no scroll targets the removed input
    +        expect(scrollToInput).not.toHaveBeenCalled();
    +    });
    +
    +    it('removes listeners and discards a pending scroll on unmount', () => {
    +        // Given a mounted hook with a pending reopen
    +        const scrollToInput = jest.fn();
    +        const {unmount} = renderHook(() => useScrollOnKeyboardReopen({current: {isFocused: () => true}}, scrollToInput, true));
    +        emitKeyboardEvent('keyboardDidHide', 0);
    +
    +        // When the form unmounts before the keyboard reopens
    +        unmount();
    +        emitKeyboardEvent('keyboardDidShow', 300);
    +
    +        // Then every subscription is removed and no stale scroll runs
    +        expect(mockRemove).toHaveBeenCalledTimes(2);
    +        expect(mockAppStateRemove).toHaveBeenCalledTimes(1);
    +        expect(scrollToInput).not.toHaveBeenCalled();
    +    });
    +
    +    it('leaves other platforms unchanged', () => {
    +        // Given the default platform implementation
    +        const scrollToInput = jest.fn();
    +        const {result} = renderHook(() => useScrollOnKeyboardReopenDefault({current: {isFocused: () => true}}, scrollToInput, true));
    +
    +        // When input focus and keyboard events occur
    +        act(() => result.current());
    +        emitKeyboardEvent('keyboardDidHide', 0);
    +        emitKeyboardEvent('keyboardDidShow', 300);
    +
    +        // Then no keyboard listener or additional scroll is introduced
    +        expect(mockKeyboardListeners).toEqual({});
    +        expect(scrollToInput).not.toHaveBeenCalled();
    +    });
    +});

    view run

  16. dmkt9 commented on Nov 13, 2026

    @dmkt9
    Contributor

    MelvinBot's proposal looks good to me

    🎀 👀 🎀 C+

  17. melvin-bot commented on Nov 13, 2026

    @melvin-bot

    Triggered auto assignment to @deetergp, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

  18. deetergp commented on Nov 16, 2026

    @deetergp
    Contributor

    @dmkt9 Sounds good, run with it!

  19. dmkt9 commented on Nov 17, 2026

    @dmkt9
    Contributor
  20. MelvinBot commented on Nov 17, 2026

    @MelvinBot
    Contributor

    🤖 Web test steps verification results: ⚠️ partial

    The web app remained blank, with the browser session reporting connection_lost. Web behavior could not be verified.
    Blank development web app blocking verification

    Step Status
    Launch signed-in ExpensifyBlocked by a blank screen; signed-in state could not be verified.
    Blank development web app blocking verification
    ⚠️
    Navigate to a Control workspaceBlocked by the blank screen.
    ⚠️
    Open Rules > Add ruleWorkspace navigation was unavailable.
    ⚠️
    Focus Describe; verify field and Next visibilityAdd rule could not be reached.
    ⚠️
    Dismiss keyboard using Android navigation-bar chevronUnavailable on web; native behavior was not tested.
    ⚠️
    Refocus Describe; verify visibility and typingThe Describe field could not be reached.
    ⚠️

    Implemented in Restore Describe Rule scrolling when Android keyboard reopens, created as a draft and assigned to dmkt9.

    Passed: 69 targeted tests, lint, typecheck, spelling, Oxfmt, and Storybook smoke tests. Full Jest and React Compiler verification remain incomplete. Android device validation is still required.


    view run · no recording available

  21. melvin-bot commented on Nov 18, 2026

    @melvin-bot

    📣 @dmkt9 We're missing your Upwork ID to automatically send you an offer for the Reviewer role.
    Once you apply to the Upwork job, your Upwork ID will be stored and you will be automatically hired for future jobs!

  22. deetergp commented on Nov 18, 2026

    @deetergp
    Contributor

    No update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugSomething is broken. Auto assigns a BugZero manager.ExternalAdded to denote the issue can be worked on by a contributorReviewingHas a PR in reviewWeeklyKSv2

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions