-
Notifications
You must be signed in to change notification settings - Fork 0
/
CroppedImageViewControllerRepresentable.swift
72 lines (59 loc) · 2.1 KB
/
CroppedImageViewControllerRepresentable.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// CroppedImageViewControllerRepresentable.swift
// watchthebirdie
//
// Created by Andrey Zarembo-Godzyatskiy on 05.09.2023.
//
import Foundation
import SwiftUI
struct CroppedImageViewControllerRepresentable: UIViewControllerRepresentable {
let id: UUID
let imageURL: URL
let originalURL: URL
var angle: Angle
var rotation: RotateLargeAnge
@Binding var cropSize: CGSize
@Binding var cropCenter: CGPoint
let originalImageSize: CGSize
var mode: ViewMode = .view
@Binding var zoom: CGFloat
@Binding var centerShift: CGPoint
func makeUIViewController(context: Context) -> CroppedImageViewController {
let uiViewController = CroppedImageViewController(
id: id,
imageURL: imageURL,
originalURL: originalURL,
angle: angle,
rotation: rotation,
cropSize: cropSize,
cropCenter: cropCenter,
originalImageSize: originalImageSize
)
uiViewController.coordinator = context.coordinator
uiViewController.coordinator?.zoom = $zoom
uiViewController.coordinator?.centerShift = $centerShift
uiViewController.coordinator?.cropSize = $cropSize
uiViewController.coordinator?.cropCenter = $cropCenter
return uiViewController
}
func updateUIViewController(_ uiViewController: CroppedImageViewController, context: Context) {
uiViewController.reportZoomChange = false
uiViewController.zoom = self.zoom
uiViewController.reportZoomChange = true
if uiViewController.angle != angle {
uiViewController.angle = angle
}
if uiViewController.mode != mode {
uiViewController.mode = mode
}
if uiViewController.cropSize != cropSize {
uiViewController.cropSize = cropSize
}
if uiViewController.cropCenter != cropCenter {
uiViewController.cropCenter = cropCenter
}
}
func makeCoordinator() -> CroppedImageCoordinator {
return CroppedImageCoordinator()
}
}