Skip to content

Commit cc0d093

Browse files
committed
Share markets
# Conflicts: # Mixin/UserInterface/Controllers/Wallet/Market/MarketViewController.swift
1 parent fac7853 commit cc0d093

11 files changed

Lines changed: 581 additions & 189 deletions

Mixin.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,7 @@
869869
9438252725EE697300709B7D /* CacheableAssetFileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9438252625EE697300709B7D /* CacheableAssetFileManager.swift */; };
870870
94386ADB2F7E599200FF1FB9 /* PopupTipRecoveryKitOptionsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94386ADA2F7E598800FF1FB9 /* PopupTipRecoveryKitOptionsView.swift */; };
871871
94386B3A2F7E9FC500FF1FB9 /* AccountRecoveryOption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94386B392F7E9FC200FF1FB9 /* AccountRecoveryOption.swift */; };
872+
9438EDB52FAB8C9C0030C00E /* MarketStatistics.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9438EDB42FAB8C980030C00E /* MarketStatistics.swift */; };
872873
94396D4B2CE3597E009DA4E9 /* InputMnemonicsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94396D4A2CE3597E009DA4E9 /* InputMnemonicsViewController.swift */; };
873874
94396F2629EB11E300A57833 /* DeviceTransferProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94396F2529EB11E300A57833 /* DeviceTransferProtocol.swift */; };
874875
94396F2829EB475500A57833 /* NWParameters+DeviceTransfer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94396F2729EB475500A57833 /* NWParameters+DeviceTransfer.swift */; };
@@ -2745,6 +2746,7 @@
27452746
9438252625EE697300709B7D /* CacheableAssetFileManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CacheableAssetFileManager.swift; sourceTree = "<group>"; };
27462747
94386ADA2F7E598800FF1FB9 /* PopupTipRecoveryKitOptionsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PopupTipRecoveryKitOptionsView.swift; sourceTree = "<group>"; };
27472748
94386B392F7E9FC200FF1FB9 /* AccountRecoveryOption.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountRecoveryOption.swift; sourceTree = "<group>"; };
2749+
9438EDB42FAB8C980030C00E /* MarketStatistics.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarketStatistics.swift; sourceTree = "<group>"; };
27482750
94396D4A2CE3597E009DA4E9 /* InputMnemonicsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputMnemonicsViewController.swift; sourceTree = "<group>"; };
27492751
94396F2529EB11E300A57833 /* DeviceTransferProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceTransferProtocol.swift; sourceTree = "<group>"; };
27502752
94396F2729EB475500A57833 /* NWParameters+DeviceTransfer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NWParameters+DeviceTransfer.swift"; sourceTree = "<group>"; };
@@ -4786,6 +4788,7 @@
47864788
9429C0E82E059B3400206DAA /* Market */ = {
47874789
isa = PBXGroup;
47884790
children = (
4791+
9438EDB42FAB8C980030C00E /* MarketStatistics.swift */,
47894792
942BA99A2C689FA10096CCC3 /* MarketViewController.swift */,
47904793
94510FCD2C8742BC00ACD972 /* MarketTokenSelectorViewController.swift */,
47914794
9443A9202CA6BB3D0030A636 /* MarketAlertCoinPickerViewController.swift */,
@@ -8020,6 +8023,7 @@
80208023
7C7579DF29DC61890002DA0B /* TransferToPhoneQRCodeViewController.swift in Sources */,
80218024
94DB79062E3A660D0066A8E7 /* SequentialWalletNameGenerator.swift in Sources */,
80228025
946331C02C622C1100C54B76 /* TransactionHistoryOpponentFilterView.swift in Sources */,
8026+
9438EDB52FAB8C9C0030C00E /* MarketStatistics.swift in Sources */,
80238027
942FB8952C8AD82F00C8025C /* ShareInscriptionAsPictureView.swift in Sources */,
80248028
94317CFF2AFBDEFF00FDC9C9 /* MemoViewController.swift in Sources */,
80258029
941D3BFA2A7912C700538504 /* QRCodeViewController.swift in Sources */,
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"scale" : "1x"
6+
},
7+
{
8+
"appearances" : [
9+
{
10+
"appearance" : "luminosity",
11+
"value" : "dark"
12+
}
13+
],
14+
"idiom" : "universal",
15+
"scale" : "1x"
16+
},
17+
{
18+
"filename" : "share_branding_multicolor_any@2x.png",
19+
"idiom" : "universal",
20+
"scale" : "2x"
21+
},
22+
{
23+
"appearances" : [
24+
{
25+
"appearance" : "luminosity",
26+
"value" : "dark"
27+
}
28+
],
29+
"filename" : "share_branding_multicolor_dark@2x.png",
30+
"idiom" : "universal",
31+
"scale" : "2x"
32+
},
33+
{
34+
"filename" : "share_branding_multicolor_any@3x.png",
35+
"idiom" : "universal",
36+
"scale" : "3x"
37+
},
38+
{
39+
"appearances" : [
40+
{
41+
"appearance" : "luminosity",
42+
"value" : "dark"
43+
}
44+
],
45+
"filename" : "share_branding_multicolor_dark@3x.png",
46+
"idiom" : "universal",
47+
"scale" : "3x"
48+
}
49+
],
50+
"info" : {
51+
"author" : "xcode",
52+
"version" : 1
53+
}
54+
}
2.43 KB
Loading
4.02 KB
Loading
2.3 KB
Loading
3.8 KB
Loading
Lines changed: 178 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,195 @@
11
import UIKit
2+
import MixinServices
23

34
final class ShareMarketAsPictureView: UIView {
45

5-
// Manipulating UIImage to render on CGContext is quite cumbersome, and the behavior varies
6-
// across different iOS versions. Therefore, an invisible view is used to capture a screenshot
7-
// to generate the image for sharing.
6+
@IBOutlet weak var chartSectionView: UIView!
7+
@IBOutlet weak var titleStackView: UIStackView!
8+
@IBOutlet weak var titleLabel: UILabel!
9+
@IBOutlet weak var rankLabel: InsetLabel!
10+
@IBOutlet weak var priceLabel: UILabel!
11+
@IBOutlet weak var changeLabel: MarketColoredLabel!
12+
@IBOutlet weak var tokenIconView: PlainTokenIconView!
13+
@IBOutlet weak var chartView: ChartView!
14+
@IBOutlet weak var periodSelectorStackView: UIStackView!
15+
@IBOutlet weak var marketCapTitleLabel: UILabel!
16+
@IBOutlet weak var marketCapContentLabel: UILabel!
17+
@IBOutlet weak var volumeTitleLabel: UILabel!
18+
@IBOutlet weak var volumeContentLabel: UILabel!
19+
@IBOutlet weak var highTitleLabel: UILabel!
20+
@IBOutlet weak var highContentLabel: UILabel!
21+
@IBOutlet weak var lowTitleLabel: UILabel!
22+
@IBOutlet weak var lowContentLabel: UILabel!
23+
@IBOutlet weak var periodSelectorHeightConstraint: NSLayoutConstraint!
24+
25+
@IBOutlet weak var statisticsSectionView: UIView!
26+
@IBOutlet weak var nameLabel: UILabel!
27+
@IBOutlet weak var statisticsStackView: UIStackView!
828

9-
@IBOutlet weak var screenshotWrapperView: UIView!
10-
@IBOutlet weak var screenshotImageView: UIImageView!
11-
@IBOutlet weak var displayImageView: UIImageView!
1229
@IBOutlet weak var obiView: ShareObiView!
1330

31+
private weak var unavailableView: UIView?
32+
33+
private var sectionViews: [UIView] {
34+
[chartSectionView, statisticsSectionView]
35+
}
36+
37+
private var statsTitleLabels: [UILabel] {
38+
[
39+
marketCapTitleLabel,
40+
volumeTitleLabel,
41+
highTitleLabel,
42+
lowTitleLabel,
43+
]
44+
}
45+
46+
private var statsContentLabels: [UILabel] {
47+
[
48+
marketCapContentLabel,
49+
volumeContentLabel,
50+
highContentLabel,
51+
lowContentLabel,
52+
]
53+
}
54+
1455
override func awakeFromNib() {
1556
super.awakeFromNib()
57+
for sectionView in sectionViews {
58+
sectionView.layer.cornerRadius = 8
59+
sectionView.layer.masksToBounds = true
60+
}
61+
titleStackView.setCustomSpacing(9, after: titleLabel)
62+
titleLabel.font = .systemFont(
63+
ofSize: 14,
64+
weight: .accessiblityBoldTextCounterWeight(.regular)
65+
)
66+
rankLabel.contentInset = UIEdgeInsets(top: 1, left: 4, bottom: 1, right: 4)
67+
rankLabel.layer.masksToBounds = true
68+
rankLabel.layer.cornerRadius = 4
69+
rankLabel.font = .systemFont(
70+
ofSize: 12,
71+
weight: .accessiblityBoldTextCounterWeight(.medium)
72+
)
73+
priceLabel.font = .systemFont(
74+
ofSize: 22,
75+
weight: .accessiblityBoldTextCounterWeight(.medium)
76+
)
77+
changeLabel.font = .systemFont(
78+
ofSize: 14,
79+
weight: .accessiblityBoldTextCounterWeight(.regular)
80+
)
81+
chartView.annotateExtremums = true
82+
chartView.minPointPosition = 135 / 184
83+
chartView.maxPointPosition = 23 / 184
84+
chartView.delegate = self
85+
for (i, period) in PriceHistoryPeriod.allCases.enumerated() {
86+
let label = InsetLabel()
87+
label.tag = i
88+
label.font = .systemFont(
89+
ofSize: 14,
90+
weight: .accessiblityBoldTextCounterWeight(.regular)
91+
)
92+
label.textAlignment = .center
93+
label.text = switch period {
94+
case .day:
95+
R.string.localizable.days_count_short(1)
96+
case .week:
97+
R.string.localizable.weeks_count_short(1)
98+
case .month:
99+
R.string.localizable.months_count_short(1)
100+
case .year:
101+
R.string.localizable.years_count_short(1)
102+
case .all:
103+
R.string.localizable.all()
104+
}
105+
label.layer.cornerRadius = periodSelectorHeightConstraint.constant / 2
106+
label.layer.masksToBounds = true
107+
label.contentInset = UIEdgeInsets(top: 4, left: 10, bottom: 4, right: 10)
108+
periodSelectorStackView.addArrangedSubview(label)
109+
}
110+
111+
nameLabel.font = .systemFont(
112+
ofSize: 14,
113+
weight: .accessiblityBoldTextCounterWeight(.regular)
114+
)
115+
for label in statsTitleLabels {
116+
label.font = .systemFont(
117+
ofSize: 12,
118+
weight: .accessiblityBoldTextCounterWeight(.regular)
119+
)
120+
}
121+
marketCapTitleLabel.text = R.string.localizable.market_cap().uppercased()
122+
volumeTitleLabel.text = R.string.localizable.volume_24h().uppercased()
123+
highTitleLabel.text = R.string.localizable.high_24h().uppercased()
124+
lowTitleLabel.text = R.string.localizable.low_24h().uppercased()
125+
for label in statsContentLabels {
126+
label.font = .systemFont(
127+
ofSize: 14,
128+
weight: .accessiblityBoldTextCounterWeight(.regular)
129+
)
130+
}
16131
obiView.load(content: .installMixin(gradient: true))
17132
}
18133

19-
func setImage(_ image: UIImage) {
20-
let ratio = image.size.width / image.size.height
21-
screenshotImageView.image = image
22-
screenshotImageView.snp.makeConstraints { make in
23-
make.width.equalTo(screenshotImageView.snp.height).multipliedBy(ratio)
134+
func showUnavailableView() {
135+
let unavailableView: UIView
136+
if let view = self.unavailableView {
137+
unavailableView = view
138+
} else {
139+
unavailableView = PriceDataUnavailableView()
140+
addSubview(unavailableView)
141+
unavailableView.snp.makeConstraints { make in
142+
make.top.equalTo(titleStackView.snp.bottom).offset(24)
143+
make.leading.equalToSuperview().offset(16)
144+
make.trailing.equalToSuperview().offset(-16)
145+
make.bottom.equalToSuperview().offset(-20)
146+
}
147+
self.unavailableView = unavailableView
24148
}
25-
displayImageView.image = image
26-
displayImageView.snp.remakeConstraints { make in
27-
make.width.equalTo(displayImageView.snp.height).multipliedBy(ratio).priority(.low)
149+
unavailableView.isHidden = false
150+
periodSelectorStackView.isHidden = true
151+
}
152+
153+
func hideUnavailableView() {
154+
unavailableView?.isHidden = true
155+
periodSelectorStackView.isHidden = false
156+
}
157+
158+
func setPeriodSelection(index: Int) {
159+
for case let label as UILabel in periodSelectorStackView.arrangedSubviews {
160+
if label.tag == index {
161+
label.backgroundColor = R.color.background_secondary()
162+
label.textColor = R.color.text()
163+
} else {
164+
label.backgroundColor = .clear
165+
label.textColor = R.color.text_quaternary()
166+
}
28167
}
29168
}
30169

31170
}
171+
172+
extension ShareMarketAsPictureView: ChartView.Delegate {
173+
174+
func chartView(_ view: ChartView, extremumAnnotationForPoint point: ChartView.Point) -> String {
175+
CurrencyFormatter.localizedString(
176+
from: point.value * Currency.current.decimalRate,
177+
format: .fiatMoneyPrice,
178+
sign: .never,
179+
symbol: .currencySymbol
180+
)
181+
}
182+
183+
func chartView(_ view: ChartView, inspectionAnnotationForPoint point: ChartView.Point) -> String {
184+
""
185+
}
186+
187+
func chartView(_ view: ChartView, didSelectPoint point: ChartView.Point) {
188+
189+
}
190+
191+
func chartViewDidCancelSelection(_ view: ChartView) {
192+
193+
}
194+
195+
}

0 commit comments

Comments
 (0)