-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Expand file tree
/
Copy pathPhotoUpdateConfirmationController.swift
More file actions
126 lines (121 loc) · 4.07 KB
/
Copy pathPhotoUpdateConfirmationController.swift
File metadata and controls
126 lines (121 loc) · 4.07 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import Foundation
import UIKit
import SwiftSignalKit
import AsyncDisplayKit
import Display
import Postbox
import TelegramCore
import TelegramPresentationData
import TelegramUIPreferences
import AccountContext
import AppBundle
import ComponentFlow
import AlertComponent
import AlertTransferHeaderComponent
import AvatarComponent
func photoUpdateConfirmationController(
context: AccountContext,
peer: EnginePeer,
image: UIImage,
text: String,
doneTitle: String,
isDark: Bool = true,
commit: @escaping () -> Void,
onCancel: (() -> Void)? = nil
) -> ViewController {
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
let strings = presentationData.strings
var content: [AnyComponentWithIdentity<AlertComponentEnvironment>] = []
content.append(AnyComponentWithIdentity(
id: "header",
component: AnyComponent(
AlertTransferHeaderComponent(
fromComponent: AnyComponentWithIdentity(id: "user", component: AnyComponent(
AvatarComponent(
context: context,
theme: presentationData.theme,
peer: peer
)
)),
toComponent: AnyComponentWithIdentity(id: "image", component: AnyComponent(
Image(
image: image,
size: CGSize(width: 60.0, height: 60.0),
cornerRadius: 30.0
)
)),
type: .transfer
)
)
))
content.append(AnyComponentWithIdentity(
id: "text",
component: AnyComponent(
AlertTextComponent(content: .plain(text))
)
))
var updatedPresentationData: (PresentationData, Signal<PresentationData, NoError>)
if isDark {
updatedPresentationData = (presentationData.withUpdated(theme: defaultDarkColorPresentationTheme), .single(presentationData.withUpdated(theme: defaultDarkColorPresentationTheme)))
} else {
updatedPresentationData = (presentationData, context.sharedContext.presentationData)
}
var didCommit = false
let alertController = AlertScreen(
content: content,
actions: [
.init(title: strings.Common_Cancel),
.init(title: doneTitle, type: .default, action: {
didCommit = true
commit()
})
],
updatedPresentationData: updatedPresentationData
)
alertController.dismissed = { _ in
if !didCommit {
onCancel?()
}
}
return alertController
}
//private final class RoundImageComponent: Component {
// let image: UIImage
//
// public init(
// image: UIImage
// ) {
// self.image = image
// }
//
// public static func ==(lhs: RoundImageComponent, rhs: RoundImageComponent) -> Bool {
// if lhs.image !== rhs.image {
// return false
// }
// return true
// }
//
// public final class View: UIImageView {
// private var component: RoundImageComponent?
// private weak var state: EmptyComponentState?
//
// func update(component: RoundImageComponent, availableSize: CGSize, state: EmptyComponentState, environment: Environment<Empty>, transition: ComponentTransition) -> CGSize {
// self.component = component
// self.state = state
//
// self.clipsToBounds = true
// self.image = component.image
// self.layer.cornerRadius = 30.0
//
// return CGSize(width: 60.0, height: 60.0)
// }
// }
//
// public func makeView() -> View {
// return View(frame: CGRect())
// }
//
// public func update(view: View, availableSize: CGSize, state: EmptyComponentState, environment: Environment<Empty>, transition: ComponentTransition) -> CGSize {
// return view.update(component: self, availableSize: availableSize, state: state, environment: environment, transition: transition)
// }
//}