Post

Replies

Boosts

Views

Activity

ScrollViewReader and scrollTo Bug
I've found that using scrollTo inside of an onChange closure doesn't scroll to the correct location if the row height of the List item is greater than a single row. It will scroll to the height of a single row leaving everything else in the row hidden. If I use the scrollTo inside a Button action it will accurately read the height of the VStack and scroll to a position that shows the full row. The second image is a result of clicking the button, the first is the triggering of the onChange event. Here is the code I'm working with: Button("Scroll To ") { readerProxy?.scrollTo(careLogItems.last) } ScrollViewReader { reader in List(careLogItems) { i in VStack { Text(i.logText) Text(i.logDate.description) }.id(i) }.onAppear { readerProxy = reader //reader.scrollTo(careLogItems.last) } CareLogItemDetail(careLogItem: $newCareLogItem, addItem: addCareLogItem) } } .onChange(of: careLogItems) { _ in print("changed \(careLogItems.count)") readerProxy?.scrollTo(careLogItems.last) } .onAppear { if (hasAppeared == false) { hasAppeared = true loadCareLogItems() } } ![]("https://developer.apple.com/forums/content/attachment/d409d385-9415-47cf-ad0a-aa9c7f317ac9" "title=Screenshot 2023-07-25 at 8.26.25 AM.png;width=548;height=1160") ![]("https://developer.apple.com/forums/content/attachment/54325855-d6c5-4aee-a817-2a7059c872d5" "title=Screenshot 2023-07-25 at 8.26.59 AM.png;width=536;height=1176")
1
0
472
Jul ’23
Adding modifier .tabViewStyle(.page) breaks NavigationStack embedded in TabbedView
This seems like a bug to me or I am just missing something obvious...as soon as I add the .tabViewStyle(.page) modifier to the below code it breaks the NavStack navigation. I can click the NavLink once and when I go back from the detail view I can't click on anything again. Here is the code: struct TabbedView: View { var body: some View { TabView { NavStack() .tag(1) NavStack() .tag(2) } .tabViewStyle(.page) //this BREAKS navigation } } struct NavStack: View { let arrs: [String] = ["First Group", "Second Group"] var body: some View { NavigationStack { ForEach(arrs, id: \.self) {_ in NavigationLink("Link") { Text("test") } } .listStyle(PlainListStyle()) } } }
2
2
558
May ’23