I am attempting to replace the dimensions of a ScrollView merchandise view on faucet gesture however in the meanwhile nothing appears to occur aside from the debugger logging the next:
onChange(of: Elective<AnimalItem>) motion tried to replace a number of occasions per body.
The code is as follows:
struct AnimalItem: Identifiable, Equatable {
non-public(set) var id: UUID = .init()
var textual content: String
var picture: String
var expanded = false
}
struct AnimalItemView: View {
@State var merchandise: AnimalItem
var physique: some View {
Picture(merchandise.expanded ? merchandise.picture : merchandise.textual content)
.resizable()
.scaledToFill()
.body(width: merchandise.expanded ? 350 : 200, top: 250)
.clipShape(RoundedRectangle(cornerRadius: 10))
}
}
struct AnimalCarousalView: View {
@State var objects: [AnimalItem] = [
.init(text: "A", image: "alligator"),
.init(text: "B", image: "bear"),
.init(text: "C", image: "cat")
]
@State var selectedItem: AnimalItem?
var physique: some View {
ScrollView(.horizontal) {
LazyHStack(spacing: 10) {
ForEach(objects, id: .id) { merchandise in
AnimalItemView(merchandise: merchandise)
.clipShape(RoundedRectangle(cornerRadius: 10))
.onTapGesture {
selectedItem = merchandise
}
}
}
}
.body(top: 250)
.contentShape(Rectangle())
.scrollIndicators(.hidden)
.clipped()
.onChange(of: selectedItem) { _ in
withAnimation {
selectedItem?.expanded.toggle()
}
}
}
}
What I wish to obtain is for the Picture
in AnimalItemView
to develop in width when tapped and shrink when tapped once more. Additionally at any time, I might like for just one scroll merchandise view to remain expanded. At present, nothing occurs after I faucet on the view. Aside from this, I additionally appear to require the clipShape
modifier utilized to the AnimalItemView
as nicely. If I do not, the AnimalItemView
solely appears to have a rounded clip for the underside edges & the highest edges seem flat. Lastly, it does not appear right to have the enlargement property expanded
be inside AnimalItem
, although I could be mistaken? Any assistance is appreciated.