forked from overtake/TelegramSwift
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChannelIntroViewController.swift
More file actions
117 lines (86 loc) · 3.34 KB
/
ChannelIntroViewController.swift
File metadata and controls
117 lines (86 loc) · 3.34 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
//
// ChannelIntroViewController.swift
// TelegramMac
//
// Created by keepcoder on 26/12/2016.
// Copyright © 2016 Telegram. All rights reserved.
//
import Cocoa
import SwiftSignalKit
import TGUIKit
import TelegramCore
import SyncCore
import Postbox
class ChannelIntroView : NSScrollView, AppearanceViewProtocol {
let imageView:ImageView = ImageView()
let textView:TextView = TextView()
let button:TitleButton = TitleButton()
private let containerView:View = View()
required override init(frame frameRect: NSRect) {
super.init(frame: frameRect)
documentView = containerView
wantsLayer = true
documentView?.addSubview(imageView)
documentView?.addSubview(textView)
documentView?.addSubview(button)
button.set(font: .medium(.title), for: .Normal)
updateLocalizationAndTheme(theme: theme)
}
func updateLocalizationAndTheme(theme: PresentationTheme) {
let theme = (theme as! TelegramPresentationTheme)
imageView.image = theme.icons.channelIntro
imageView.sizeToFit()
button.set(text: L10n.channelIntroCreateChannel, for: .Normal)
button.set(color: theme.colors.accent, for: .Normal)
_ = button.sizeToFit()
backgroundColor = theme.colors.background
textView.background = theme.colors.background
documentView?.background = theme.colors.background
let attr = NSMutableAttributedString()
_ = attr.append(string: tr(L10n.channelIntroDescriptionHeader), color: theme.colors.text, font: .medium(.header))
_ = attr.append(string:"\n\n")
_ = attr.append(string: tr(L10n.channelIntroDescription), color: theme.colors.grayText, font: .normal(.text))
textView.set(layout: TextViewLayout(attr, alignment:.center))
}
override func layout() {
super.layout()
containerView.setFrameSize(frame.width, 0)
textView.layout?.measure(width: 380 - 60)
textView.update(textView.layout)
imageView.centerX(y:30)
textView.centerX(y:imageView.frame.maxY + 30)
button.centerX(y: textView.frame.maxY + 30)
containerView.setFrameSize(frame.width, button.frame.maxY + 30)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
class ChannelIntroViewController: EmptyComposeController<Void,Void,ChannelIntroView> {
override func getRightBarViewOnce() -> BarView {
return TextButtonBarView(controller: self, text: tr(L10n.channelCreate), style: navigationButtonStyle, alignment:.Right)
}
override var removeAfterDisapper: Bool {
return true
}
override var enableBack: Bool {
return true
}
func executeNext() {
onComplete.set(.single(Void()))
}
override func returnKeyAction() -> KeyHandlerResult {
executeNext()
return .rejected
}
override func viewDidLoad() {
super.viewDidLoad()
(self.rightBarView as? TextButtonBarView)?.set(handler:{ [weak self] _ in
self?.executeNext()
}, for: .Click)
self.genericView.button.set(handler: { [weak self] _ in
self?.executeNext()
}, for: .Click)
readyOnce()
}
}