joogps / Glur

A library for progressive blurs in SwiftUI.
https://apps.apple.com/app/glur/id6478063257
MIT License
1.33k stars 21 forks source link

Weird yellow background when using Glur on macOS #8

Open mpdifran opened 8 months ago

mpdifran commented 8 months ago

Hey all!

Loving the Glur library, super cool stuff. I've recently integrated it into my App Store screenshot app, and I've noticed some weird behaviour on macOS in particular.

Glur functions as expected on iOS and iPadOS, but when I view the same Glur on macOS, I get a yellow background. Have you seen this before? Any idea what's going on?

Note: The app tint is yellow, so perhaps the yellow is coming from there?

macOS iPadOS
Screenshot 2024-02-17 at 5 06 52 PM IMG_E5B58E6FF948-1
joogps commented 8 months ago

hey!

I think I know what this is. when SwiftUI isn't able to rasterize a view (such as through .drawingGroup) it displays a red prohibited icon over a yellow background.

this might be what's happening here, as your background view might not work with .drawingGroup on Mac specifically... is it just a gradient or is there something else?

joogps commented 8 months ago

also, this is such a great use of this effect. are you using it to make app previews?

mpdifran commented 8 months ago

Yeah that's the plan! I saw Glur, and I was like, this is such a cool effect to have in app screenshots, I have it integrate it haha.

Let me take a look at what is included in the item I'm blurring. Without revealing too much about the code I'm using to create the device frame, I'm using the following modifiers before applying the Glur effect:

.opacity Group to handle if conditions on modifiers .shadow .overlay .blendMode .onDrop .simultaneousGesture .onTapGesture .scaleEffect

I'm drawing the device at full size (somewhere around 1242 x 2688), then using scaleEffect to scale it down in the app, before applying Glur. I was having trouble getting Glur to work before the scale effect, but moving it to after seemed to help. I still have problems for certain large devices even after the scale, like iPads.

Here's my View extension that leverages Group:

public extension View {

    func `if`<Content: View>(_ condition: Bool, content: (Self) -> Content) -> some View {
        Group {
            if condition {
                content(self)
            } else {
                self
            }
        }
    }
}