Pow Documentation

repository·main·Indexed 26 days ago

https://github.com/emergetools/pow

A SwiftUI library providing visual and haptic 'Change Effects' that trigger when values change, as well as smooth transitions. Features include a variety of effects like .spray, .jump, .ping, .shake, and .shine, along with specialized transitions accessed via the movingParts namespace such as anvil, blinds, iris, and vanish. Supports iOS 15.0+, macOS 12.0, Mac Catalyst 15.0+, and visionOS beta 6.

Tokens
3.2K
Snippets
27
Records
38
Agent score
88%

What's inside Pow

  1. Use Change Effects with the changeEffect modifier

    main

    Change Effects trigger a visual or haptic response whenever a monitored value changes. Use the .changeEffect(_:value:isEnabled:) modifier to apply an effect to a view.

    Note: You can also chain .delay(seconds) to any effect to postpone its execution.

    Button {
        post.toggleLike()
    } label: {
        Label(post.likes.formatted(), systemName: "heart.fill")
    }
    .changeEffect(.spray { heart }, value: post.likes, isEnabled: post.isLiked)
    .tint(post.isLiked ? .red : .gray)
  2. Install Pow via Swift Package Manager

    main

    To add Pow to your Xcode project, select File > Add Package and enter the repository URL: https://github.com/EmergeTools/Pow.

    To add it directly to a Package.swift file, add the dependency and the product as follows:

    .package(url: "https://github.com/EmergeTools/Pow", from: Version(1, 0, 0))
    
    // And to your target as a product:
    .product(name: "Pow", package: "Pow")
  3. Upgrade Pow from 0.x.x to 1.0.0

    main

    To upgrade Pow to version 1.0.0 or higher, you must manually update the package dependency because the transition from 0.x.x to 1.0.0 is a major version bump. Xcode's 'Up to Next Major Version' rule will not perform this update automatically.

    Swift Package Manager Update

    Update your package reference to use the new repository URL and the new version number:

    Old Reference:

    .package(url: "https://github.com/movingparts-io/Pow", from: Version(0, 3, 1))

    New Reference:

    .package(url: "https://github.com/EmergeTools/Pow", from: Version(1, 0, 0))

    Troubleshooting Xcode Errors

    If Swift Package Manager shows errors immediately after the upgrade, this is a known Xcode issue. The solution is to close and re-open Xcode.

    Verifying the Update

    Check the 'Package Dependencies' list in your Xcode File Navigator. You should see Pow version 1.0.0, and since the project is now open source, you should be able to see the source code in your project tree.

  4. Use Pow transitions via movingParts namespace

    main

    All Pow transitions are accessed through the movingParts static variable on the AnyTransition type. You apply them to a view using the .transition() modifier.

    Example usage:

    myView.transition(.movingParts.anvil)
    myView.transition(.movingParts.anvil)
  5. Configure the Spray Change Effect

    main

    The .spray effect emits multiple particles in different shades and sizes moving up from the origin point.

    likeButton
      .changeEffect(
        .spray(origin: .center) { Image(systemName: "heart.fill") },
        value: likes
      )
  6. Configure Haptic Feedback Change Effects

    main

    Pow provides several ways to trigger haptic feedback:

    • feedback(hapticNotification type: UINotificationFeedbackGenerator.FeedbackType): Triggers success, failure, or warning notifications.
    • feedback(hapticImpact style: UIImpactFeedbackGenerator.FeedbackStyle): Simulates physical impacts.
    • feedbackHapticSelection: Triggers feedback indicating a change in selection.