Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions Sources/Tropos/Views/CircularProgressLayer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import UIKit

@objc(TRCircularProgressLayer) class CircularProgressLayer: CALayer {
@objc var progress: CGFloat = CGFloat(0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be either : CGFloat = 0 or = CGFloat(0) (I usually prefer the former).

@objc var radius = CGFloat(15.0)
@objc let outerRingWidth = CGFloat(3.0)

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}

override init() {
super.init()
self.actions = [
"bounds": NSNull(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, does a nil literal work here? AFAIK nil should be bridged to NSNull, but I’m not sure if that works for CAAction.

"contents": NSNull(),
"position": NSNull(),
]
self.contentsScale = UIScreen.main.scale
self.needsDisplayOnBoundsChange = true
}

init(layer: CircularProgressLayer) {
super.init(layer: layer)
progress = layer.progress
radius = layer.radius
}

override func draw(in ctx: CGContext) {
let center = CGPoint(x: self.bounds.width / 2.0, y: self.bounds.height / 2.0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that in order to match the previous behaviour of TRCGPointMakeIntegral(), these should be round()ed. Maybe a CGPoint extension with a func integral() that returns a new point with each dimension rounded?

let progress = min(self.progress, 1.0 - CGFloat.ulpOfOne)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could drop the explicit CGFloat and become .ulpOfOne.

let radians = (progress * .pi * 2.0) - .pi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be - (.pi / 2)? Previously this was (CGFloat)M_PI_2.


ctx.setFillColor(self.backgroundColor ?? UIColor.black.cgColor)
ctx.fill(bounds)
ctx.setBlendMode(.clear)
ctx.setLineWidth(CGFloat(outerRingWidth))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is outerRingWidth already CGFloat?

ctx.setStrokeColor(UIColor.clear.cgColor)
ctx.addArc(
center: center,
radius: CGFloat(radius),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is radius already a CGFloat?

startAngle: 0.0,
endAngle: 2 * .pi,
clockwise: false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous version of this specified clockwise as YES.

)
ctx.strokePath()

if progress > 0.0 {
ctx.setFillColor(UIColor.clear.cgColor)
let progressPath = CGMutablePath()
progressPath.move(to: center)
progressPath.addArc(
center: center,
radius: CGFloat(self.radius),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already CGFloat?

startAngle: 3.0 * .pi,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was previously 3.0f * (CGFloat)M_PI_2, or 1.5 * .pi.

endAngle: radians,
clockwise: false
)
ctx.closePath()
ctx.addPath(progressPath)
ctx.fillPath()
}
}

override class func needsDisplay(forKey key: String) -> Bool {
switch key {
case "progress", "radius", "outerRingWidth":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use #keyPath(progress), #keyPath(radius), etc., here to avoid the string literals.

return true
default:
return false
}
}
}
9 changes: 0 additions & 9 deletions Sources/Tropos/Views/TRCircularProgressLayer.h

This file was deleted.

96 changes: 0 additions & 96 deletions Sources/Tropos/Views/TRCircularProgressLayer.m

This file was deleted.

2 changes: 1 addition & 1 deletion Sources/Tropos/Views/TRRefreshView.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#import "Tropos-Swift.h"
#import "TRRefreshView.h"
#import "TRCircularProgressLayer.h"
#import "TRColorBackdropLayer.h"
#import "TRRefreshLayer.h"

Expand Down
10 changes: 4 additions & 6 deletions Tropos.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
0F9A6CB421C9A9D40035C811 /* CLLocation+TRRecentLocation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F9A6CB121C996EC0035C811 /* CLLocation+TRRecentLocation.swift */; };
0F9A6CBA21CBF4C30035C811 /* LocationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F9A6CB921CBF4C30035C811 /* LocationController.swift */; };
0FB1907821E3AF8900A2A8CA /* CircularProgressLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0FB1907721E3AF8800A2A8CA /* CircularProgressLayer.swift */; };
4A21D76820C9E6FA0055A2AF /* IntentHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A21D76720C9E6FA0055A2AF /* IntentHandler.swift */; };
4A21D76C20C9E6FB0055A2AF /* TroposIntents.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 4A21D76520C9E6FA0055A2AF /* TroposIntents.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
4A5109D520C9CB8100F993FC /* INInteraction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A5109D420C9CB8100F993FC /* INInteraction.swift */; };
Expand Down Expand Up @@ -114,7 +115,6 @@
4D1ABA0B1A89686200B7F8FB /* TRNavigationBar.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D1ABA0A1A89686200B7F8FB /* TRNavigationBar.m */; };
4D3336F61A80BE16001BA9A8 /* TRDailyForecastView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4D3336F51A80BE16001BA9A8 /* TRDailyForecastView.xib */; };
4D49554C1A8C298A0066F278 /* TRRefreshView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D49554B1A8C298A0066F278 /* TRRefreshView.m */; };
4D49554F1A8C29C30066F278 /* TRCircularProgressLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D49554E1A8C29C30066F278 /* TRCircularProgressLayer.m */; };
4D4955521A8C2B5D0066F278 /* UIImage+TRColorBackdrop.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D4955511A8C2B5D0066F278 /* UIImage+TRColorBackdrop.m */; };
4D7389DF1A9890CD0039F13B /* UIScrollView+TRReactiveCocoa.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D7389DE1A9890CD0039F13B /* UIScrollView+TRReactiveCocoa.m */; };
4D76CCD41A99C3FA00DDE5EB /* TRRefreshLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D76CCD31A99C3FA00DDE5EB /* TRRefreshLayer.m */; };
Expand Down Expand Up @@ -241,6 +241,7 @@
0B30A1610CAE1C2E302C28B0 /* Info.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
0F9A6CB121C996EC0035C811 /* CLLocation+TRRecentLocation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CLLocation+TRRecentLocation.swift"; sourceTree = "<group>"; };
0F9A6CB921CBF4C30035C811 /* LocationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationController.swift; sourceTree = "<group>"; };
0FB1907721E3AF8800A2A8CA /* CircularProgressLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CircularProgressLayer.swift; sourceTree = "<group>"; };
1CDD2312F1EF05277F045E15 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
22FE01C01AF3F5550085B494 /* Secrets.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Secrets.h; sourceTree = "<group>"; };
449386DA1B5044EE00766EC9 /* pl-PL */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pl-PL"; path = "pl-PL.lproj/Localizable.strings"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -348,8 +349,6 @@
4D3336F51A80BE16001BA9A8 /* TRDailyForecastView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TRDailyForecastView.xib; sourceTree = "<group>"; };
4D49554A1A8C298A0066F278 /* TRRefreshView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TRRefreshView.h; sourceTree = "<group>"; };
4D49554B1A8C298A0066F278 /* TRRefreshView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TRRefreshView.m; sourceTree = "<group>"; };
4D49554D1A8C29C30066F278 /* TRCircularProgressLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TRCircularProgressLayer.h; sourceTree = "<group>"; };
4D49554E1A8C29C30066F278 /* TRCircularProgressLayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TRCircularProgressLayer.m; sourceTree = "<group>"; };
4D4955501A8C2B5D0066F278 /* UIImage+TRColorBackdrop.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+TRColorBackdrop.h"; sourceTree = "<group>"; };
4D4955511A8C2B5D0066F278 /* UIImage+TRColorBackdrop.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+TRColorBackdrop.m"; sourceTree = "<group>"; };
4D7389DD1A9890CD0039F13B /* UIScrollView+TRReactiveCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIScrollView+TRReactiveCocoa.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -781,10 +780,9 @@
639AAB142C96B59FC995CA1D /* Views */ = {
isa = PBXGroup;
children = (
0FB1907721E3AF8800A2A8CA /* CircularProgressLayer.swift */,
51FEC99D21CD9F3300CDBC97 /* FadingImageView.swift */,
51FEC99921CD9AC500CDBC97 /* FadingLabel.swift */,
4D49554D1A8C29C30066F278 /* TRCircularProgressLayer.h */,
4D49554E1A8C29C30066F278 /* TRCircularProgressLayer.m */,
4DC069CB1A95B8F800F3BCEB /* TRColorBackdropLayer.h */,
4DC069CC1A95B8F800F3BCEB /* TRColorBackdropLayer.m */,
4D98E9831A80C43F00856412 /* TRDailyForecastView.h */,
Expand Down Expand Up @@ -1325,7 +1323,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
4D49554F1A8C29C30066F278 /* TRCircularProgressLayer.m in Sources */,
4D7389DF1A9890CD0039F13B /* UIScrollView+TRReactiveCocoa.m in Sources */,
4AA138C42134835A0083B816 /* Intents.intentdefinition in Sources */,
4DC069CD1A95B8F800F3BCEB /* TRColorBackdropLayer.m in Sources */,
Expand All @@ -1334,6 +1331,7 @@
4DDF65061AB3AC0C00909D67 /* TRWeatherController.m in Sources */,
4ACA584B1CC526D600DD0CDC /* RACSignal+TROperators.m in Sources */,
4A86FB65205C0E4D00E761C3 /* AppDelegate.swift in Sources */,
0FB1907821E3AF8900A2A8CA /* CircularProgressLayer.swift in Sources */,
A10109001D336C9C0024B1BA /* TRTableViewCell.swift in Sources */,
4D49554C1A8C298A0066F278 /* TRRefreshView.m in Sources */,
A12FCE251D336FA90062E7F1 /* Color.swift in Sources */,
Expand Down