pointfreeco / swift-snapshot-testing

📸 Delightful Swift snapshot testing.

Home Page:https://www.pointfree.co/episodes/ep41-a-tour-of-snapshot-testing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ability to disable alpha channel from image snapshots

NachoSoto opened this issue · comments

Looks like there is no way to make snapshots opaque? It would save a lot of space to remove the alpha channel when not needed.

We wanted this as well, though for a different reason #673 (comment)

We made a custom Snapshotting instance named opaqueImage that always adds a white background to the image. I'm not sure it reduces the file size, but it's a step closer to being able to do that.

Snapshotting<UIView, UIImage>
    .image(
        size: size,
        traits: traits
    )
    .pullback { view in
        let backgroundView = UIView(frame: view.frame)
        backgroundView.backgroundColor = .white
        backgroundView.preservesSuperviewLayoutMargins = true
        backgroundView.addSubview(view)
        return backgroundView
    }