Skip to content

Fix Agents - Input field does not auto scroll down when entering next line#94565

Open
GCyganek wants to merge 16 commits into
Expensify:mainfrom
software-mansion-labs:@GCyganek/landscape-mode/agent-prompt-multiline-input
Open

Fix Agents - Input field does not auto scroll down when entering next line#94565
GCyganek wants to merge 16 commits into
Expensify:mainfrom
software-mansion-labs:@GCyganek/landscape-mode/agent-prompt-multiline-input

Conversation

@GCyganek

@GCyganek GCyganek commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

Fixes the Add Agent prompt and Edit Agent prompt multiline input in landscape/mobile landscape when the keyboard is open. Collapses the header via CollapsibleHeaderOnKeyboard, shrinks the prompt to two visible lines, scrolls the form on iOS focus, and adjusts native multiline BaseTextInput flex so the field stays usable above the keyboard.

Fixed Issues

$ #93631
PROPOSAL: N/A

Tests

  1. Go to Account > Agents.
  2. Rotate device to landscape mode.
  3. Tap Write custom instructions.
  4. Enter multiline content.
  5. Verify Input field will auto scroll down when entering next line and is not hidden behind keypad.
  6. Create an agent.
  7. Open the agent.
  8. Tap Write custom instructions.
  9. Enter multiline content.
  10. Verify Input field will auto scroll down when entering next line and is not hidden behind keypad.
  • Verify that no errors appear in the JS console

Offline tests

N/A

QA Steps

Same as tests.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Screen.Recording.2026-07-02.at.12.40.52.mov
Screen.Recording.2026-07-02.at.12.41.29.mov
Android: mWeb Chrome
iOS: Native
Screen.Recording.2026-07-02.at.11.51.00.mov
Screen.Recording.2026-07-02.at.11.51.50.mov
iOS: mWeb Safari
MacOS: Chrome / Safari
Screen.Recording.2026-07-02.at.12.58.40.mov

@melvin-bot

melvin-bot Bot commented Jun 25, 2026

Copy link
Copy Markdown

Hey! I see that you made changes to our Form component. Make sure to update the docs in FORMS.md accordingly. Cheers!

@GCyganek

Copy link
Copy Markdown
Contributor Author

@Expensify/design could you take a look? I changed the behaviour in landscape mode to shrink the prompt input so that ~2 lines are visible with open keyboard and fixed scroll on input focus on iOS as it does not work automatically with multiline text inputs. I feel like it would be better to set max height in landscape mode for the prompt input, but I left it as is as and wanted to first ask you about it here. Currently it grows with the prompt text, but we could add max height and make it scrollable when it hits the height limit (like in portrait or on web)

Screen.Recording.2026-06-25.at.11.53.00.mov
Screen.Recording.2026-06-25.at.12.37.02.mov

@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/components/Form/FormProvider.tsx 61.81% <ø> (ø)
src/components/Form/FormWrapper.tsx 82.60% <100.00%> (+0.25%) ⬆️
src/components/FormAlertWithSubmitButton.tsx 97.14% <100.00%> (+0.47%) ⬆️
src/pages/settings/Agents/AddAgentPage.tsx 87.30% <100.00%> (+1.09%) ⬆️
...rc/pages/settings/Agents/Fields/EditPromptPage.tsx 70.73% <100.00%> (+0.73%) ⬆️
src/pages/settings/Agents/const.ts 100.00% <100.00%> (ø)
...nents/CollapsibleHeaderOnKeyboard/index.native.tsx 61.03% <66.66%> (+0.51%) ⬆️
...es/settings/Agents/scrollToMultilineInput/index.ts 0.00% <0.00%> (ø)
src/pages/settings/Profile/ProfilePage.tsx 95.19% <60.00%> (ø)
...ettings/Agents/scrollToMultilineInput/index.ios.ts 0.00% <0.00%> (ø)
... and 2 more
... and 116 files with indirect coverage changes

@shawnborton

Copy link
Copy Markdown
Contributor

@GCyganek that makes sense to me, I say go for it.

@GCyganek

GCyganek commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

@codex please review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dca8f12b6b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/pages/settings/Agents/Fields/EditPromptPage.tsx
@GCyganek GCyganek marked this pull request as ready for review July 2, 2026 11:09
@GCyganek GCyganek requested review from a team as code owners July 2, 2026 11:09
@melvin-bot melvin-bot Bot requested review from mkhutornyi and removed request for a team July 2, 2026 11:09
@melvin-bot

melvin-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown

@mkhutornyi Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot melvin-bot Bot requested review from heyjennahay and removed request for a team July 2, 2026 11:09
@GCyganek

GCyganek commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

@truph01 could you review as this is landscape mode issue?

@truph01

truph01 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

@truph01 could you review as this is landscape mode issue?

Sure, I will review it

@truph01

truph01 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

@NicolasBonet Could you assign me to this PR based on #94565 (comment)?

Comment thread src/pages/settings/Agents/AddAgentPage.tsx Outdated
Comment thread src/pages/settings/Agents/Fields/EditPromptPage.tsx Outdated
testID={EditPromptPage.displayName}
includeSafeAreaPaddingBottom
offlineIndicatorStyle={styles.mtAuto}
shouldEnableMaxHeight={shouldUseScrollableLayout}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldEnableMaxHeight dropped without an equivalent in EditPromptPage

AddAgentPage.tsx keeps shouldEnableMaxHeight={shouldUseScrollableLayout} on its ScreenWrapper, but this prop was removed entirely here rather than wired to the new isInLandscapeMode value. Was that intentional, or should it mirror AddAgentPage's handling for consistency?

@GCyganek GCyganek Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EditPromptPage is a bit different, as I wanted the input to take the rest of the height in landscape mode, whereas in AddAgentPage in landscape mode the input height is a static value, it was intentional to remove it only in EditPromptPage

) : null}
{hiddenLabel}
<View style={[styles.textInputAndIconContainer, styles.flex1, isMultiline && hasLabel && styles.textInputMultilineContainer, styles.pointerEventsBoxNone]}>
<View style={[styles.textInputAndIconContainer, isMultiline && hasLabel ? styles.textInputMultilineContainer : styles.flex1, styles.pointerEventsBoxNone]}>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shared TextInput style change may affect other multiline+label inputs app-wide

This tweaks BaseTextInput's native implementation (used app-wide), making flex1 mutually exclusive with textInputMultilineContainer instead of always-applied. AddAgentRulePage.tsx and EditAgentRulePage.tsx use the exact same multiline+label pattern this replaces, but aren't updated here.

Could you confirm those screens still render correctly, or scope this fix locally instead of in the shared implementation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While investigating this I noticed that AddAgentRulePage and EditAgentRulePage have similar implementation to what was in EditPrompPage and AddAgentPage I changed in this PR. I will update these components as well to make the behaviour in landscape mode consistent

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll then check if this change does not break anything because these 2 components + AgentAIPromptSection are the only one that use multiline input with label

@GCyganek GCyganek Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

styles.textInputMultilineContainer sets height: 100% which I wanted to keep in case we have both isMultiline and hasLabel as true values, as keeping both height: 100% and flex: 1 in this case was causing problems with input resizing during device orientation change

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm, I just tested it again without this change and it works fine 🙄

@GCyganek

GCyganek commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

@Expensify/design I realized that there are two places that have the same behaviour (add and edit agent rule in workspace) in landscape mode as the screens I have already fixed here that were reported as bugged. Could you confirm if this is ok now?

Screen.Recording.2026-07-02.at.16.08.32.mov
Screen.Recording.2026-07-02.at.16.04.37.mov

Compared to current behaviour:

Screen.Recording.2026-07-02.at.16.16.15.mov

const targetHeight = Math.max(0, keyboardTop - VERTICAL_SPACE_FOR_FOCUSED_INPUT - collapsibleHeaderOffsetSV.get());
const targetHeight = alwaysCollapseHeaderOnKeyboard
? MIN_HEADER_HEIGHT_ON_COLLAPSE
: Math.max(MIN_HEADER_HEIGHT_ON_COLLAPSE, keyboardTop - VERTICAL_SPACE_FOR_FOCUSED_INPUT - collapsibleHeaderOffsetSV.get());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MIN_HEADER_HEIGHT_ON_COLLAPSE changes collapse behavior for all existing consumers.

The old floor was Math.max(0, ...), the new one is Math.max(16, ...). This affects every existing consumer of CollapsibleHeaderOnKeyboard that doesn't pass alwaysCollapseHeaderOnKeyboard..

Is it fine?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine. It's just that designers didn't like cases where we did not have any padding above the input on header collapse, so I decided to fix all such cases like this, because I was getting new cases with inputs shown without top padding on header collapse on this PR

const shouldUseScrollableLayout = useIsInLandscapeMode();
const {windowWidth, windowHeight} = useWindowDimensions();
const {isKeyboardActive} = useKeyboardState();
const isInLandscapeMode = isInLandscapeModeUtil(windowWidth, windowHeight) || (isMobile() && windowWidth > windowHeight);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent landscape detection across sibling pages

EditPromptPage computes landscape as:

isInLandscapeModeUtil(windowWidth, windowHeight) || (isMobile() && windowWidth > windowHeight)
while AddAgentRulePage and EditAgentRulePage use:

useIsInLandscapeMode().

These are equivalent today (both web-noop, both phone-only on native), but the diverging patterns are confusing for anyone reading this code side-by-side.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to overwrite original approach as it was not connected to the issue, but I checked mWeb of this page and i'ts not usable even with this change, so if we want to have the same approach, then I'd drop isMobile() && windowWidth > windowHeight check and focus on checking this later for mWeb

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped mWeb landscape check

@truph01

truph01 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

@Expensify/design Could you check this comment?

// Assumed vertical space for the focused input field — used to reserve space above the keyboard.
const VERTICAL_SPACE_FOR_FOCUSED_INPUT = 120;
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 = 16;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GCyganek We are using value 8 in PR #93935, could you find the proper value?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I'll try to unify the approach for this on both PRs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I set 8 as min header height on collapse, will update the mentioned PR in a moment

@shawnborton

Copy link
Copy Markdown
Contributor

Could you confirm if this is ok now?

Yeah, that approach still seems fine to me 👍

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants