iOS 上的 SwiftUI 15,自定义 buttonStyle 不再工作,它在 iOS 上工作正常 14,如何修复?

SwiftUI on iOS 15, custom buttonStyle doesn't work anymore, it works fine on iOS 14, how to fix?

如标题所述。我在 iOS 14 上使用自定义 SwiftUI buttonStyle。它工作正常,但现在在 iOS 15 上不起作用。没有错误没有警告,我不知道如何处理它。有人知道要修复它吗?

struct InnerShadowButtonStyle: ButtonStyle {

    func makeBody(configuration: Configuration) -> some View {
        
        let p = configuration.isPressed
        
        return configuration.label
        
          .overlay (
            RoundedRectangle(cornerRadius: 0)
                .stroke(Color.clear, lineWidth: 4)
                .shadow(color: p ? .gray : .clear, radius: 3, x: 3, y: 3)
                .clipShape(RoundedRectangle(cornerRadius: 0))
                .opacity(p ? 1.0 : 0.0)
          )
    }
}

似乎 SwiftUI 3 根本不绘制透明矩形,因为您用 Color.clear 抚摸它。

你可以用 Color.black.opacity(0.001):

之类的东西强制它
configuration.label
    .overlay (
        RoundedRectangle(cornerRadius: 0)
            .stroke(Color.black.opacity(0.001), lineWidth: 4)
            .shadow(color: p ? .gray : .clear, radius: 3, x: 3, y: 3)
            .clipShape(RoundedRectangle(cornerRadius: 0))
            .opacity(p ? 1.0 : 0.0)
    )