-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
POC: Show warning banner on map when user is about to approach the th…
…reshold for maximum allowed cities to save This in accordance to #12 Also see https://iafisher.com/projects/cities/faqs
- Loading branch information
Geoffrey Liu
committed
May 22, 2022
1 parent
28146c3
commit 554418f
Showing
4 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// WarningBannerView.swift | ||
// HowManyCities | ||
// | ||
// Created by Geoffrey Liu on 5/11/22. | ||
// | ||
|
||
import UIKit | ||
|
||
final class WarningBannerView: UIView { | ||
private lazy var label: UILabel = { | ||
let label = UILabel().autolayoutEnabled | ||
label.numberOfLines = 2 | ||
|
||
return label | ||
}() | ||
|
||
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
|
||
isHidden = true | ||
addSubview(label) | ||
label.pin(to: safeAreaLayoutGuide, margins: .init(top: 0, left: 16, bottom: 8, right: 16)) | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
func setState(_ state: CityLimitWarning) { | ||
switch state { | ||
case .none: | ||
isHidden = true | ||
backgroundColor = .clear | ||
label.text = nil | ||
case .warning(let remaining): | ||
isHidden = false | ||
backgroundColor = .systemYellow | ||
label.text = "You're approaching the limit (\(remaining) cities left)" | ||
case .unableToSave(let surplus): | ||
isHidden = false | ||
backgroundColor = .systemRed | ||
label.text = "Unable to save now, you're over the limit by \(surplus) cities" | ||
|
||
} | ||
} | ||
} |