{"id":24497046,"url":"https://github.com/yannxou/tabviewlostscrollposition","last_synced_at":"2026-05-19T04:35:29.558Z","repository":{"id":198489870,"uuid":"700795168","full_name":"yannxou/TabViewLostScrollPosition","owner":"yannxou","description":"Showcase of an issue in SwiftUI's TabView where a contained view scroll position is lost when using swipe gesture ","archived":false,"fork":false,"pushed_at":"2023-10-05T14:15:16.000Z","size":11183,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-21T21:20:15.328Z","etag":null,"topics":["bug","swift","swiftui","xcode"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yannxou.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-10-05T10:02:59.000Z","updated_at":"2024-08-27T08:26:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"c0d6051f-4484-4e4f-8789-657975341ede","html_url":"https://github.com/yannxou/TabViewLostScrollPosition","commit_stats":null,"previous_names":["yannxou/tabviewlostscrollposition"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yannxou%2FTabViewLostScrollPosition","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yannxou%2FTabViewLostScrollPosition/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yannxou%2FTabViewLostScrollPosition/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yannxou%2FTabViewLostScrollPosition/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yannxou","download_url":"https://codeload.github.com/yannxou/TabViewLostScrollPosition/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243690174,"owners_count":20331729,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bug","swift","swiftui","xcode"],"created_at":"2025-01-21T21:20:00.046Z","updated_at":"2026-05-19T04:35:29.531Z","avatar_url":"https://github.com/yannxou.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TabViewLostScrollPosition\n\nThis test project showcases an issue in SwiftUI's `TabView` where the contained views can lose their scroll position when the selected tab changes using the swipe gesture.\n\nThe included project has been done using Xcode 15.0 and tested under iOS 16 and iOS 17.0.\n\n## Up to 3 tabs is fine\n\nAs you can see below, with 3 tabs the scroll position is maintained as we swipe from tab to tab:\n\nhttps://github.com/yannxou/TabViewLostScrollPosition/assets/5954961/c53442a4-06a4-4c79-b6a0-86f0512bfeba\n\n\n## What about 4?\n\nIf we do the same test with 4 tabs you'll notice that the tab #0 resets its scroll position when we come back after going through them all. Moreover, if we later go again to the right-most tab we can see it also lost its scroll position. Why is that?\n\nhttps://github.com/yannxou/TabViewLostScrollPosition/assets/5954961/4b51a6ab-6c82-4c5c-b725-9da0e137d84b\n\n\nThis gets more interesting if we do the same test but using the `Picker` instead of the swipe gesture. In this case all scroll positions are maintained:\n\nhttps://github.com/yannxou/TabViewLostScrollPosition/assets/5954961/8063a8be-3ccd-490e-9e30-5bde059f6879\n\n\n## Some sort of explanation\n\nIt seems that `TabView` does keep somehow the state of all views since the scroll is maintained when using the `Picker` to change the tab or by programatically setting the `selection` binding. But when using the swipe gesture it looks like only the current tab, the previous one and next tab (based on the swipe direction) are kept. \n\nThis is more evident if we do the test with 5 tabs:\n\nhttps://github.com/yannxou/TabViewLostScrollPosition/assets/5954961/a73048dc-399d-4910-9f52-919735a9867e\n\n\nAnd again, everything's fine when using the `Picker` or updating programatically:\n\nhttps://github.com/yannxou/TabViewLostScrollPosition/assets/5954961/604fc921-cba7-4d50-b29b-e013a6ed088c\n\n\n\n## Bug?\n\nIt would seem that this is a bug in the current `TabView` implementation. I hope this test project helps anyone else with the same issue and provides some context for a future fix.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyannxou%2Ftabviewlostscrollposition","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyannxou%2Ftabviewlostscrollposition","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyannxou%2Ftabviewlostscrollposition/lists"}