Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing in binding for index disables animations. #6

Open
josephmannis opened this issue Feb 12, 2021 · 3 comments
Open

Passing in binding for index disables animations. #6

josephmannis opened this issue Feb 12, 2021 · 3 comments

Comments

@josephmannis
Copy link

josephmannis commented Feb 12, 2021

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

@miguel-arrf
Copy link

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!

@norrisboat
Copy link

@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

@dpyy
Copy link

dpyy commented May 8, 2023

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants