From bbfe1e4636b9e67ab236fabe358cf08385def0fc Mon Sep 17 00:00:00 2001 From: Shibo Lyu Date: Thu, 10 Aug 2023 14:47:57 +0800 Subject: [PATCH] feat: Animation for targetSize change. --- Sources/CropImage/CropImageView.swift | 1 + Sources/CropImage/RectHoleShape.swift | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Sources/CropImage/CropImageView.swift b/Sources/CropImage/CropImageView.swift index 8187ca7..53190ad 100644 --- a/Sources/CropImage/CropImageView.swift +++ b/Sources/CropImage/CropImageView.swift @@ -151,6 +151,7 @@ public struct CropImageView: View { RectHoleShape(size: targetSize) .fill(style: FillStyle(eoFill: true)) .foregroundColor(.black.opacity(0.6)) + .animation(.default, value: targetSize) .allowsHitTesting(false) controls { do { diff --git a/Sources/CropImage/RectHoleShape.swift b/Sources/CropImage/RectHoleShape.swift index d77db99..ca317f5 100644 --- a/Sources/CropImage/RectHoleShape.swift +++ b/Sources/CropImage/RectHoleShape.swift @@ -8,7 +8,13 @@ import SwiftUI struct RectHoleShape: Shape { - let size: CGSize + var size: CGSize + + var animatableData: AnimatablePair { + get { .init(size.width, size.height) } + set { size = .init(width: newValue.first, height: newValue.second) } + } + func path(in rect: CGRect) -> Path { let path = CGMutablePath() path.move(to: rect.origin)