fix: smooth tab switching with fade animations (#1479)#1480
fix: smooth tab switching with fade animations (#1479)#1480Vedag812 wants to merge 1 commit intokiwix:mainfrom
Conversation
|
@Vedag812 Thank you very much for your PR. Can you please upload screencast to demonstrate the fix? |
There was a problem hiding this comment.
Pull request overview
This PR aims to make tab switching visually smoother by replacing abrupt content changes with fade/crossfade animations, reducing perceived blank flashes during transitions (fix for #1479).
Changes:
- Fade in the iOS
WKWebViewafter layout stabilization using a shortUIView.animateinstead of an immediate alpha toggle. - Make the loading spinner overlay transparent (so underlying web content remains visible) on the
BrowserTabview. - Add an opacity transition + animation driven by
navigation.currentItemfor iPhone tab switches inCompactViewController.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| Views/BuildingBlocks/WebView.swift | Reduces debounce delay and animates WebView alpha to fade in after layout. |
| Views/BrowserTab.swift | Removes opaque overlay background and disables hit testing on the loading overlay spinner. |
| App/CompactViewController.swift | Adds animation + opacity transition around the compact tab content for crossfading. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let webView = self?.webView, | ||
| view.subviews.contains(webView) else { return } | ||
| webView.alpha = 1 | ||
| UIView.animate(withDuration: 0.2) { | ||
| webView.alpha = 1 | ||
| } |
There was a problem hiding this comment.
layoutSubject is triggered on every viewDidLayoutSubviews, but the sink now runs an unconditional UIView.animate each time it fires. This can cause repeated/needless animations on later layout passes (rotation, safe-area changes, etc.). Consider guarding so the fade-in runs only once (e.g., check webView.alpha == 0 / a hasFadedIn flag).
| CompactView(tabID: tabID) | ||
| .transition(.opacity) | ||
| } | ||
| } | ||
| .animation(.easeInOut(duration: 0.2), value: navigation.currentItem) |
There was a problem hiding this comment.
The .transition(.opacity) is unlikely to apply when switching between different .tab(tabID) values because this branch stays active and CompactView is updated rather than inserted/removed. To actually crossfade between tabs, give CompactView a changing identity at this level (e.g., .id(tabID)) or apply the transition to the view whose identity changes so SwiftUI performs a removal/insertion animation.
d8da934 to
63f3af3
Compare
63f3af3 to
150e969
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1480 +/- ##
=======================================
Coverage 92.59% 92.59%
=======================================
Files 18 18
Lines 878 878
=======================================
Hits 813 813
Misses 65 65 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hi @kelson42 @BPerlakiH any updates? |
@BPerlakiH will review your PR, but give him a few days. |
sure no issues |
150e969 to
900ae20
Compare
|
@Vedag812 Thank you for the PR. iPadOn iPad it looks better now: iPad beforeipad_before.moviPad afteripad_after.moviPhoneOn iPhone the composition of the UI is different, and the changes in App/CompactViewController.swift has no visual effect to be honest: iPhone beforeiphone_before.moviPhone afteriphone_after.movmacOSNot relevant in this case, and after testing, there's no visible change on that, so we can ignore it for this review. ConclusionPlease revert the changes in App/CompactViewController.swift, and it should be good to be merged. |
|
FYA: @kelson42 |
I hardly see a difference and therefore IMHO, the fix is incomplete. I suspect, just an idea: when switching:
|
|
The "black flash" comes from the fact that the device is in DarkMode, but the ZIM content is not (yet). ipad_light.mov |
|
Also,if I go frame by frame on the iPad "after" video, it seems there's fade IN, but there's no fade OUT when the switch occurs. |
I think we need more R&D to do in this area, also the issue: #1403 is very much correlated. |
Fixes #1479
Changes
1. Animated WebView fade-in (WebView.swift)
alpha = 0 → 1toggle to a smoothUIView.animate(withDuration: 0.2)fade-in2. Translucent loading overlay (BrowserTab.swift)
Color.backgroundfrom theLoadingProgressViewoverlay on iPad/macOS3. Crossfade transition (CompactViewController.swift)
CompactViewWrapperbody in aGroupwith.animation(.easeInOut(duration: 0.2)).transition(.opacity)toCompactViewfor a smooth crossfade when switching tabs on iPhone