There is a favorite button in my view which has NavigationLink. Each time I press the favorite button, opacity animations also shows. I don't want to show any animation while I tapping the favorite buttons. I know how to remove animation at whole view, but I hope the animation works when I press outside of favorite buttons.
HStack {
Image(systemName: "a.book.closed.fill")
Text(book.name)
Spacer()
FavoriteButton(isFavorite: $isFavorite)
.onChange(of: isFavorite) { newValue in
book.isFavorite = newValue
model.saveData()
}
}
This is my book row view
ScrollView {
ForEach(model.savedBookEntities) { elem in
NavigationLink() {
VocaView(book: elem)
} label: {
BookRow(book: elem)
}
.contextMenu() {
// Some context menus
}
}
}
and this is my ScrollView in NavigationView
Animation happens on animatable parameter changing. If FavoriteButton
does not change anything else inside, then try to disable animation for isFavorite
, like
HStack {
Image(systemName: "a.book.closed.fill")
Text(book.name)
Spacer()
FavoriteButton(isFavorite: $isFavorite)
.onChange(of: isFavorite) { newValue in
book.isFavorite = newValue
model.saveData()
}
.animation(nil, value: isFavorite) // << here !!
}
//.animation(nil, value: isFavorite) // << or here !!
also book.isFavorite
might affect, so if above would not work for you try the same with book.isFavorite
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.