Skip to content

Make Copilot switching discoverable with a dedicated Switch button on the Accounts page (v2)#95769

Open
wildan-m wants to merge 14 commits into
Expensify:mainfrom
wildan-m:wildan/92253-copilot-switch-button-v2
Open

Make Copilot switching discoverable with a dedicated Switch button on the Accounts page (v2)#95769
wildan-m wants to merge 14 commits into
Expensify:mainfrom
wildan-m:wildan/92253-copilot-switch-button-v2

Conversation

@wildan-m

@wildan-m wildan-m commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

This re-lands #93393 (reverted in #95748) together with fixes for the two deploy blockers it surfaced.

1. Reapply the feature — revert of the revert (658bde1c7ee), no conflicts.

2. #95693 — no tooltip in landscape, wrong position after rotating back

The educational tooltip measured its anchor once and never again. On an orientation change the anchor is laid out twice: first at an intermediate position, then at its final one. measure() only reports the new position after the native layout has landed, so that single early measurement left the tooltip anchored to a position the component had already left.

Instrumented on an Android emulator, rotating back to portrait:

change      t=521946
onLayout#1  t=522152  layoutX=198.10  ->  measure x=218.29   (intermediate)
onLayout#2  t=523473  layoutX=249.90  ->  measure x=270.10   (final)

Anchors on the left edge hid this, because their x doesn't depend on the container width. The Switch button sits on the right edge, so with ANCHOR_ORIGIN_HORIZONTAL.RIGHT the stale x put the tooltip at left: -5.76dp — off the screen — and made the safe-area bounds check read the button as overflowing in landscape, hiding the tooltip entirely.

Fix: re-measure on every layout of the anchor once the tooltip has been displayed, so it tracks the component instead of a snapshot of where it used to be. No timers, no delay constants — the layout event itself is the trigger.

Note: this is a latent bug in BaseEducationalTooltip, not something #93393 introduced. It reproduces on the pre-PR build (avatar anchor) in landscape too; the right-aligned Switch button is just the first anchor that made the positional consequence visible.

3. #95717 — tooltip stays in place when the page is scrolled

BaseEducationalTooltip already knows how to hide and re-measure on scroll, but two independent gaps stopped it here:

  1. AccountSwitcher never passed shouldHideOnScroll, so it defaulted to false and the tooltip never subscribed to the scroll event.
  2. InitialSettingsPage's ScrollView never called useScrollEventEmitter, so CONST.EVENTS.SCROLLING was never emitted on that page at all — there was nothing to subscribe to. (LHNOptionsList and BaseSelectionListWithSections both emit it; the settings page didn't.)

Fix: opt in and emit. The tooltip now hides while the list moves and, once it settles, either follows the button or stays hidden when the button has scrolled out of view.

Fixed Issues

$ #92253
$ #95693
$ #95717
PROPOSAL: #92253 (comment)

Tests

Requires an account that is a copilot for at least one other account, and that has not yet dismissed the account-switcher tooltip.

Rotation (#95693), Android/iOS native:

  1. Sign in and open Account.
  2. Verify the one-time tooltip appears anchored under the Switch button.
  3. Rotate the device to landscape. Verify the tooltip is still shown, anchored to the Switch button.
  4. Rotate back to portrait. Verify the tooltip returns to exactly its original position under the Switch button, not clipped or shifted off the left edge.

Scrolling (#95717), all platforms:
5. Back in portrait at the top of the Account list, with the tooltip visible, scroll the page down.
6. Verify the tooltip is hidden once the Switch button scrolls out of view — it must not float over the other rows.
7. Scroll back to the top. Verify the tooltip reappears anchored to the Switch button.

Feature (re-land of #93393):
8. Verify the Switch button opens the account switcher.
9. Verify the avatar and account name at the top of Account are no longer pressable.
10. Verify Status now lives under Profile.

  • Verify that no errors appear in the JS console

Offline tests

The tooltip, the Switch button and the account switcher are all rendered from local Onyx data, so behaviour is unchanged offline. Repeat the Tests above with the network disabled and verify the tooltip still appears, hides on scroll, and repositions on rotation.

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 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 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
Kapture.2026-07-16.at.20.51.46.mp4
Android: mWeb Chrome
Kapture.2026-07-16.at.13.18.39.mp4
iOS: Native
Kapture.2026-07-16.at.13.14.09.mp4
iOS: mWeb Safari
Kapture.2026-07-16.at.13.18.39.mp4
MacOS: Chrome / Safari
Kapture.2026-07-16.at.13.06.32.mp4

wildan-m added 3 commits July 10, 2026 03:19
…button on the Accounts page"

This reverts commit 658bde1, restoring the change reverted while the deploy
blockers it surfaced were investigated. The following commits fix those blockers.
The tooltip measured its anchor once and never again. On an orientation change the
anchor is laid out twice: once at an intermediate position, then at its final one.
measure() only reports the new position after the native layout has landed, so the
single early measurement left the tooltip anchored to a position the component had
already left.

Anchors on the left edge hid this, since their x doesn't depend on the container
width. The Switch button sits on the right edge, so the stale x placed the
right-aligned tooltip off the left of the screen, and made the bounds check read the
button as overflowing in landscape, hiding the tooltip entirely.

Re-measure on every layout of the anchor once the tooltip has been displayed, so it
tracks the component instead of a snapshot of where it used to be.
The tooltip is anchored to the Switch button, which scrolls with the settings list,
but it is drawn in a portal at a fixed position. It stayed put while the list moved,
floating over unrelated rows once the button had scrolled away.

BaseEducationalTooltip already hides and re-measures on scroll, but two things stopped
it here: the tooltip never opted in via shouldHideOnScroll, and the settings page never
emitted a scrolling event for anything to listen to.

Opt in and emit, so the tooltip hides while the list moves and, once it settles, either
follows the button or stays hidden when the button has scrolled out of view.
@melvin-bot

melvin-bot Bot commented Jul 9, 2026

Copy link
Copy Markdown

Hey, I noticed you changed src/languages/en.ts in a PR from a fork. For security reasons, translations are not generated automatically for PRs from forks.

If you want to automatically generate translations for other locales, an Expensify employee will have to:

  1. Look at the code and make sure there are no malicious changes.
  2. Run the Generate static translations GitHub workflow. If you have write access and the K2 extension, you can simply click: [this button]

Alternatively, if you are an external contributor, you can run the translation script locally with your own OpenAI API key. To learn more, try running:

npx ts-node ./scripts/generateTranslations.ts --help

Typically, you'd want to translate only what you changed by running npx ts-node ./scripts/generateTranslations.ts --compare-ref main

wildan-m added 8 commits July 16, 2026 08:02
…e tooltip

In landscape the educational tooltip stayed hidden after rotating, and only appeared
once you left the page and came back.

Dimensions.get('window') already excludes the horizontal safe-area insets, but the
bounds check added the right inset back to the element's right edge. On a device with
a landscape display cutout that counted it twice: the Switch button's right edge is
842.28 inside an 862.48 window, yet the check computed 894.09 and read it as
overflowing, so it hid the tooltip.

Leaving the page and returning worked because that remounts the switcher, and the
first-display path shows the tooltip without consulting the bounds check at all.
Rotation re-runs only the bounds-checked path, so there was nothing to undo the hide.

Anchor both edges to the inset-adjusted left so they share the window's origin, and
pull the arithmetic into a helper so it can be tested against the measured values.
On mWeb the educational tooltip stayed hidden after rotating to landscape, and only
came back after leaving the page and returning.

The debounced reset closed over isResizing, so the callback created by the first resize
event still saw it as false and took the early return instead of settling. The effect's
cleanup then cancelled that pending call as soon as isResizing flipped true, leaving a
second resize event as the only thing that could ever reset it. Dragging a window emits
a stream of events so it settled; an orientation change can emit just one, so it stayed
true forever and BaseEducationalTooltip kept hiding the tooltip without ever
re-rendering it.

Track the settle deadline in the effect instead, so a lone resize event still settles.
The pending "scrolling ended" event was cancelled on unmount without being sent, so
navigating away mid-scroll left every listener believing the scroll was still going:
educational tooltips stayed hidden, hovers stayed suppressed, and the composer kept
swallowing wheel events. The scroll is over once the view is gone, so say so.

Also cover the behaviour the surrounding code was built for, so it stays covered: a
tooltip re-measures once resizing settles, a target resting against the left edge is
still in bounds, and one that scrolls out of view horizontally is not.
The previous commit pulled the bounds arithmetic into a helper so it could be unit
tested, which meant reworking how the component reads its insets and moving code that
was never at fault. Fix the one wrong expression in place instead: dropping the right
inset also makes it an unused dependency, so it goes too.
@wildan-m
wildan-m marked this pull request as ready for review July 18, 2026 15:33
@wildan-m
wildan-m requested review from a team as code owners July 18, 2026 15:33
@melvin-bot
melvin-bot Bot requested review from a team, eh2077 and joekaufmanexpensify and removed request for a team July 18, 2026 15:33
@melvin-bot

melvin-bot Bot commented Jul 18, 2026

Copy link
Copy Markdown

@eh2077 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 18, 2026 15:33

@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: d516241c3a

ℹ️ 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 on lines +211 to +212
if (hasDisplayedTooltipRef.current) {
renderTooltip();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep the first tooltip measurement delayed

When an educational tooltip is mounted inside an animated container and the anchor fires a second onLayout before CONST.TOOLTIP_ANIMATION_DURATION elapses, hasDisplayedTooltipRef is already true because it is set as soon as shouldMeasure flips, before the delayed show.current runs. This new path therefore calls renderTooltip() immediately and skips the existing settle delay, so the first render can be measured against a transient animated layout and appear in the wrong place; gate this on the delayed show actually completing instead.

Useful? React with 👍 / 👎.

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, fixed in c319d19. hasDisplayedTooltipRef was set as soon as shouldMeasure flipped — before the delayed first render actually ran — so a second onLayout inside the animation window re-measured against a transient layout. Moved the flag into the delayed show.current(), so both the layout and scroll-gating re-measure paths only fire after the first render settles. Added a regression test for a second layout arriving before the delay elapses.

The re-measure-on-layout path checked hasDisplayedTooltipRef, but that ref was set as
soon as shouldMeasure flipped — before the delayed first render actually ran. So a
second onLayout arriving within the animation window (e.g. an animated container still
settling) re-measured against a transient layout and could place the tooltip wrongly.

Set the ref inside the delayed show instead, so both the layout and the scroll-gating
re-measure paths only run after the first render has genuinely settled.

@joekaufmanexpensify joekaufmanexpensify left a comment

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.

V2 attempt after fixing deploy blockers

@eh2077

eh2077 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible 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 checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • 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 verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • 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 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.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this 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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Android: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari

@eh2077

eh2077 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

sorry for the delay, will finish test and review by tmr.

Comment thread src/hooks/useScrollEventEmitter.ts Outdated
Comment on lines +43 to +49
// Unmounting mid-scroll drops the pending "scrolling ended" event, leaving every listener
// stuck as if the scroll never finished. The scroll is over either way, so say so.
if (!isScrollingRef.current) {
return;
}
DeviceEventEmitter.emit(CONST.EVENTS.SCROLLING, false);
isScrollingRef.current = false;

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.

I don't prefer playing trick about scrolling. Why don't use ProductTrainingTooltipInner?

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 point — reverted useScrollEventEmitter to main; the copilot tooltip now hides on scroll purely via EducationalTooltip's shouldHideOnScroll, the same mechanism ProductTrainingTooltipInner uses, with the Accounts page emitting scroll events like LHNOptionsList does.

wildan-m added 2 commits July 25, 2026 07:38
…t-switch-button-v2

# Conflicts:
#	src/languages/de.ts
#	src/languages/en.ts
#	src/languages/es.ts
#	src/languages/fr.ts
#	src/languages/it.ts
#	src/languages/ja.ts
#	src/languages/nl.ts
#	src/languages/pl.ts
#	src/languages/pt-BR.ts
#	src/languages/zh-hans.ts
Per review: hiding the copilot tooltip on scroll doesn't need the shared scroll emitter
touched. The tooltip uses EducationalTooltip's shouldHideOnScroll and the settings page
emits scroll events the same way the LHN list does — matching the ProductTrainingTooltip
pattern. The emit-on-unmount hardening was a defensive edge-case fix unrelated to this
feature, so revert useScrollEventEmitter to main and drop its test.
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