From 8a4b71757c7f9a3ba78c78e51fd2c4653df7eeff Mon Sep 17 00:00:00 2001 From: Shibo Lyu Date: Thu, 10 Aug 2023 18:04:13 +0800 Subject: [PATCH] fix: Overflow. --- Sources/CropImage/CropImageView.swift | 39 +++++++++++++++++---------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/Sources/CropImage/CropImageView.swift b/Sources/CropImage/CropImageView.swift index 2895bae..fc1b7f4 100644 --- a/Sources/CropImage/CropImageView.swift +++ b/Sources/CropImage/CropImageView.swift @@ -144,7 +144,7 @@ public struct CropImageView: View { } } - public var body: some View { + var underlyingImage: some View { UnderlyingImageView( offset: $offset, scale: $scale, @@ -152,20 +152,31 @@ public struct CropImageView: View { image: image, initialImageSize: initialImageSize ) - .overlay( ZStack { - RectHoleShape(size: targetSize) - .fill(style: FillStyle(eoFill: true)) - .foregroundColor(.black.opacity(0.6)) - .animation(.default, value: targetSize) - .allowsHitTesting(false) - controls($offset, $scale, $rotation) { - do { - onCrop(.success(try crop())) - } catch { - onCrop(.failure(error)) - } + } + + var rectHole: some View { + RectHoleShape(size: targetSize) + .fill(style: FillStyle(eoFill: true)) + .foregroundColor(.black.opacity(0.6)) + .animation(.default, value: targetSize) + .allowsHitTesting(false) + } + + @MainActor var control: some View { + controls($offset, $scale, $rotation) { + do { + onCrop(.success(try crop())) + } catch { + onCrop(.failure(error)) } - } ) + } + } + + public var body: some View { + underlyingImage + .clipped() + .overlay(rectHole) + .overlay(control) } }