Scintillate

1.1.0

A UIKit+AppKit-friendly way to either mask content, or show a loading state. Think: SwiftUI's 'redacted' modifier, for non-SwiftUI applications.
alexslee/Scintillate

Scintillate

A lightweight, UIKit+AppKit-friendly way to either mask content, or show a loading state. Think: SwiftUI's 'redacted' modifier, for non-SwiftUI applications on iOS + macOS.

Internal implementation

You can look through the code, but tl;dr, the effect is recursively applied as a CALayer per subview* (with optional use of CAGradientLayer and CAAnimation depending on your settings). These layers should be removed automatically for you when the effect is shut down.

(* Note: 'per subview' here refers to the absolute bottoms of the view hierarchy. I.e., thinking of it as a tree data structure, the effect will only be applied to leaves.)

Also...

I don't have much in the way of AppKit experience, so it may not function as smoothly with NSViews as it does for UIViews. Let me know if anything pops up there.

Usage

Setup

  1. Install the package, which can be done via Swift Package Manager.

  2. Decide where you want to invoke the scintillating effect. To start it, you just need to provide the root view within which you want to apply the effect (remember it's recursive!), and any custom settings you wish.

For instance:

    Scintillate.kickStart(in: stackView)

would start the scintillating effect with default settings (no animation, and a default color).

To turn the effect off, simply call shutDown on the same view:

    Scintillate.shutDown(in: stackView)

Customizing the effect

This can be done via a ScintillateSettings that you may construct and pass into the kickStart method. It allows you to enable animation (default is off), render the mask as a gradient, and customize a color (if you choose to animate and/or make the mask a gradient without specifying a secondary color, one will be interpreted based on the primary color).

TODOs:

  • Check tablet appearance + fix rotation behaviour
  • Make color customizable
  • Actually make them shiny (read: animate the layers)
  • Add more options for customization (maybe)
  • Refine animation speed (and maybe make customizable ^)
  • All the bugfixes

Description

  • Swift Tools 5.5.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sun Sep 04 2022 04:33:28 GMT-0500 (GMT-05:00)