Commit cfb301df by Dmitry Stepanets

[IOS-172]: Added minutely info view updating on scroll

parent 5fbd9a09
...@@ -3,22 +3,4 @@ ...@@ -3,22 +3,4 @@
uuid = "55281C35-FE9F-4CED-865E-FBED0E7393F6" uuid = "55281C35-FE9F-4CED-865E-FBED0E7393F6"
type = "0" type = "0"
version = "2.0"> version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "451CF0CC-97B9-44A7-9228-3653F9EC81B0"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "1Weather/UI/SharedViews/MinutelyForecastView/MinutelyForecastView.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "250"
endingLineNumber = "250"
landmarkName = "scrollViewDidScroll(_:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket> </Bucket>
...@@ -49,12 +49,19 @@ class MinutelyForecastDetailsView: UIView { ...@@ -49,12 +49,19 @@ class MinutelyForecastDetailsView: UIView {
triangle.path = path triangle.path = path
} }
func configure(hourly: HourlyWeather, colors: [UIColor]) { func configure(valueStirng: String, date: Date?, colors: [UIColor]) {
gradient.colors = colors.map{ $0.cgColor } gradient.colors = colors.map{ $0.cgColor }
triangle.fillColor = colors.last?.cgColor triangle.fillColor = colors.last?.cgColor
timeLabel.text = formatter.string(from: hourly.date)
tempLabel.text = hourly.temp?.settingsConverted.shortString if let forecastDate = date {
forecastImage.image = hourly.type.image(isDay: hourly.isDay) timeLabel.text = formatter.string(from: forecastDate)
}
else {
timeLabel.text = "--"
}
tempLabel.text = valueStirng
forecastImage.image = nil
} }
} }
...@@ -84,10 +91,6 @@ private extension MinutelyForecastDetailsView { ...@@ -84,10 +91,6 @@ private extension MinutelyForecastDetailsView {
container.addSubview(separator) container.addSubview(separator)
//Constraints //Constraints
self.snp.makeConstraints { make in
make.height.equalTo(38)
}
container.snp.makeConstraints { make in container.snp.makeConstraints { make in
make.left.top.right.equalToSuperview() make.left.top.right.equalToSuperview()
make.bottom.equalTo(triangleView.snp.top) make.bottom.equalTo(triangleView.snp.top)
...@@ -101,7 +104,7 @@ private extension MinutelyForecastDetailsView { ...@@ -101,7 +104,7 @@ private extension MinutelyForecastDetailsView {
separator.snp.makeConstraints { make in separator.snp.makeConstraints { make in
make.width.equalTo(1) make.width.equalTo(1)
make.height.equalToSuperview().multipliedBy(0.65) make.height.equalToSuperview().multipliedBy(0.65)
make.left.equalTo(timeLabel.snp.right).offset(8) make.left.equalToSuperview().inset(70)
make.centerY.equalToSuperview() make.centerY.equalToSuperview()
} }
...@@ -113,7 +116,7 @@ private extension MinutelyForecastDetailsView { ...@@ -113,7 +116,7 @@ private extension MinutelyForecastDetailsView {
forecastImage.snp.makeConstraints { make in forecastImage.snp.makeConstraints { make in
make.width.height.equalTo(28) make.width.height.equalTo(28)
make.centerY.equalToSuperview() make.centerY.equalToSuperview()
make.left.equalTo(tempLabel.snp.right).offset(4) // make.left.equalTo(tempLabel.snp.right).offset(4)
make.right.equalToSuperview().inset(12) make.right.equalToSuperview().inset(12)
} }
} }
......
...@@ -75,9 +75,12 @@ class MinutelyForecastView: UIView { ...@@ -75,9 +75,12 @@ class MinutelyForecastView: UIView {
override func layoutSubviews() { override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
let leftInset = detailsInfoView.frame.origin.x - scrollView.frame.origin.x + detailsInfoView.frame.width / 2 let leftInset = detailsInfoView.frame.origin.x - scrollView.frame.origin.x + detailsInfoView.frame.width / 2
if scrollView.contentInset.left != leftInset {
scrollView.contentInset = .init(top: 0, left: leftInset, bottom: 0, right: leftInset + 20) scrollView.contentInset = .init(top: 0, left: leftInset, bottom: 0, right: leftInset + 20)
scrollView.setContentOffset(.init(x: -leftInset, y: 0), animated: false) scrollView.setContentOffset(.init(x: -leftInset, y: 0), animated: false)
}
//Dash //Dash
let dashlinePath = CGMutablePath() let dashlinePath = CGMutablePath()
...@@ -92,7 +95,8 @@ class MinutelyForecastView: UIView { ...@@ -92,7 +95,8 @@ class MinutelyForecastView: UIView {
self.location = location self.location = location
centerDashline.strokeColor = kTemperatureColors.last?.cgColor centerDashline.strokeColor = kTemperatureColors.last?.cgColor
if !location.hourly.isEmpty { if !location.hourly.isEmpty {
self.detailsInfoView.configure(hourly: location.hourly[0], self.detailsInfoView.configure(valueStirng: location.hourly.first?.temp?.shortString ?? "--",
date: location.hourly.first?.date,
colors: kTemperatureColors) colors: kTemperatureColors)
} }
...@@ -182,6 +186,8 @@ private extension MinutelyForecastView { ...@@ -182,6 +186,8 @@ private extension MinutelyForecastView {
//Constraints //Constraints
detailsInfoView.snp.makeConstraints { make in detailsInfoView.snp.makeConstraints { make in
make.width.equalTo(158)
make.height.equalTo(50)
make.top.equalToSuperview() make.top.equalToSuperview()
make.centerX.equalToSuperview() make.centerX.equalToSuperview()
} }
...@@ -243,10 +249,10 @@ extension MinutelyForecastView: UIScrollViewDelegate { ...@@ -243,10 +249,10 @@ extension MinutelyForecastView: UIScrollViewDelegate {
return return
} }
if 0..<cachedValue.key ~= location?.minutely?.forecast.count ?? 0 {
let forecast = location?.minutely?.forecast[cachedValue.key] let forecast = location?.minutely?.forecast[cachedValue.key]
detailsInfoView.configure(hourly: forecast, colors: <#T##[UIColor]#>) detailsInfoView.configure(valueStirng: forecast?.temp.shortString ?? "--",
} date: forecast?.time,
colors: kTemperatureColors)
print("[min] Target current index \(cachedValue.key)") print("[min] Target current index \(cachedValue.key)")
} }
} }
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