danielsaidi / SwiftUIKit

SwiftUIKit is a Swift SDK that adds extra functionality to Swift & SwiftUI.
MIT License
1.4k stars 54 forks source link

ReorderableForEach -> Pass through index of element #29

Closed dwnz closed 9 months ago

dwnz commented 9 months ago

Heya,

Have been playing around with ReorderableForEach - it's awesome! Cheers for the method.

One thing I need is the index of the element, was using the SwiftUI ForEach and passing the index through to the view, doesn't appear there's a way to do this with the method? I attempted to add it myself but got a little lost

Is there any chance of getting it added when you have a spare moment? Cheers!

danielsaidi commented 9 months ago

Hi @dwnz

I'm happy to hear that you like it!

I would prefer to not modify the original list like this:

ForEach(Array(items.enumerated()), id: \.offset) { ... }

This would cause the component to list a different collection that what you pass in, and I'm not sure if this would cause problems when working with he collection 🤔

Would it work for you to map the original items to a type that has an index?

dwnz commented 9 months ago

Heya, @danielsaidi ,

Cheers for the response. Yeah that's probably fair - was thinking of something similar to how the Swift ForEach works

Have just updated my original items to include an index, works all good. Thanks again!

danielsaidi commented 9 months ago

Perfect 🙌