ACarousel icon indicating copy to clipboard operation
ACarousel copied to clipboard

Passing in binding for index disables animations.

Open josephmannis opened this issue 4 years ago • 3 comments

Example:

    ...Other code
    
    @State var currIndex: Int = 0
    
    var body: some View {
        ACarousel(items, id: \.id, index: $currIndex, ...) { ... }
    }

In this case, the animations will not occur properly. Demo:

https://drive.google.com/file/d/1asAYFM6B3ZREpgqhD4Kr3behYqe2bsy9/view?usp=sharing

josephmannis avatar Feb 12 '21 20:02 josephmannis

Yes, the problem still persists and this turns the package unusable for many situations, which is unfortunate given its quality... I hope that this can get fixed!

miguel-arrf avatar Dec 05 '21 14:12 miguel-arrf

@josephmannis @miguel-arrf It's related to the id supplied into ACarousel. Try using just strings your items and make id: \.self and it should work

e.g

ACarousel(["1","2","3","4"], id: \.self, index: $currIndex,...){ ... }

e.g with struct

struct Item: Identifiable, Hashable {
    let id = UUID()
    let name: String
}

ACarousel([Item(name:"t"), Item(name:"e"), Item(name:"s"), Item(name:"t")], id: \.name, index: $currIndex,...){ ... }

For some reason, I haven't figured out yet using id: \.self doesn't work even though the struct conforms to Identifiable

norrisboat avatar May 06 '22 00:05 norrisboat

@josephmannis @miguel-arrf It's related to the id supplied into ACarousel. Try using just strings your items and make id: \.self and it should work

e.g

ACarousel(["1","2","3","4"], id: \.self, index: $currIndex,...){ ... }

e.g with struct

struct Item: Identifiable, Hashable {
    let id = UUID()
    let name: String
}

ACarousel([Item(name:"t"), Item(name:"e"), Item(name:"s"), Item(name:"t")], id: \.name, index: $currIndex,...){ ... }

For some reason, I haven't figured out yet using id: \.self doesn't work even though the struct conforms to Identifiable

Using your code I get

ForEach<Array<Item>, Int, ModifiedContent<ModifiedContent<ModifiedContent<ZStack<TupleView<(ModifiedContent<_ShapeView<RoundedRectangle, Color>, _AppearanceActionModifier>, ModifiedContent<Text, _PaddingLayout>)>>, _FrameLayout>, _FrameLayout>, _ScaleEffect>>: the ID 7 occurs multiple times within the collection, this will give undefined results! ForEach<Array<Item>, Int, ModifiedContent<ModifiedContent<ModifiedContent<ZStack<TupleView<(ModifiedContent<_ShapeView<RoundedRectangle, Color>, _AppearanceActionModifier>, ModifiedContent<Text, _PaddingLayout>)>>, _FrameLayout>, _FrameLayout>, _ScaleEffect>>: the ID 0 occurs multiple times within the collection, this will give undefined results!

in the console, is this ok? I guess that's how wrap works in this library?

dpyy avatar May 08 '23 03:05 dpyy