swift-composable-architecture icon indicating copy to clipboard operation
swift-composable-architecture copied to clipboard

scrollview proxy scroll to not working when child view are scoped from mother reducer

Open ckse93 opened this issue 6 months ago • 1 comments

Description

Hi, I noticed that when making list cells, if you scope the elements from mother reducer, and provide child reducer, then ScrollViewProxy's scrollTo functionality does not work. However if I replicate the same logic using raw data, where I generate child reducers from, scrollTo functionality works as expected.

here is the link to isolated bug showcase: https://github.com/ckse93/TCA-ScrollTo-bug-showcase

Checklist

  • [x] I have determined whether this bug is also reproducible in a vanilla SwiftUI project.
  • [x] If possible, I've reproduced the issue using the main branch of this package.
  • [x] This issue hasn't been addressed in an existing GitHub issue or discussion.

Expected behavior

when proxy.scrollTo() is triggered, the scroll view should scroll to the element

Actual behavior

No response

Reproducing project

TCA scrollTo.zip github repo

The Composable Architecture version information

No response

Destination operating system

No response

Xcode version information

No response

Swift Compiler version information


ckse93 avatar May 19 '25 19:05 ckse93

Tested out your project, .id(itemStore.name) solves the problem.

List(motherStore.scope(state: \.items, action: \.itemAction)) { itemStore in
     Text(itemStore.name)
        .id(itemStore.name) // this works
     // .id(itemStore.id) // this doesn't work, because id: ObjectIdentifier
}
`

alpaycli avatar May 29 '25 13:05 alpaycli

Hi @ckse93, I believe @alpaycli has figured out your problem here. You are using the name of the items to scroll to a row, yet you are using the store's identity to tag each row. If you want access to the state's ID rather than the store's, you can do store.state.id.

Since this isn't an issue with the library I am going to convert it to a discussion. Please feel free to continue the conversation over there!

mbrandonw avatar Jun 20 '25 16:06 mbrandonw