Repository navigation
fix(ios): show a page that SwiftUI hosts again after setPage - #1203
Draft
KisaneNeko wants to merge 1 commit into
Draft
KisaneNeko wants to merge 1 commit into
KisaneNeko wants to merge 1 commit into
Conversation
Each page is one React Native view, which PageChildViewController adds to its own view once, in viewDidLoad. SwiftUI can keep two controllers alive for the same page. The newer one takes the page view, and when SwiftUI removes it the view is left with no parent. If SwiftUI then shows the older controller again, nothing adds the view back, and the page is blank. When the collection view is about to display a cell, its controller now takes the page view back if the view has no parent. A view that a newer controller holds is left alone. Fixes callstack#1202
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #1202. It surfaced while reviewing #1193, whose repro screen triggers it, but it happens on 9.0.10 without that PR.
On iOS, a page shown by
setPagecan be blank. The pager reports the page as selected, but the page has no content and stays empty after the pager stops.reproduction
What happened
PageChildViewControlleradds it to its own view once, inviewDidLoad.I traced this with logging: in the blank state, the visible cell's controller wraps the right page view, but that view has no superview.
Fix
PagerScrollDelegatenow handlescollectionView(_:willDisplay:forItemAt:). Before a cell shows, itsPageChildViewControllerchecks its page view. If the view has no parent, the controller takes it back.willDisplaya reused cell can still hold an older controller while SwiftUI is about to show a newer one. Taking the view unconditionally blanked page 0 in the basic example, which thebasic-pagere2e tests caught.viewDidLoadis unchanged.Test Plan
What's required for testing (prerequisites)?
iOS simulator or device. The new example screen, which re-renders the event log above the pager on every page, focus and keyboard event.
What are the steps to reproduce (after prerequisites)?
Added
Issue #1202 Blank Page Reproto the example app ande2e/tests/issues/issue-1202-blank-page.e2e.ts:Go 1.Go 2), page 2 (Go 1), page 1 (Go 0) and page 0 (Go 1).Go 2.Selected: 2, but the pager area is empty.Verified
Selected: 2) and passes 3/3 with it.typecheck(root, example and e2e),lint(no warnings in the changed files),testand prettier pass.Android is untouched.
Compatibility
Checklist
README.md: not applicable🤖 Generated with Claude Code