neumorphic
neumorphic copied to clipboard
Using .contextMenu deletes shadow when dismissing
Any idea on how to fix that not so great animation when closing a context menu on one of these views?
It looks like that the .contextMenu animation messed up with mask or clipShape. I am not sure if it is a bug on contextMenu.
Adding .contentShape fix the clipping problem. https://stackoverflow.com/questions/62741902/contextmenu-on-a-rounded-lineargradient-produces-sharp-edges-in-swiftui
Button(action: {}) {
Text("Tap me!")
}.softButtonStyle(Capsule())
.contentShape(Capsule())
.contextMenu {
Button(action: {}) {
Text("Option")
Image(systemName: "globe")
}
}
It's better but it's still not looking great.
Yeah, I'm doing that on my view already and with softOuterShadow it looks fine I open the contextMenu, but yes when I close it the shadow is gone for a second and then it jumps back in. Trying to figure out a workaround for that but had no luck so far
I come up with a workaround which is adding a background view below the .contextMenu. However, it works only on Xcode 12 beta 4.
Button(action: {}) {
Text("Button").fontWeight(.bold)
}
.softButtonStyle(Capsule(), pressedEffect: .none)
.contentShape(Capsule())
.contextMenu(
ContextMenu(menuItems: {
Text("Menu Item 1")
Text("Menu Item 2")
}
))
.background(
Capsule().fill(Neumorphic.shared.mainColor()).softOuterShadow()
)
I 've release a new version v1.2.1 that you can change the pressed effect in soft button style. You can change the pressedEffect to .none so that the button won't show the inner shadow when it is pressed.
Nice I'm actually using on a view not a button but the workaround did the trick, I had to a background above and below the contextMenu but the animation is much better now 👍