-
Notifications
You must be signed in to change notification settings - Fork 13.4k
fix(content): automatically recalculate offset when header/footer changes #30862
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
Open
HappyKnuckles
wants to merge
6
commits into
ionic-team:main
Choose a base branch
from
HappyKnuckles:fix/content-auto-offset
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bda011b
fix(content): automatically recalculate offset when header/footer cha…
HappyKnuckles 61aa0a0
run lint
HappyKnuckles aa6bd72
fix(content): add 100ms debounce to ResizeObserver and improve type s…
HappyKnuckles 3a58aa7
fix(content): adjusted PR requests
HappyKnuckles 2f349ae
Changed timeout to requestAnimationFrame
HappyKnuckles 0a2fc35
Updated images
HappyKnuckles File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
core/src/components/content/test/auto-offset/content.e2e.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import { test, configs } from '@utils/test/playwright'; | ||
|
|
||
| configs().forEach(({ title, screenshot, config }) => { | ||
| test.describe(title('content: auto offset'), () => { | ||
| test('should not have visual regressions', async ({ page }) => { | ||
| await page.goto(`/src/components/content/test/auto-offset`, config); | ||
| await page.setIonViewport(); | ||
| await expect(page).toHaveScreenshot(screenshot(`content-auto-offset-initial`)); | ||
| }); | ||
|
|
||
| test('should update offsets when header height changes', async ({ page }) => { | ||
| await page.goto(`/src/components/content/test/auto-offset`, config); | ||
| await page.setIonViewport(); | ||
|
|
||
| const content = page.locator('ion-content'); | ||
| const before = await content.evaluate((el: HTMLElement) => getComputedStyle(el).getPropertyValue('--offset-top')); | ||
|
|
||
| await page.click('#expand-header-btn'); | ||
|
|
||
| await expect(content).not.toHaveCSS('--offset-top', before); | ||
|
|
||
| await expect(page).toHaveScreenshot(screenshot(`content-auto-offset-header-updated`)); | ||
| }); | ||
|
|
||
| test('should update offsets when footer height changes', async ({ page }) => { | ||
| await page.goto(`/src/components/content/test/auto-offset`, config); | ||
| await page.setIonViewport(); | ||
|
|
||
| const content = page.locator('ion-content'); | ||
| const before = await content.evaluate((el: HTMLElement) => | ||
| getComputedStyle(el).getPropertyValue('--offset-bottom') | ||
| ); | ||
|
|
||
| await page.click('#expand-footer-btn'); | ||
|
|
||
| await expect(content).not.toHaveCSS('--offset-bottom', before); | ||
|
|
||
| await expect(page).toHaveScreenshot(screenshot(`content-auto-offset-footer-updated`)); | ||
| }); | ||
| }); | ||
| }); |
Binary file added
BIN
+11.7 KB
...ts-snapshots/content-auto-offset-footer-updated-ios-ltr-Mobile-Chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+21.8 KB
...s-snapshots/content-auto-offset-footer-updated-ios-ltr-Mobile-Firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+15.9 KB
...ts-snapshots/content-auto-offset-footer-updated-ios-ltr-Mobile-Safari-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.6 KB
...ts-snapshots/content-auto-offset-footer-updated-ios-rtl-Mobile-Chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+21.7 KB
...s-snapshots/content-auto-offset-footer-updated-ios-rtl-Mobile-Firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+15.3 KB
...ts-snapshots/content-auto-offset-footer-updated-ios-rtl-Mobile-Safari-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.5 KB
....ts-snapshots/content-auto-offset-footer-updated-md-ltr-Mobile-Chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+20.2 KB
...ts-snapshots/content-auto-offset-footer-updated-md-ltr-Mobile-Firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+15.1 KB
....ts-snapshots/content-auto-offset-footer-updated-md-ltr-Mobile-Safari-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.4 KB
....ts-snapshots/content-auto-offset-footer-updated-md-rtl-Mobile-Chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+20.5 KB
...ts-snapshots/content-auto-offset-footer-updated-md-rtl-Mobile-Firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+14.8 KB
....ts-snapshots/content-auto-offset-footer-updated-md-rtl-Mobile-Safari-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.5 KB
...ts-snapshots/content-auto-offset-header-updated-ios-ltr-Mobile-Chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+20.8 KB
...s-snapshots/content-auto-offset-header-updated-ios-ltr-Mobile-Firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+14.6 KB
...ts-snapshots/content-auto-offset-header-updated-ios-ltr-Mobile-Safari-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.4 KB
...ts-snapshots/content-auto-offset-header-updated-ios-rtl-Mobile-Chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+20.7 KB
...s-snapshots/content-auto-offset-header-updated-ios-rtl-Mobile-Firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+14.2 KB
...ts-snapshots/content-auto-offset-header-updated-ios-rtl-Mobile-Safari-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.4 KB
....ts-snapshots/content-auto-offset-header-updated-md-ltr-Mobile-Chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+19.4 KB
...ts-snapshots/content-auto-offset-header-updated-md-ltr-Mobile-Firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+14.2 KB
....ts-snapshots/content-auto-offset-header-updated-md-ltr-Mobile-Safari-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.3 KB
....ts-snapshots/content-auto-offset-header-updated-md-rtl-Mobile-Chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+19.5 KB
...ts-snapshots/content-auto-offset-header-updated-md-rtl-Mobile-Firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+13.9 KB
....ts-snapshots/content-auto-offset-header-updated-md-rtl-Mobile-Safari-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.59 KB
...nt.e2e.ts-snapshots/content-auto-offset-initial-ios-ltr-Mobile-Chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+18.6 KB
...t.e2e.ts-snapshots/content-auto-offset-initial-ios-ltr-Mobile-Firefox-linux.png
Oops, something went wrong.
Binary file added
BIN
+12.2 KB
...nt.e2e.ts-snapshots/content-auto-offset-initial-ios-ltr-Mobile-Safari-linux.png
Oops, something went wrong.
Binary file added
BIN
+9.51 KB
...nt.e2e.ts-snapshots/content-auto-offset-initial-ios-rtl-Mobile-Chrome-linux.png
Oops, something went wrong.
Binary file added
BIN
+18.4 KB
...t.e2e.ts-snapshots/content-auto-offset-initial-ios-rtl-Mobile-Firefox-linux.png
Oops, something went wrong.
Binary file added
BIN
+11.9 KB
...nt.e2e.ts-snapshots/content-auto-offset-initial-ios-rtl-Mobile-Safari-linux.png
Oops, something went wrong.
Binary file added
BIN
+9.39 KB
...ent.e2e.ts-snapshots/content-auto-offset-initial-md-ltr-Mobile-Chrome-linux.png
Oops, something went wrong.
Binary file added
BIN
+17.3 KB
...nt.e2e.ts-snapshots/content-auto-offset-initial-md-ltr-Mobile-Firefox-linux.png
Oops, something went wrong.
Binary file added
BIN
+11.8 KB
...ent.e2e.ts-snapshots/content-auto-offset-initial-md-ltr-Mobile-Safari-linux.png
Oops, something went wrong.
Binary file added
BIN
+9.34 KB
...ent.e2e.ts-snapshots/content-auto-offset-initial-md-rtl-Mobile-Chrome-linux.png
Oops, something went wrong.
Binary file added
BIN
+17.3 KB
...nt.e2e.ts-snapshots/content-auto-offset-initial-md-rtl-Mobile-Firefox-linux.png
Oops, something went wrong.
Binary file added
BIN
+11.5 KB
...ent.e2e.ts-snapshots/content-auto-offset-initial-md-rtl-Mobile-Safari-linux.png
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en" dir="ltr"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <title>Content - Auto Offset</title> | ||
| <meta | ||
| name="viewport" | ||
| content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" | ||
| /> | ||
| <link href="../../../../../css/ionic.bundle.css" rel="stylesheet" /> | ||
| <link href="../../../../../scripts/testing/styles.css" rel="stylesheet" /> | ||
| <script src="../../../../../scripts/testing/scripts.js"></script> | ||
| <script nomodule src="../../../../../dist/ionic/ionic.js"></script> | ||
| <script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script> | ||
| </head> | ||
|
|
||
| <body> | ||
| <ion-app mode="ios"> | ||
| <ion-header translucent> | ||
| <ion-toolbar> | ||
| <ion-title>Auto Offset Test</ion-title> | ||
| </ion-toolbar> | ||
| <ion-toolbar id="extra-header-content" style="display: none"> | ||
| <ion-searchbar label="dynamic"></ion-searchbar> | ||
| </ion-toolbar> | ||
| </ion-header> | ||
|
|
||
| <ion-content fullscreen style="--background: blue"> | ||
| <button id="expand-header-btn">Expand Header</button> | ||
| <br /><br /> | ||
| <button id="expand-footer-btn">Expand Footer</button> | ||
| </ion-content> | ||
|
|
||
| <ion-footer translucent> | ||
| <ion-toolbar id="extra-footer-content" style="display: none"> | ||
| <div class="ion-padding">Expanded Footer Area</div> | ||
| </ion-toolbar> | ||
| <ion-toolbar> | ||
| <ion-title>Footer</ion-title> | ||
| </ion-toolbar> | ||
| </ion-footer> | ||
| </ion-app> | ||
| <script> | ||
| const headerBtn = document.getElementById('expand-header-btn'); | ||
| const footerBtn = document.getElementById('expand-footer-btn'); | ||
| const extraHeaderToolBar = document.getElementById('extra-header-content'); | ||
| const extraFooterToolbar = document.getElementById('extra-footer-content'); | ||
|
|
||
| headerBtn.addEventListener('click', () => { | ||
| extraHeaderToolBar.style.display = 'flex'; | ||
| }); | ||
|
|
||
| footerBtn.addEventListener('click', () => { | ||
| extraFooterToolbar.style.display = 'flex'; | ||
| }); | ||
| </script> | ||
| </body> | ||
| </html> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
timeouthere lives inside theResizeObservercallback closure, sodisconnectObserverscan't reach it to callclearTimeout. If a header or footer resizes within ~100ms of the content being removed from the DOM, the pendingsetTimeoutstill fires and callsthis.resize(), which callsforceUpdateon a disconnected component.Could you hoist this to a class field (something like
private observerResizeTimeout: ReturnType<typeof setTimeout> | null = null) and clear it indisconnectObservers? The existingresizeTimeoutfield at the top of the class is doing the same thing for theonResizehandler at line 192.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I adjusted it in the latest commit.
However regarding the timeout: i noticed that the timeout is very noticeable visually.
Do you think it is worth switching to
requestAnimationFrame?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Yeah, a rAF might be a better solution there, probably worth trying out. It should be a pretty quick test to see if it works better, basically the same structure, you'd even want to cache it and clear it out the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rAF indeed seems to improve it, so i will go with that solution.