Commit 300a5415 by Dmitry Stepanets

Added center dashline

parent 6da24400
......@@ -18,6 +18,7 @@
87D815AC2636D61D0015A6D1 /* NWSAlertViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87D815AB2636D61D0015A6D1 /* NWSAlertViewModel.swift */; };
90766436021777888F434DCB /* Pods_OneWeatherWidgetExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C588E8BC9935BC4408CE6E27 /* Pods_OneWeatherWidgetExtension.framework */; };
9FAD89D1BEBA0FEB5F50BE73 /* Pods_1Weather.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7BDC55F44AA0B2FA48788F0E /* Pods_1Weather.framework */; };
CD1000AE26D92A8F002D6C61 /* Array+Unique.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD1000AD26D92A8F002D6C61 /* Array+Unique.swift */; };
CD1237C3255D5C5900C98139 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD1237C2255D5C5900C98139 /* AppDelegate.swift */; };
CD1237CC255D5C5C00C98139 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CD1237CB255D5C5C00C98139 /* Assets.xcassets */; };
CD1237F4255D889F00C98139 /* GradientView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD1237F3255D889F00C98139 /* GradientView.swift */; };
......@@ -332,6 +333,7 @@
87D815AB2636D61D0015A6D1 /* NWSAlertViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NWSAlertViewModel.swift; sourceTree = "<group>"; };
C588E8BC9935BC4408CE6E27 /* Pods_OneWeatherWidgetExtension.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_OneWeatherWidgetExtension.framework; sourceTree = BUILT_PRODUCTS_DIR; };
C8C576F6184B547435CFF0F3 /* Pods-1Weather.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-1Weather.debug.xcconfig"; path = "Target Support Files/Pods-1Weather/Pods-1Weather.debug.xcconfig"; sourceTree = "<group>"; };
CD1000AD26D92A8F002D6C61 /* Array+Unique.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Array+Unique.swift"; sourceTree = "<group>"; };
CD1237BF255D5C5900C98139 /* 1Weather.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = 1Weather.app; sourceTree = BUILT_PRODUCTS_DIR; };
CD1237C2255D5C5900C98139 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
CD1237CB255D5C5C00C98139 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
......@@ -910,6 +912,7 @@
CD7D318A268F36AF000D01FA /* UIApplication+Version.swift */,
CD85797226721DD400CC4CDA /* UIColor+Highlight.swift */,
CDB0D4CD2670DABF0081C773 /* UIImage+AverageColor.swift */,
CD1000AD26D92A8F002D6C61 /* Array+Unique.swift */,
);
path = Extensions;
sourceTree = "<group>";
......@@ -2049,6 +2052,7 @@
CD86246525E66E8A0097F3FB /* PrecipitationCell.swift in Sources */,
CE13B821262480B3007CBD4D /* Scheduler.swift in Sources */,
CE13B81E262480B3007CBD4D /* AdCacheManager.swift in Sources */,
CD1000AE26D92A8F002D6C61 /* Array+Unique.swift in Sources */,
CEBAC1C82638240800A89681 /* DeeplinksRouter.swift in Sources */,
CD3F6E6925FA59D4002DB99B /* ForecastDetailPeriodButton.swift in Sources */,
CD37D405260DFFDD002669D6 /* CellFactory.swift in Sources */,
......
//
// Array+Unique.swift
// 1Weather
//
// Created by Dmitry Stepanets on 27.08.2021.
//
import Foundation
extension Sequence where Iterator.Element: Hashable {
func unique() -> [Iterator.Element] {
var seen: Set<Iterator.Element> = []
return filter { seen.insert($0).inserted }
}
}
......@@ -10,6 +10,7 @@ import OneWeatherCore
class MinutelyForecastDetailsView: UIView {
//Private
private let container = UIView()
private let gradient = CAGradientLayer()
private let tempLabel = UILabel()
private let timeLabel = UILabel()
......@@ -35,15 +36,17 @@ class MinutelyForecastDetailsView: UIView {
super.layoutSubviews()
//Gradient
gradient.frame = self.bounds
gradient.frame = container.bounds
//Triangle
let bezierPath = UIBezierPath()
bezierPath.addLine(to: .init(x: triangleView.frame.width, y: 0))
bezierPath.addLine(to: .init(x: (triangleView.frame.width / 2).rounded(.down),
y: triangleView.frame.height))
bezierPath.addLine(to: .zero)
triangle.path = bezierPath.cgPath
let path = CGMutablePath()
path.move(to: CGPoint(x: 0, y: 0))
path.addLine(to: CGPoint(x: triangleView.bounds.width / 2, y: triangleView.bounds.height))
path.addLine(to: CGPoint(x: triangleView.bounds.width, y: 0))
path.addLine(to: CGPoint(x: 0, y: 0))
triangle.frame = triangleView.bounds
triangle.path = path
}
func configure(hourly: HourlyWeather, colors: [UIColor]) {
......@@ -57,32 +60,39 @@ class MinutelyForecastDetailsView: UIView {
private extension MinutelyForecastDetailsView {
func prepareView() {
addSubview(container)
gradient.startPoint = .init(x: 0.5, y: 0)
gradient.endPoint = .init(x: 0.5, y: 1)
gradient.cornerRadius = 8
layer.addSublayer(gradient)
container.layer.addSublayer(gradient)
timeLabel.font = AppFont.SFPro.light(size: 12)
timeLabel.textColor = .white
addSubview(timeLabel)
container.addSubview(timeLabel)
tempLabel.font = AppFont.SFPro.bold(size: 24)
tempLabel.textColor = .white
addSubview(tempLabel)
container.addSubview(tempLabel)
forecastImage.contentMode = .scaleAspectFit
forecastImage.clipsToBounds = true
addSubview(forecastImage)
container.addSubview(forecastImage)
let separator = UIView()
separator.backgroundColor = .white.withAlphaComponent(0.5)
addSubview(separator)
container.addSubview(separator)
//Constraints
self.snp.makeConstraints { make in
make.height.equalTo(38)
}
container.snp.makeConstraints { make in
make.left.top.right.equalToSuperview()
make.bottom.equalTo(triangleView.snp.top)
}
timeLabel.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.left.equalToSuperview().inset(12)
......
......@@ -48,19 +48,13 @@ private class MinutelyLevelView: UIView {
}
}
private extension Sequence where Iterator.Element: Hashable {
func unique() -> [Iterator.Element] {
var seen: Set<Iterator.Element> = []
return filter { seen.insert($0).inserted }
}
}
class MinutelyForecastView: UIView {
//Private
private let detailsInfoView = MinutelyForecastDetailsView()
private let levelsStackView = UIStackView()
private let verticalStackView = UIStackView()
private let scrollView = UIScrollView()
private let centerDashline = CAShapeLayer()
private lazy var dateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "h:mm a"
......@@ -72,6 +66,7 @@ class MinutelyForecastView: UIView {
super.init(frame: .zero)
prepareDetailView()
prepareCenterDashLine()
prepareScrollView()
prepareVerticalStackView()
}
......@@ -81,10 +76,19 @@ class MinutelyForecastView: UIView {
let leftInset = detailsInfoView.frame.origin.x - scrollView.frame.origin.x + detailsInfoView.frame.width / 2
scrollView.contentInset = .init(top: 0, left: leftInset, bottom: 0, right: leftInset + 20)
scrollView.setContentOffset(.init(x: -leftInset, y: 0), animated: false)
//Dash
let dashlinePath = CGMutablePath()
dashlinePath.move(to: .init(x: detailsInfoView.frame.origin.x + detailsInfoView.bounds.width / 2,
y: detailsInfoView.frame.origin.y + detailsInfoView.bounds.height))
dashlinePath.addLine(to: .init(x: detailsInfoView.frame.origin.x + detailsInfoView.bounds.width / 2,
y: verticalStackView.frame.origin.y + verticalStackView.bounds.height))
centerDashline.path = dashlinePath
}
func configure(with location: Location) {
self.location = location
centerDashline.strokeColor = kTemperatureColors.last?.cgColor
self.detailsInfoView.configure(hourly: location.hourly[0],
colors: kTemperatureColors)
updateChart()
......@@ -186,7 +190,7 @@ private extension MinutelyForecastView {
}
func prepareScrollView() {
scrollView.backgroundColor = .lightGray
scrollView.backgroundColor = .clear
addSubview(scrollView)
levelsStackView.axis = .horizontal
......@@ -205,7 +209,12 @@ private extension MinutelyForecastView {
make.top.equalTo(detailsInfoView.snp.bottom).offset(8)
make.right.equalToSuperview().inset(20)
make.bottom.equalToSuperview().inset(40)
make.height.equalTo(185)
}
}
func prepareCenterDashLine() {
centerDashline.lineWidth = 1
centerDashline.lineDashPattern = [4,2]
layer.addSublayer(centerDashline)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment