Commit cfb301df by Dmitry Stepanets

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

parent 5fbd9a09
......@@ -3,22 +3,4 @@
uuid = "55281C35-FE9F-4CED-865E-FBED0E7393F6"
type = "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>
......@@ -49,12 +49,19 @@ class MinutelyForecastDetailsView: UIView {
triangle.path = path
}
func configure(hourly: HourlyWeather, colors: [UIColor]) {
func configure(valueStirng: String, date: Date?, colors: [UIColor]) {
gradient.colors = colors.map{ $0.cgColor }
triangle.fillColor = colors.last?.cgColor
timeLabel.text = formatter.string(from: hourly.date)
tempLabel.text = hourly.temp?.settingsConverted.shortString
forecastImage.image = hourly.type.image(isDay: hourly.isDay)
if let forecastDate = date {
timeLabel.text = formatter.string(from: forecastDate)
}
else {
timeLabel.text = "--"
}
tempLabel.text = valueStirng
forecastImage.image = nil
}
}
......@@ -84,10 +91,6 @@ private extension MinutelyForecastDetailsView {
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)
......@@ -101,7 +104,7 @@ private extension MinutelyForecastDetailsView {
separator.snp.makeConstraints { make in
make.width.equalTo(1)
make.height.equalToSuperview().multipliedBy(0.65)
make.left.equalTo(timeLabel.snp.right).offset(8)
make.left.equalToSuperview().inset(70)
make.centerY.equalToSuperview()
}
......@@ -113,7 +116,7 @@ private extension MinutelyForecastDetailsView {
forecastImage.snp.makeConstraints { make in
make.width.height.equalTo(28)
make.centerY.equalToSuperview()
make.left.equalTo(tempLabel.snp.right).offset(4)
// make.left.equalTo(tempLabel.snp.right).offset(4)
make.right.equalToSuperview().inset(12)
}
}
......
......@@ -75,9 +75,12 @@ class MinutelyForecastView: UIView {
override func layoutSubviews() {
super.layoutSubviews()
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)
if scrollView.contentInset.left != leftInset {
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()
......@@ -92,7 +95,8 @@ class MinutelyForecastView: UIView {
self.location = location
centerDashline.strokeColor = kTemperatureColors.last?.cgColor
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)
}
......@@ -182,6 +186,8 @@ private extension MinutelyForecastView {
//Constraints
detailsInfoView.snp.makeConstraints { make in
make.width.equalTo(158)
make.height.equalTo(50)
make.top.equalToSuperview()
make.centerX.equalToSuperview()
}
......@@ -243,10 +249,10 @@ extension MinutelyForecastView: UIScrollViewDelegate {
return
}
if 0..<cachedValue.key ~= location?.minutely?.forecast.count ?? 0 {
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)")
}
}
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