Skip to content

Commit

Permalink
Merge pull request #129 from Esri/eli.activity-bar-view-bug
Browse files Browse the repository at this point in the history
improves activity bar setting colors and animations
  • Loading branch information
esreli authored Oct 12, 2018
2 parents 9658d62 + 0fe3ed6 commit feb87d8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 26 deletions.
37 changes: 13 additions & 24 deletions data-collection/data-collection/Custom Views/ActivityBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class ActivityBarView: UIView {

init(mapView: AGSMapView, colors:(a: UIColor, b: UIColor)) {
self.mapView = mapView
self.colorA = colors.a
self.colorB = colors.b
self.colors = colors

super.init(frame: .zero)

Expand All @@ -43,13 +42,7 @@ class ActivityBarView: UIView {

weak var mapView: AGSMapView?

var colorA: UIColor {
didSet {
updateAnimationsForNewColor()
}
}

var colorB: UIColor {
var colors: (a: UIColor, b: UIColor) {
didSet {
updateAnimationsForNewColor()
}
Expand All @@ -66,28 +59,28 @@ class ActivityBarView: UIView {
}
}

public func resetBackgroundColor() {
isAnimating = false
backgroundColor = colorA
}

private func startProgressAnimation() {
isAnimating = true
alpha = 1.0
isHidden = false
UIView.animate(withDuration: 0.1, animations: { [weak self] in
self?.alpha = 1.0
}, completion: { [weak self] (completion) in
backgroundColor = colors.a

let swapAnimation: (Bool) -> Void = { [weak self] (completed) in
guard let self = self, completed else { return }
UIView.animate(withDuration: 0.2, delay: 0.0, options: [.autoreverse, .repeat], animations: {
self?.swapBackgroundColor()
self.backgroundColor = self.colors.b
})
})
}

UIView.animate(withDuration: 0.1, animations: { [weak self] in
self?.alpha = 1.0
}, completion: swapAnimation)
}

private func stopProgressAnimation() {
isAnimating = false
layer.removeAllAnimations()
resetBackgroundColor()
backgroundColor = colors.a
UIView.animate(withDuration: 0.1, animations: { [weak self] in
self?.alpha = 0.0
}, completion: { [weak self] (completion) in
Expand All @@ -100,8 +93,4 @@ class ActivityBarView: UIView {
isHidden = true
layer.removeAllAnimations()
}

private func swapBackgroundColor() {
backgroundColor = backgroundColor == colorA ? colorB : colorA
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ class MapViewController: UIViewController {
}

let workModeChange: AppContextChange = .workMode { [weak self] workMode in
self?.activityBarView.colorA = (workMode == .online) ? UIColor.primary.lighter : UIColor.offline.lighter
self?.activityBarView.colorB = (workMode == .online) ? UIColor.primary.darker : UIColor.offline.darker
let color: UIColor = (workMode == .online) ? .primary : .offline
self?.activityBarView.colors = (color.lighter, color.darker)
self?.slideNotificationView.messageBackgroundColor = (workMode == .online) ? UIColor.primary.lighter : UIColor.offline.darker
}

Expand Down

0 comments on commit feb87d8

Please sign in to comment.