Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mobile: adjust modals height to visual viewport #4427

Merged
merged 5 commits into from
Feb 22, 2025

Conversation

andrew--r
Copy link
Contributor

@andrew--r andrew--r commented Feb 21, 2025

Motivation

Currently, keyboard on mobile (specifically iOS) overlaps modal's content, which is not great in some cases:

  • longs lists (e.g. transaction category/payee modals) are not fully visible and it's not possible to choose one of the last options without additional actions (hiding the keyboard, searching by the option text)
  • submit buttons are sometimes hidden under the keyboard if the form is long enough (e.g. category note form), which also forces a user to hide the keyboard before submitting changes
BEFORE.MP4

Solution

React Aria exposes a CSS custom property with a height of the visual viewport:

The --visual-viewport-height CSS custom property will be set on the ModalOverlay, which you can use to set the height to account for the virtual keyboard on mobile. (source)

I slightly changed the layout of the <Modal>. Now there are two base layers:

  • ReactAriaModalOverlay that expands to the whole viewport (not the visual one) and provides a backdrop
  • let's call it "positioning container" inside the overlay that takes the height of the visual viewport and positions the modal relative to it

Overlay and positioning container should be separate to keep the overlay stable when keyboard closes, otherwise you'll see flicker (while keyboard is closing, the part of the screen that it occupied will not be covered by backdrop).

I also tweaked the height of some existing modals to be relative to the visual viewport.

AFTER.MP4

Note

Would be nice to get someone to test this on Android, as I don't have an Android device to confirm the behaviour there. Shouldn't break anything though

Fixes #3939

Copy link

netlify bot commented Feb 21, 2025

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit 7c66f1b
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/67b9159537484c0008c15945
😎 Deploy Preview https://deploy-preview-4427.demo.actualbudget.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

github-actions bot commented Feb 21, 2025

Bundle Stats — desktop-client

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
17 6.99 MB → 6.99 MB (+520 B) +0.01%
Changeset
File Δ Size
src/components/common/Modal.tsx 📈 +368 B (+3.73%) 9.63 kB → 9.99 kB
src/components/modals/PayeeAutocompleteModal.tsx 📈 +38 B (+2.12%) 1.75 kB → 1.79 kB
src/components/modals/AccountAutocompleteModal.tsx 📈 +38 B (+1.83%) 2.03 kB → 2.07 kB
src/components/modals/CategoryAutocompleteModal.tsx 📈 +38 B (+1.64%) 2.26 kB → 2.3 kB
src/components/modals/EditFieldModal.tsx 📈 +38 B (+0.50%) 7.49 kB → 7.53 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
static/js/index.js 4.35 MB → 4.35 MB (+520 B) +0.01%

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
static/js/en-GB.js 99.33 kB 0%
static/js/nl.js 98.45 kB 0%
static/js/uk.js 111.11 kB 0%
static/js/workbox-window.prod.es5.js 5.69 kB 0%
static/js/indexeddb-main-thread-worker-e59fee74.js 13.5 kB 0%
static/js/resize-observer.js 18.37 kB 0%
static/js/BackgroundImage.js 122.29 kB 0%
static/js/de.js 111.98 kB 0%
static/js/narrow.js 85.76 kB 0%
static/js/AppliedFilters.js 10.79 kB 0%
static/js/useAccountPreviewTransactions.js 1.69 kB 0%
static/js/en.js 103.19 kB 0%
static/js/fr.js 73.67 kB 0%
static/js/pt-BR.js 113.53 kB 0%
static/js/wide.js 102.9 kB 0%
static/js/ReportRouter.js 1.59 MB 0%

Copy link
Contributor

github-actions bot commented Feb 21, 2025

Bundle Stats — loot-core

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
1 1.34 MB 0%

Changeset

No files were changed

View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
kcab.worker.js 1.34 MB 0%

@andrew--r andrew--r force-pushed the master branch 2 times, most recently from a4f524c to ccbad73 Compare February 21, 2025 21:54
@andrew--r andrew--r changed the title Mobile: adapt autocomplete modals to visual viewport Mobile: adapt modals to visual viewport Feb 21, 2025
@andrew--r andrew--r changed the title Mobile: adapt modals to visual viewport Mobile: adjust modals height to visual viewport Feb 21, 2025
@andrew--r andrew--r marked this pull request as ready for review February 21, 2025 22:30
Copy link
Contributor

coderabbitai bot commented Feb 21, 2025

Walkthrough

This pull request implements changes to the modal components within the desktop client to enhance layout and responsiveness. In the Modal.tsx file, a new wrapping <div> container is introduced to center the modal using flex styling, with properties such as overflowY, display, alignItems, and justifyContent moved from the ReactAriaModalOverlay to this new container. The Dialog component's styling has been simplified by removing the outline property and adjusting the style prop to include properties like flex, padding, and borderRadius. Additionally, the height for narrow widths in the account, category, edit field, and payee autocomplete modals has been updated from a fixed 85vh to a dynamic calculation using calc(var(--visual-viewport-height) * 0.85), while the height for non-narrow widths remains unchanged. There are no modifications to exported entities.

Possibly related PRs

Suggested labels

:sparkles: Merged, :white_check_mark: Approved

Suggested reviewers

  • matt-fidd
  • youngcw

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 27dcea9 and b56ffa7.

⛔ Files ignored due to path filters (6)
  • packages/desktop-client/e2e/accounts.test.ts-snapshots/Accounts-Import-Transactions-import-csv-file-twice-1-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/accounts.test.ts-snapshots/Accounts-Import-Transactions-import-csv-file-twice-2-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/accounts.test.ts-snapshots/Accounts-Import-Transactions-import-csv-file-twice-3-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/accounts.test.ts-snapshots/Accounts-Import-Transactions-imports-transactions-from-a-CSV-file-1-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/accounts.test.ts-snapshots/Accounts-Import-Transactions-imports-transactions-from-a-CSV-file-2-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/accounts.test.ts-snapshots/Accounts-Import-Transactions-imports-transactions-from-a-CSV-file-3-chromium-linux.png is excluded by !**/*.png
📒 Files selected for processing (1)
  • packages/desktop-client/src/components/common/Modal.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/desktop-client/src/components/common/Modal.tsx
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Functional
  • GitHub Check: Visual regression
  • GitHub Check: build (windows-latest)
  • GitHub Check: build (ubuntu-latest)
  • GitHub Check: compare

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (3)
packages/desktop-client/src/components/modals/PayeeAutocompleteModal.tsx (1)

32-34: ⚠️ Potential issue

Update defaultAutocompleteProps to use visual viewport height.

The height in defaultAutocompleteProps still uses vh units which may cause layout issues with mobile keyboards. Update it to use the visual viewport height for consistency.

   const defaultAutocompleteProps = {
-    containerProps: { style: { height: isNarrowWidth ? '90vh' : 275 } },
+    containerProps: { style: { height: isNarrowWidth ? 'calc(var(--visual-viewport-height) * 0.9)' : 275 } },
   };
packages/desktop-client/src/components/modals/AccountAutocompleteModal.tsx (1)

28-30: ⚠️ Potential issue

Update defaultAutocompleteProps to use visual viewport height.

Similar to PayeeAutocompleteModal, the height in defaultAutocompleteProps should use the visual viewport height for consistent behavior with mobile keyboards.

   const defaultAutocompleteProps = {
-    containerProps: { style: { height: isNarrowWidth ? '90vh' : 275 } },
+    containerProps: { style: { height: isNarrowWidth ? 'calc(var(--visual-viewport-height) * 0.9)' : 275 } },
   };
packages/desktop-client/src/components/modals/CategoryAutocompleteModal.tsx (1)

34-36: ⚠️ Potential issue

Update defaultAutocompleteProps to use visual viewport height.

For consistency with other modal components and proper mobile keyboard handling, update the height calculation to use the visual viewport height.

   const defaultAutocompleteProps = {
-    containerProps: { style: { height: isNarrowWidth ? '90vh' : 275 } },
+    containerProps: { style: { height: isNarrowWidth ? 'calc(var(--visual-viewport-height) * 0.9)' : 275 } },
   };
🧹 Nitpick comments (2)
packages/desktop-client/src/components/common/Modal.tsx (1)

118-142: Clean up commented code and align viewport units

Two suggestions for improvement:

  1. Remove the commented-out border style on line 131 to maintain clean code.
  2. Consider using calc(var(--visual-viewport-height) * 0.9) for maxHeight instead of 90vh to maintain consistency with the visual viewport approach.
   style={{
     flex: 1,
     padding: 10,
     willChange: 'opacity, transform',
     maxWidth: '90vw',
     minWidth: '90vw',
     maxHeight: '90vh',
-    //border: '1px solid ' + theme.modalBorder,
     color: theme.pageText,
     backgroundColor: theme.modalBackground,
packages/desktop-client/src/components/modals/EditFieldModal.tsx (1)

1-1: Consider centralizing modal height calculations.

The height calculations and viewport ratios (0.85, 0.9) are duplicated across multiple modal components. Consider extracting these into a shared utility or constants file to improve maintainability and ensure consistency.

Example approach:

// modalUtils.ts
export const MODAL_VIEWPORT_RATIOS = {
  DEFAULT: 0.85,
  AUTOCOMPLETE: 0.9
} as const;

export const getModalHeight = (isNarrowWidth: boolean, ratio = MODAL_VIEWPORT_RATIOS.DEFAULT) => 
  isNarrowWidth ? `calc(var(--visual-viewport-height) * ${ratio})` : 275;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ff7c358 and 851c47f.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/4427.md is excluded by !**/*.md
📒 Files selected for processing (5)
  • packages/desktop-client/src/components/common/Modal.tsx (2 hunks)
  • packages/desktop-client/src/components/modals/AccountAutocompleteModal.tsx (1 hunks)
  • packages/desktop-client/src/components/modals/CategoryAutocompleteModal.tsx (1 hunks)
  • packages/desktop-client/src/components/modals/EditFieldModal.tsx (1 hunks)
  • packages/desktop-client/src/components/modals/PayeeAutocompleteModal.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Functional
  • GitHub Check: Visual regression
🔇 Additional comments (4)
packages/desktop-client/src/components/common/Modal.tsx (3)

99-108: Well-implemented solution for mobile viewport handling!

The new positioning container effectively addresses the mobile keyboard overlap issue by:

  • Using var(--visual-viewport-height) to respect the keyboard space
  • Implementing flex layout for proper centering
  • Maintaining scrollability with overflowY: 'auto'

314-323: Good addition of flex: 'none' to header!

This change ensures the header maintains a consistent size and doesn't flex unexpectedly within the modal layout.


76-173: Verify modal behavior on Android devices

As mentioned in the PR objectives, the changes haven't been tested on Android devices. While the implementation looks solid, it would be beneficial to verify:

  1. Keyboard interaction with modals
  2. Visual viewport height calculation
  3. Scrolling behavior

Would you like me to help create a testing checklist for Android devices?

packages/desktop-client/src/components/modals/EditFieldModal.tsx (1)

247-249: LGTM!

The height calculation using visual viewport is correctly implemented and consistent with other modal components.

@@ -311,6 +318,7 @@ export function ModalHeader({
alignItems: 'center',
position: 'relative',
height: 60,
flex: 'none',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change is intentional: without it the ModalHeader shrinks, which looks bad on small viewports

@matt-fidd
Copy link
Contributor

This is definitely a big improvement, thank you!

Is there any way to minimise/animate the jump when it closes? There are a couple of times that the popover grows again when the keyboard closes and it takes a bit of time and jumps back.

matt-fidd
matt-fidd previously approved these changes Feb 21, 2025
Copy link
Contributor

@matt-fidd matt-fidd left a comment

Choose a reason for hiding this comment

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

Looks much better on mobile

@matt-fidd
Copy link
Contributor

Fixes #3939

@matt-fidd
Copy link
Contributor

/update-vrt

@andrew--r
Copy link
Contributor Author

Is there any way to minimise/animate the jump when it closes? There are a couple of times that the popover grows again when the keyboard closes and it takes a bit of time and jumps back.

@matt-fidd that's a good point, I've added a height transition to the container, so at least the change is smooth, but I don't think there's a way to get rid of the delay, would be happy to hear any ideas. Here is how it looks like with the transition:

ScreenRecording_02-21-2025.23-34-34_1.MP4

Fixes #3939

Nice, didn't know there is an issue for the problem.

Thanks for a quick review! 🙂

willChange: 'opacity, transform',
maxWidth: '90vw',
minWidth: '90vw',
maxHeight: 'var(--visual-viewport-height)',
Copy link
Contributor

@matt-fidd matt-fidd Feb 21, 2025

Choose a reason for hiding this comment

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

This makes the taller modals (CSV import, see VRT update commit) look a bit odd on desktop, could you limit it to expanding on mobile only?

Suggested change
maxHeight: 'var(--visual-viewport-height)',
maxHeight: isNarrowWidth ? 'var(--visual-viewport-height)' : '90vh',

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes, missed that, changed it to calc(var(--visual-viewport-height) * 0.9) which should be effectively the same (90% of the viewport height): b56ffa7

@andrew--r
Copy link
Contributor Author

/update-vrt

@matt-fidd
Copy link
Contributor

matt-fidd commented Feb 22, 2025

Looks good! Could you add a dummy commit to retrigger the CI, it's a limitation of the updatevrt command at the moment.

git pull && git commit --amend --no-edit && git push -f does the trick

Copy link
Contributor

@matt-fidd matt-fidd left a comment

Choose a reason for hiding this comment

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

Amazing, thank you for this!

@matt-fidd matt-fidd merged commit 1511587 into actualbudget:master Feb 22, 2025
21 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Mar 4, 2025
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Can't paste decryption key on mobiel
2 participants