Shiny SwiftUI Library

repository·master·Indexed 22 days ago

https://github.com/maustinstar/shiny

A SwiftUI library that adds motion-based texture and lighting effects to views using the device's gyroscope. It provides the .shiny() modifier with several predefined gradient styles, including .rainbow, .iridescent, .matte, .glossy, and .hyperGlossy, as well as support for custom gradients to simulate realistic light movement.

Tokens
1.4K
Snippets
9
Records
9
Agent score
76%

What's inside Shiny

  1. Install the Shiny package

    master

    You can add Shiny to your project using either Xcode's built-in package manager or by modifying your Package.swift file for Swift Packages.

    ### For Xcode Projects
    File > Swift Packages > Add Package Dependency: https://github.com/maustinstar/shiny
    
    ### For Swift Packages
    ```swift
    .package(url: "https://github.com/maustinstar/shiny.git", from: "0.0.1"),
  2. Use the .shiny() modifier on SwiftUI views

    master

    To add motion-based texture effects to a SwiftUI view, import Shiny and apply the .shiny() modifier. This modifier uses the device's gyroscope to simulate lighting and motion effects on colors, drawing attention to interface elements like Text, Toggle, or VStack.

    import Shiny
    ...
    Text("Hello, shiny world! ✨").shiny()
  3. Apply glossy and matte effects with .shiny()

    master

    Use .shiny(.glossy(color)) to create a glossy text effect and .shiny(.matte(color)) to create a matte background effect. For example, applying .shiny(.glossy(.black)) to text and .shiny(.matte(.black)) to a RoundedRectangle creates glossy text on a matte black card.

    Text("shiny")
        .font(.largeTitle)
        .fontWeight(.bold).shiny(.glossy(.black))
        .background(
            RoundedRectangle(cornerRadius: 14.0)
                .frame(width: 200.0, height: 70.0)
                .shiny(.matte(.black)))
  4. Apply advanced shiny effects with parameters

    master

    The .shiny() modifier can be customized with specific styles. For example, you can use .hyperGlossy(color) to apply a high-gloss effect to a background. This allows you to layer effects, such as applying rainbow text on top of a glossy card.

    Text("shiny")
        .font(.largeTitle)
        .fontWeight(.bold).shiny()
        .background(
            RoundedRectangle(cornerRadius: 14.0)
                .frame(width: 200.0, height: 70.0)
                .shiny(.hyperGlossy(UIColor.systemGray5)))
  5. Apply rainbow effects with .shiny()

    master

    You can apply a rainbow effect to text and use .hyperGlossy on shapes to create a high-contrast, colorful look. For example, applying .shiny() to a Text view and .shiny(.hyperGlossy(UIColor.systemGray5)) to a RoundedRectangle background creates rainbow text on a silver card.

    Text("shiny")
        .font(.largeTitle)
        .fontWeight(.bold).shiny()
        .background(
            RoundedRectangle(cornerRadius: 14.0)
                .frame(width: 200.0, height: 70.0)
                .shiny(.hyperGlossy(UIColor.systemGray5)))
  6. Apply iridescent effects with .shiny()

    master

    Combine .shiny(.iridescent) on text with .shiny(.glossy(color)) on a background shape to create an iridescent text effect on a glossy card.

    Text("shiny")
        .font(.largeTitle)
        .fontWeight(.bold).shiny(.iridescent)
        .background(
            RoundedRectangle(cornerRadius: 14.0)
                .frame(width: 200.0, height: 70.0)
                .shiny(.glossy(.black)))
  7. Use built-in shiny gradients

    master

    The .shiny() modifier accepts several predefined gradient styles to change the visual character of the surface:

    • .rainbow: Cycles through system colors in rainbow order (default).
    • .iridescent: Cycles through translucent blues and purples for a sparkling effect.
    • .matte(UIColor): Generates a matte surface from a provided color, modeling a dispersed light source.
    • .glossy(UIColor): Generates a surface from a provided color, modeling a focused light source.
    • .hyperGlossy(UIColor): Generates a surface from a provided color, modeling an intense light source.
    // Examples of different styles
    Text("Rainbow").shiny(.rainbow)
    Text("Iridescent").shiny(.iridescent)
    Text("Matte").shiny(.matte(.yellow))
    Text("Glossy").shiny(.glossy(.blue))
    Text("Hyper Glossy").shiny(.hyperGlossy(.blue))