Hello, I have the following code:
struct SettingsButton: View {
var action: () -> Void
@State private var rotate: Bool = false
var body: some View {
Button(action: {
rotate.toggle()
action()
}, label: {
Image(systemName: "gearshape")
})
.symbolEffect(.rotate, value: rotate)
}
}
For some reason, my button is not rotating. Other effects such as pulse and bounce work as expected. I applied the .clockwise direction thinking it needed a direction set, but that didn't work either. I also tried using the symbolEffect with isActive, and that didn't work. Lastly, I thought there may be an issue with Xcode so I closed that and reopened, but still not working.
Any ideas?
Post
Replies
Boosts
Views
Activity
My picker looks like this:
Picker("Color", selection: $backgroundColor.animation(), content: {
ForEach(TransactionCategory.Colors.allCases, id: \.self) { color in
Text(color.rawValue)
.tag(color)
.foregroundStyle(color.getColor())
}
})
This changes a tint color which is applied to the entire tabview. I can see that it's working because the buttons in the top tab bar are changing color as I change the picker value. However, the color of the text inside the picker is not changing until I go back one view and then come back to this view. I tried setting an ID on the picker and then updating it when the picker value changes, but that didn't work.
Any ideas?
Wrapping views with a VStack breaks animation, but using an extension to do the same thing fixes it.
I was having issues with views transitioning between being visible and not visible inside of List. They would appear, but the animation would be jerky. I switched to using a Section, and the animation looked much better. However, the spacing between views and padding wasn't what I wanted. So I wrapped some of the views inside the Section with a VStack.
But first, this is how my view SectionView looks:
struct SectionView<Content: View>: View {
let title: String
@ViewBuilder var content: () -> Content
var body: some View {
Section {
Text(title)
.font(.title3.bold())
content()
}
.listRowInsets(EdgeInsets(top: 10, leading: 20, bottom: 10, trailing: 20))
.listRowBackground(Color.clear)
.listRowSeparator(.hidden)
.contentShape(.rect)
}
}
Below was in a separate view:
SectionView(title: "Title") {
Group {
HStack {
// Stuff here
}
if let selectedMonth {
VStack(alignment: .leading, spacing: 10) {
// Stuff here
}
}
}
.animation(.smooth, value: selectedMonth)
}
This, however, broke the animations again when the VStack appears. It went back to being jerky. So instead of wrapping the content inside of a VStack, I created an extension to do the same thing.
extension View {
@ViewBuilder
func condensed() -> some View {
VStack(alignment: .leading, spacing: 10, content: {
self
})
}
}
So now instead of wrapping it in a VStack, I do this:
if let selectedMonth {
Group {
// Stuff here
}
.condensed()
}
The animations look good again. I just can't figure out why that is. Can anyone help me understand this?