markiv / SwiftUI-Shimmer

Shimmer is a super-light modifier that adds a shimmering effect to any SwiftUI View, for example, to show that an operation is in progress. It works well on light and dark modes, and across iOS, macOS, tvOS, watchOS and visionOS.
MIT License
1.04k stars 60 forks source link

Custom Gradient Support #7

Open LePips opened 1 year ago

LePips commented 1 year ago

Hello there 👋

I'm going to be using a shimmer in my application and thought this package was great! However, I desired more customization over the gradient.

Overview

I change GradientMask to supply the definition used for the underlying LinearGradient. The default values match the current gradient.

Example ```swift Text("Shimmering") .shimmering(gradientMask: .init( centerOpacity: 0.8, edgeOpacity: 0.3, startPoint: .topLeading, endPoint: .bottomTrailing, width: 0.1)) ```

Since GradientMask.startPoint and GradientMask.endPoint are properties, this allows the gradient to "move" in different directions. Due to this, I think that this overrides #4.

Right to Left Example https://user-images.githubusercontent.com/20747774/201496531-581444e8-5d9e-4204-82bf-802ce0ec05ee.mov
Top to Bottom Example https://user-images.githubusercontent.com/20747774/201496550-99f90a1a-9c99-4b07-ab97-d48116244210.mov

Inverse mask

Currently, the gradient is applied as a plain .mask(...) which doesn't suite my needs, as it changes the opacity of the underlying view to the opacity of the edge points of the LinearGradient, and I don't think that a shimmer should change the opacity of the underlying view. GradientMask.inverse determines whether the mask should be inverted or not, therefore having the shimmer effect be the gradient itself, and not a mask over the gradient. I personally think this should be the default behavior but I won't change the current implementation.

Current Implementation Example https://user-images.githubusercontent.com/20747774/201496252-16c66f36-68ee-4034-8ad5-6b414892965d.mov
Inverted Mask Example https://user-images.githubusercontent.com/20747774/201496481-64b57e6b-e59d-4c8b-b9b9-ba7528bebda1.mov

Other

mickey-at-easelapps-ai commented 1 year ago

Is this going to be merged? This seems like a reasonable pull request...