-
-
Notifications
You must be signed in to change notification settings - Fork 736
Expand file tree
/
Copy pathPhotoBrowser.swift
More file actions
88 lines (76 loc) · 2.27 KB
/
PhotoBrowser.swift
File metadata and controls
88 lines (76 loc) · 2.27 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//
// PhotoBrowser.swift
// SwiftUIExample
//
// Created by Silence on 2023/9/8.
// Copyright © 2023 洪欣. All rights reserved.
//
import SwiftUI
import UIKit
import HXPhotoPicker
import Foundation
@available(iOS 13.0, *)
struct PhotoBrowser {
enum TransitionType {
case start
case end
var opacity: CGFloat {
switch self {
case .start:
return 0
case .end:
return 1
}
}
}
let pageIndex: Int
let rowCount: CGFloat
@Binding var photoAssets: [PhotoAsset]
@Binding var assets: [Asset]
@Binding var transitionTypes: [TransitionType]
func show(_ image: UIImage, itemSize: CGSize, pointHandler: @escaping (Int) -> CGPoint) {
var config = HXPhotoPicker.PhotoBrowser.Configuration()
config.showDelete = true
HXPhotoPicker.PhotoBrowser.show(
photoAssets,
pageIndex: pageIndex,
config: config,
transitionalImage: image
) { index, _ in
transitionTypes[index] = .start
let point = pointHandler(index)
let view = UIView(frame: .init(x: point.x, y: point.y, width: itemSize.width, height: itemSize.height))
view.layer.cornerRadius = 5
return view
} transitionCompletion: { index, _ in
transitionTypes[index] = .end
} deleteAssetHandler: { index, _, browser in
PhotoTools.showAlert(
viewController: browser,
title: "是否删除?",
leftActionTitle: "取消",
rightActionTitle: "确定",
rightHandler: { _ in
browser.deleteCurrentPreviewPhotoAsset()
photoAssets.remove(at: index)
assets.remove(at: index)
}
)
}
}
}
@available(iOS 13.0, *)
struct Editor {
let asset: EditorAsset
let config: EditorConfiguration
@Binding var resultAsset: EditorAsset
func start() {
Task {
do {
let result = try await Photo.edit(asset, config: config)
resultAsset = result
} catch {
}
}
}
}