neumorphic icon indicating copy to clipboard operation
neumorphic copied to clipboard

Using .contextMenu deletes shadow when dismissing

Open LualdiD opened this issue 4 years ago • 4 comments

Any idea on how to fix that not so great animation when closing a context menu on one of these views?

LualdiD avatar Aug 08 '20 00:08 LualdiD

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.

costachung avatar Aug 08 '20 04:08 costachung

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

LualdiD avatar Aug 08 '20 08:08 LualdiD

I come up with a workaround which is adding a background view below the .contextMenu. However, it works only on Xcode 12 beta 4.

ezgif-4-990c08150d7e

            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.

costachung avatar Aug 10 '20 00:08 costachung

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 👍

LualdiD avatar Aug 10 '20 22:08 LualdiD