LiquidGlassKit

repository·master·Indexed 18 days ago

https://github.com/dnv1ex/liquidglasskit

A design system backport that brings iOS 26 'Liquid Glass' visual effects to iOS 13 through 18. It provides Metal-based rendering for components including LiquidGlassSlider, LiquidGlassSwitch, and LiquidGlassEffectView, featuring refraction, chromatic dispersion, and Fresnel reflections. The library includes factory methods for version-based implementation selection and a ZeroCopyBridge utility using IOSurface for Metal texture bridging.

Tokens
1.1K
Snippets
3
Records
5
Agent score
14%

What's inside LiquidGlassKit

  1. Overview of LiquidGlassKit components

    master

    LiquidGlassKit provides drop-in replacements for standard UIKit components to replicate the iOS 26 liquid glass design system on iOS 13+.

    Core Rendering

    • LiquidGlassView: The engine using Metal shaders for refraction, chromatic dispersion, Fresnel reflections, glare highlights, and shape merging. It uses CABackdropLayer or a root view rendering fallback for App Store safety.
    • ZeroCopyBridge: A utility using IOSurface to bridge rendering into Metal textures without unnecessary memory copies.

    UI Components

    • LiquidLensView: A replacement for _UILiquidLensView. Features include resting/lifted states and acceleration-based animations. Conforms to AnyLiquidLensView.
    • LiquidGlassEffectView: A UIVisualEffectView-compatible wrapper. Supports LiquidGlassEffect (regular/clear) and LiquidGlassContainerEffect. Conforms to AnyVisualEffectView.
    • LiquidGlassSlider: A UISlider replacement with dual thumb states (contracted/expanded), rubber-band physics, and haptic feedback. Conforms to AnySlider.
    • LiquidGlassSwitch: A UISwitch replacement with dual thumb states, edge-based toggling, and haptic feedback. Conforms to AnySwitch.
  2. Use factory methods to instantiate components

    master

    LiquidGlassKit provides factory methods that automatically handle implementation selection based on the iOS version. If you set isNative: true, the library will use the native iOS 26+ implementation when available and fall back to the custom LiquidGlassKit implementation on older versions. If isNative: false (or omitted/default behavior on older versions), it uses the recreated components.

    Common factory patterns include:

    • LiquidGlassSwitch.make(isNative:)
    • LiquidGlassSlider.make(isNative:)
    • VisualEffectView(effect: LiquidGlassEffect(style: .regular, isNative: true))
    // Automatically uses native UISwitch on iOS 26+, custom on older versions
    let switch = LiquidGlassSwitch.make(isNative: true)
    
    // Automatically uses native UISlider on iOS 26+, custom on older versions
    let slider = LiquidGlassSlider.make(isNative: true)
    
    // Automatically uses native UIVisualEffectView on iOS 26+, custom on older versions
    let effectView = VisualEffectView(effect: LiquidGlassEffect(style: .regular, isNative: true))
  3. Install LiquidGlassKit via Swift Package Manager

    master

    To integrate LiquidGlassKit into your iOS project, use Swift Package Manager (SPM). You can add it by modifying your Package.swift file or by using the Xcode interface.

    Via Package.swift

    Add the following dependency to your manifest:

    dependencies: [
        .package(url: "https://github.com/yourusername/LiquidGlassKit.git", from: "1.0.0")
    ]

    Via Xcode

    1. Go to FileAdd Packages...
    2. Enter the repository URL: https://github.com/yourusername/LiquidGlassKit.git
    3. Select the desired version or branch.
  4. Implement UILiquidLensView for iOS 26 compatibility

    master

    To use the liquid lens effect in a way that is compatible with the private _UILiquidLensView used in iOS 26's UITabBar, you must dynamically add the AnyLiquidLensView protocol to the native class if it exists. This allows the native class to be treated as a UILiquidLensView in your code.

    On versions older than iOS 26, you should use the custom LiquidLensView provided by the library.

    var liquidLensView: UILiquidLensView?
    
    if #available(iOS 26.0, *) {
        let viewClass: AnyClass? = NSClassFromString("_UILiquidLensView")
        class_addProtocol(viewClass, AnyLiquidLensView.self)
        liquidLensView = (viewClass as? AnyLiquidLensView.Type)?.init() as? UILiquidLensView
    } else {
        liquidLensView = LiquidLensView()
    }