From 897afcde740dac3ec923a516fc08dc16558dab78 Mon Sep 17 00:00:00 2001 From: noahsmartin Date: Tue, 26 Dec 2023 17:31:16 -0800 Subject: [PATCH] Add package (#50) --- Example/Pow Example.xcodeproj/project.pbxproj | 20 ++++++++++ .../Examples/Screens/CheckoutExample.swift | 2 + Fastlane/Fastfile | 4 ++ Package.swift | 6 ++- Sources/Pow/Effects/SmokeEffect.swift | 38 +++++++++++-------- Sources/Pow/Transitions/Anvil.swift | 6 +++ Sources/Pow/Transitions/Boing.swift | 9 +++++ Sources/Pow/Transitions/Clock.swift | 6 +++ Sources/Pow/Transitions/Glare.swift | 6 +++ Sources/Pow/Transitions/Skid.swift | 6 +++ Sources/Pow/Transitions/Vanish.swift | 6 +++ 11 files changed, 93 insertions(+), 16 deletions(-) diff --git a/Example/Pow Example.xcodeproj/project.pbxproj b/Example/Pow Example.xcodeproj/project.pbxproj index 492ae16..8feb6ef 100644 --- a/Example/Pow Example.xcodeproj/project.pbxproj +++ b/Example/Pow Example.xcodeproj/project.pbxproj @@ -103,6 +103,7 @@ 54F15E5429D59D250054690B /* PulseExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54F15E5329D59D250054690B /* PulseExample.swift */; }; 54F15E5629D5A0D70054690B /* GlowExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54F15E5529D5A0D70054690B /* GlowExample.swift */; }; B7A5DA8D2B0E853A0035FC0A /* Pow in Frameworks */ = {isa = PBXBuildFile; productRef = B7A5DA8C2B0E853A0035FC0A /* Pow */; }; + FA13B8ED2B3BAF5600F58836 /* SnapshotPreferences in Frameworks */ = {isa = PBXBuildFile; productRef = FA13B8EC2B3BAF5600F58836 /* SnapshotPreferences */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -212,6 +213,7 @@ buildActionMask = 2147483647; files = ( B7A5DA8D2B0E853A0035FC0A /* Pow in Frameworks */, + FA13B8ED2B3BAF5600F58836 /* SnapshotPreferences in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -420,6 +422,7 @@ name = "Pow Example"; packageProductDependencies = ( B7A5DA8C2B0E853A0035FC0A /* Pow */, + FA13B8EC2B3BAF5600F58836 /* SnapshotPreferences */, ); productName = "Pow Example"; productReference = 546A2986292A31BB00A80DE2 /* Pow Example.app */; @@ -450,6 +453,7 @@ ); mainGroup = 546A297D292A31BB00A80DE2; packageReferences = ( + FA13B8EB2B3BAF5600F58836 /* XCRemoteSwiftPackageReference "SnapshotPreviews-iOS" */, ); productRefGroup = 546A2987292A31BB00A80DE2 /* Products */; projectDirPath = ""; @@ -777,11 +781,27 @@ }; /* End XCConfigurationList section */ +/* Begin XCRemoteSwiftPackageReference section */ + FA13B8EB2B3BAF5600F58836 /* XCRemoteSwiftPackageReference "SnapshotPreviews-iOS" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/EmergeTools/SnapshotPreviews-iOS"; + requirement = { + kind = exactVersion; + version = 0.7.6; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + /* Begin XCSwiftPackageProductDependency section */ B7A5DA8C2B0E853A0035FC0A /* Pow */ = { isa = XCSwiftPackageProductDependency; productName = Pow; }; + FA13B8EC2B3BAF5600F58836 /* SnapshotPreferences */ = { + isa = XCSwiftPackageProductDependency; + package = FA13B8EB2B3BAF5600F58836 /* XCRemoteSwiftPackageReference "SnapshotPreviews-iOS" */; + productName = SnapshotPreferences; + }; /* End XCSwiftPackageProductDependency section */ }; rootObject = 546A297E292A31BB00A80DE2 /* Project object */; diff --git a/Example/Pow Example/Examples/Screens/CheckoutExample.swift b/Example/Pow Example/Examples/Screens/CheckoutExample.swift index 22ef47d..78ee083 100644 --- a/Example/Pow Example/Examples/Screens/CheckoutExample.swift +++ b/Example/Pow Example/Examples/Screens/CheckoutExample.swift @@ -1,5 +1,6 @@ import Pow import SwiftUI +import SnapshotPreferences struct CheckoutExample: View, Example { enum PaymentError: Error { @@ -271,5 +272,6 @@ struct CheckoutExample_Previews: PreviewProvider { CheckoutExample() .toolbar(.visible, for: .navigationBar) } + .emergeSnapshotPrecision(0.99) } } diff --git a/Fastlane/Fastfile b/Fastlane/Fastfile index 5277c06..3d791d7 100644 --- a/Fastlane/Fastfile +++ b/Fastlane/Fastfile @@ -3,6 +3,10 @@ fastlane_require 'git' default_platform(:ios) def build_for_config(config) + + package_file = "../Package.swift" + `sed -i '' 's/let enablePreviews = .*/let enablePreviews = #{config == "Debug" ? "true" : "false"}/' "#{package_file}"` + g = Git.open('.') build_app( project: "./Example/Pow Example.xcodeproj", diff --git a/Package.swift b/Package.swift index 86cd4ff..a27f82d 100644 --- a/Package.swift +++ b/Package.swift @@ -3,6 +3,8 @@ import PackageDescription +let enablePreviews = false + let package = Package( name: "Pow", platforms: [ @@ -19,13 +21,15 @@ let package = Package( dependencies: [ // Dependencies declare other packages that this package depends on. // .package(url: /* package url */, from: "1.0.0"), + .package(url: "https://github.com/EmergeTools/SnapshotPreviews-iOS", exact: "0.7.6") ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. // Targets can depend on other targets in this package, and on products in packages this package depends on. .target( name: "Pow", - dependencies: []), + dependencies: enablePreviews ? [.product(name: "SnapshotPreferences", package: "SnapshotPreviews-iOS", condition: .when(platforms: [.iOS]))] : [], + swiftSettings: enablePreviews ? [.define("EMG_PREVIEWS")] : nil), .testTarget( name: "PowTests", dependencies: ["Pow"]), diff --git a/Sources/Pow/Effects/SmokeEffect.swift b/Sources/Pow/Effects/SmokeEffect.swift index a2141c6..660ed7f 100644 --- a/Sources/Pow/Effects/SmokeEffect.swift +++ b/Sources/Pow/Effects/SmokeEffect.swift @@ -1,5 +1,8 @@ import SwiftUI import simd +#if os(iOS) && EMG_PREVIEWS +import SnapshotPreferences +#endif public extension AnyConditionalEffect { /// An effect that emits smoke from the view. @@ -336,30 +339,35 @@ struct ContinuousParticleEffect_Previews: PreviewProvider { } static var previews: some View { + Group { Preview() - .preferredColorScheme(.dark) - .previewDisplayName("Dark") + .preferredColorScheme(.dark) + .previewDisplayName("Dark") Preview() - .preferredColorScheme(.light) - .previewDisplayName("Light") + .preferredColorScheme(.light) + .previewDisplayName("Light") PreviewS() - .preferredColorScheme(.dark) - .previewDisplayName("Small") + .preferredColorScheme(.dark) + .previewDisplayName("Small") Preview2() - .preferredColorScheme(.dark) - .previewDisplayName("Large") + .preferredColorScheme(.dark) + .previewDisplayName("Large") Preview3() - .preferredColorScheme(.dark) - .previewDisplayName("Particle Layer") + .preferredColorScheme(.dark) + .previewDisplayName("Particle Layer") - #if os(iOS) +#if os(iOS) PreviewLayer() - .previewDisplayName("Emitter Layer") - #endif + .previewDisplayName("Emitter Layer") +#endif PreviewAlt() - .preferredColorScheme(.dark) - .previewDisplayName("Emitter Dark") + .preferredColorScheme(.dark) + .previewDisplayName("Emitter Dark") + } + #if os(iOS) && EMG_PREVIEWS + .emergeSnapshotPrecision(0) + #endif } } #endif diff --git a/Sources/Pow/Transitions/Anvil.swift b/Sources/Pow/Transitions/Anvil.swift index c89a5c2..073f629 100644 --- a/Sources/Pow/Transitions/Anvil.swift +++ b/Sources/Pow/Transitions/Anvil.swift @@ -1,4 +1,7 @@ import SwiftUI +#if os(iOS) && EMG_PREVIEWS +import SnapshotPreferences +#endif public extension AnyTransition.MovingParts { /// A transition that drops the view down from the top. @@ -280,6 +283,9 @@ struct Anvil_Previews: PreviewProvider { .navigationBarHidden(true) } .environment(\.colorScheme, .dark) + #if os(iOS) && EMG_PREVIEWS + .emergeSnapshotPrecision(0) + #endif } } #endif diff --git a/Sources/Pow/Transitions/Boing.swift b/Sources/Pow/Transitions/Boing.swift index f72318c..81748fa 100644 --- a/Sources/Pow/Transitions/Boing.swift +++ b/Sources/Pow/Transitions/Boing.swift @@ -1,4 +1,7 @@ import SwiftUI +#if os(iOS) && EMG_PREVIEWS +import SnapshotPreferences +#endif public extension AnyTransition.MovingParts { /// A transition that moves the view down with any overshoot resulting in an @@ -218,6 +221,9 @@ struct Bounce_Previews: PreviewProvider { .navigationBarHidden(true) } .environment(\.colorScheme, .dark) + #if os(iOS) && EMG_PREVIEWS + .emergeSnapshotPrecision(0) + #endif } } @@ -290,6 +296,9 @@ struct Boing_2_Previews: PreviewProvider { NavigationView { Preview() } + #if os(iOS) && EMG_PREVIEWS + .emergeSnapshotPrecision(0) + #endif } } #endif diff --git a/Sources/Pow/Transitions/Clock.swift b/Sources/Pow/Transitions/Clock.swift index c8108a2..86a8c28 100644 --- a/Sources/Pow/Transitions/Clock.swift +++ b/Sources/Pow/Transitions/Clock.swift @@ -1,4 +1,7 @@ import SwiftUI +#if os(iOS) && EMG_PREVIEWS +import SnapshotPreferences +#endif public extension AnyTransition.MovingParts { /// A transition using a clockwise sweep around the centerpoint of the view. @@ -225,6 +228,9 @@ struct Clock_Previews: PreviewProvider { .navigationBarHidden(true) } .environment(\.colorScheme, .dark) + #if os(iOS) && EMG_PREVIEWS + .emergeSnapshotPrecision(0) + #endif } } #endif diff --git a/Sources/Pow/Transitions/Glare.swift b/Sources/Pow/Transitions/Glare.swift index 508f29a..767aba2 100644 --- a/Sources/Pow/Transitions/Glare.swift +++ b/Sources/Pow/Transitions/Glare.swift @@ -1,4 +1,7 @@ import SwiftUI +#if os(iOS) && EMG_PREVIEWS +import SnapshotPreferences +#endif public extension AnyTransition.MovingParts { /// A transitions that shows the view by combining a diagonal wipe with a @@ -254,6 +257,9 @@ struct Glare_Previews: PreviewProvider { .navigationBarHidden(true) } .environment(\.colorScheme, .dark) + #if os(iOS) && EMG_PREVIEWS + .emergeSnapshotPrecision(0) + #endif } } #endif diff --git a/Sources/Pow/Transitions/Skid.swift b/Sources/Pow/Transitions/Skid.swift index e91a07c..b530d6e 100644 --- a/Sources/Pow/Transitions/Skid.swift +++ b/Sources/Pow/Transitions/Skid.swift @@ -1,4 +1,7 @@ import SwiftUI +#if os(iOS) && EMG_PREVIEWS +import SnapshotPreferences +#endif public extension AnyTransition.MovingParts { /// The direction from which to animate in during a `skid` transition's insertion. @@ -182,6 +185,9 @@ struct Skid_Previews: PreviewProvider { .navigationBarHidden(true) } .environment(\.colorScheme, .dark) + #if os(iOS) && EMG_PREVIEWS + .emergeSnapshotPrecision(0) + #endif } } diff --git a/Sources/Pow/Transitions/Vanish.swift b/Sources/Pow/Transitions/Vanish.swift index 99a704f..8eb8bf7 100644 --- a/Sources/Pow/Transitions/Vanish.swift +++ b/Sources/Pow/Transitions/Vanish.swift @@ -1,4 +1,7 @@ import SwiftUI +#if os(iOS) && EMG_PREVIEWS +import SnapshotPreferences +#endif public extension AnyTransition.MovingParts { /// A transition that dissolves the view into many small particles. @@ -236,6 +239,9 @@ struct Vanish_Previews: PreviewProvider { .navigationBarHidden(true) } .environment(\.colorScheme, .dark) + #if os(iOS) && EMG_PREVIEWS + .emergeSnapshotPrecision(0) + #endif } } #endif