diff --git a/Example/ColorfulApp.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Example/ColorfulApp.xcworkspace/xcshareddata/swiftpm/Package.resolved index 74b516f..c9b579e 100644 --- a/Example/ColorfulApp.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Example/ColorfulApp.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -14,8 +14,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/Lakr233/SpringInterpolation.git", "state" : { - "revision" : "be8721cffc87ec514fa13ba5dab586a2730f51c9", - "version" : "1.1.2" + "revision" : "ff526fec3ef6df62395141a0cc55a4ba2d82ee81", + "version" : "1.2.2" } } ], diff --git a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/Contents.json b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/Contents.json index aaaaaad..2808f8c 100644 --- a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -1,67 +1,67 @@ { "images" : [ { - "filename" : "RoundedIconTemplate.png", + "filename" : "新建项目.png", "idiom" : "universal", "platform" : "ios", "size" : "1024x1024" }, { - "filename" : "icon_16x16.png", + "filename" : "icon-16.png", "idiom" : "mac", "scale" : "1x", "size" : "16x16" }, { - "filename" : "icon_16x16@2x.png", + "filename" : "icon-16@2x.png", "idiom" : "mac", "scale" : "2x", "size" : "16x16" }, { - "filename" : "icon_32x32.png", + "filename" : "icon-32.png", "idiom" : "mac", "scale" : "1x", "size" : "32x32" }, { - "filename" : "icon_32x32@2x.png", + "filename" : "icon-32@2x.png", "idiom" : "mac", "scale" : "2x", "size" : "32x32" }, { - "filename" : "icon_128x128.png", + "filename" : "icon-128.png", "idiom" : "mac", "scale" : "1x", "size" : "128x128" }, { - "filename" : "icon_128x128@2x.png", + "filename" : "icon-128@2x.png", "idiom" : "mac", "scale" : "2x", "size" : "128x128" }, { - "filename" : "icon_256x256.png", + "filename" : "icon-256.png", "idiom" : "mac", "scale" : "1x", "size" : "256x256" }, { - "filename" : "icon_256x256@2x.png", + "filename" : "icon-256@2x.png", "idiom" : "mac", "scale" : "2x", "size" : "256x256" }, { - "filename" : "icon_512x512.png", + "filename" : "icon-512.png", "idiom" : "mac", "scale" : "1x", "size" : "512x512" }, { - "filename" : "icon_512x512@2x.png", + "filename" : "icon-512@2x.png", "idiom" : "mac", "scale" : "2x", "size" : "512x512" diff --git a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/RoundedIconTemplate.png b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/RoundedIconTemplate.png deleted file mode 100644 index 03473fb..0000000 Binary files a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/RoundedIconTemplate.png and /dev/null differ diff --git a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon-128.png b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon-128.png new file mode 100644 index 0000000..6de8b91 Binary files /dev/null and b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon-128.png differ diff --git a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon-128@2x.png b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon-128@2x.png new file mode 100644 index 0000000..65f4172 Binary files /dev/null and b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon-128@2x.png differ diff --git a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon-16.png b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon-16.png new file mode 100644 index 0000000..1fbf559 Binary files /dev/null and b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon-16.png differ diff --git a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon-16@2x.png b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon-16@2x.png new file mode 100644 index 0000000..1c93e81 Binary files /dev/null and b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon-16@2x.png differ diff --git a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon-256.png b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon-256.png new file mode 100644 index 0000000..65f4172 Binary files /dev/null and b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon-256.png differ diff --git a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon-256@2x.png b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon-256@2x.png new file mode 100644 index 0000000..2ce8711 Binary files /dev/null and b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon-256@2x.png differ diff --git a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon-32.png b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon-32.png new file mode 100644 index 0000000..1c93e81 Binary files /dev/null and b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon-32.png differ diff --git a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon-32@2x.png b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon-32@2x.png new file mode 100644 index 0000000..bf2ef5f Binary files /dev/null and b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon-32@2x.png differ diff --git a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon-512.png b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon-512.png new file mode 100644 index 0000000..2ce8711 Binary files /dev/null and b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon-512.png differ diff --git a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon-512@2x.png b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon-512@2x.png new file mode 100644 index 0000000..d74b43c Binary files /dev/null and b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon-512@2x.png differ diff --git a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon_128x128.png b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon_128x128.png deleted file mode 100644 index ae8f6a6..0000000 Binary files a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon_128x128.png and /dev/null differ diff --git a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon_128x128@2x.png b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon_128x128@2x.png deleted file mode 100644 index dca5d7c..0000000 Binary files a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon_128x128@2x.png and /dev/null differ diff --git a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon_16x16.png b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon_16x16.png deleted file mode 100644 index d09fa17..0000000 Binary files a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon_16x16.png and /dev/null differ diff --git a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon_16x16@2x.png b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon_16x16@2x.png deleted file mode 100644 index 08d872e..0000000 Binary files a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon_16x16@2x.png and /dev/null differ diff --git a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon_256x256.png b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon_256x256.png deleted file mode 100644 index dca5d7c..0000000 Binary files a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon_256x256.png and /dev/null differ diff --git a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon_256x256@2x.png b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon_256x256@2x.png deleted file mode 100644 index 1b560e3..0000000 Binary files a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon_256x256@2x.png and /dev/null differ diff --git a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon_32x32.png b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon_32x32.png deleted file mode 100644 index 08d872e..0000000 Binary files a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon_32x32.png and /dev/null differ diff --git a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon_32x32@2x.png b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon_32x32@2x.png deleted file mode 100644 index 8497898..0000000 Binary files a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon_32x32@2x.png and /dev/null differ diff --git a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon_512x512.png b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon_512x512.png deleted file mode 100644 index 1b560e3..0000000 Binary files a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon_512x512.png and /dev/null differ diff --git a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon_512x512@2x.png b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon_512x512@2x.png deleted file mode 100644 index 4889073..0000000 Binary files a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/icon_512x512@2x.png and /dev/null differ diff --git "a/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/\346\226\260\345\273\272\351\241\271\347\233\256.png" "b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/\346\226\260\345\273\272\351\241\271\347\233\256.png" new file mode 100644 index 0000000..9f7f199 Binary files /dev/null and "b/Example/ColorfulApp/Assets.xcassets/AppIcon.appiconset/\346\226\260\345\273\272\351\241\271\347\233\256.png" differ diff --git a/Package.resolved b/Package.resolved index 74b516f..c9b579e 100644 --- a/Package.resolved +++ b/Package.resolved @@ -14,8 +14,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/Lakr233/SpringInterpolation.git", "state" : { - "revision" : "be8721cffc87ec514fa13ba5dab586a2730f51c9", - "version" : "1.1.2" + "revision" : "ff526fec3ef6df62395141a0cc55a4ba2d82ee81", + "version" : "1.2.2" } } ], diff --git a/Package.swift b/Package.swift index 045892b..7b7a018 100644 --- a/Package.swift +++ b/Package.swift @@ -16,7 +16,7 @@ let package = Package( ], dependencies: [ .package(url: "https://github.com/Lakr233/ColorVector.git", from: "1.0.3"), - .package(url: "https://github.com/Lakr233/SpringInterpolation.git", from: "1.1.2"), + .package(url: "https://github.com/Lakr233/SpringInterpolation.git", from: "1.2.2"), ], targets: [ .target( diff --git a/Sources/ColorfulX/AnimatedMulticolorGradientView.swift b/Sources/ColorfulX/AnimatedMulticolorGradientView.swift index 6ec1853..2ec2ba0 100644 --- a/Sources/ColorfulX/AnimatedMulticolorGradientView.swift +++ b/Sources/ColorfulX/AnimatedMulticolorGradientView.swift @@ -12,7 +12,9 @@ import SpringInterpolation private let SPRING_CONFIG = SpringInterpolation.Configuration( angularFrequency: 1.5, - dampingRatio: 0.2 + dampingRatio: 0.2, + threshold: 0.001, + stopWhenHitTarget: true ) private let SPRING_ENGINE = SpringInterpolation2D(SPRING_CONFIG) private let defaultFrameRate: Int = 60 @@ -119,6 +121,22 @@ open class AnimatedMulticolorGradientView: MulticolorGradientView { return realDeltaTime } + @inline(__always) + func isColorTransitionCompleted() -> Bool { + colorElements + .filter(\.enabled) + .allSatisfy { $0.transitionProgress.context.currentPos >= 1 } + } + + @inline(__always) + public func shouldRenderNextFrameWithinSynchornization() -> Bool { + // if transition not completed, keep ticking until complete + if !isColorTransitionCompleted() { return true } + guard frameLimiterShouldScheduleNextFrame() else { return false } + guard speed > 0 || renderInputWasModified else { return false } + return true + } + // MARK: - RENDER LIFE CYCLE override public func layoutSublayers(of layer: CALayer) { @@ -140,14 +158,8 @@ open class AnimatedMulticolorGradientView: MulticolorGradientView { } override func vsync() { - // check if we should render - guard frameLimiterShouldScheduleNextFrame() else { return } - - // check if we need to update the render parameter - // the underlying MulticolorGradientView will only render if parameter was modified - guard speed > 0 || renderInputWasModified else { return } + guard shouldRenderNextFrameWithinSynchornization() else { return } updateRenderParameters(deltaTime: deltaTimeForRenderParametersUpdate()) - // sine the render parameters were updated, we call super.vsync to render super.vsync() }