Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
6 changes: 5 additions & 1 deletion Demo/ARSLineProgress.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
276406C21C3832B700BCE105 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 276406C11C3832B700BCE105 /* Assets.xcassets */; };
276406C51C3832B700BCE105 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 276406C31C3832B700BCE105 /* LaunchScreen.storyboard */; };
27E116281C55844300661F75 /* ARSLineProgress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27E116271C55844300661F75 /* ARSLineProgress.swift */; };
938FA74420460F6D00B968F1 /* ARSLineProgressCustomizationObjcExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 938FA74320460F6D00B968F1 /* ARSLineProgressCustomizationObjcExt.swift */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -55,6 +56,7 @@
276406C41C3832B700BCE105 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
276406C61C3832B700BCE105 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
27E116271C55844300661F75 /* ARSLineProgress.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ARSLineProgress.swift; path = ../../Source/ARSLineProgress.swift; sourceTree = "<group>"; };
938FA74320460F6D00B968F1 /* ARSLineProgressCustomizationObjcExt.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ARSLineProgressCustomizationObjcExt.swift; path = ../../Source/ARSLineProgressCustomizationObjcExt.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -87,8 +89,9 @@
276406B91C3832B600BCE105 /* ARSLineProgress */ = {
isa = PBXGroup;
children = (
27E116271C55844300661F75 /* ARSLineProgress.swift */,
2734519E1DAA807000D53326 /* ARSLineProgressCustomization.swift */,
938FA74320460F6D00B968F1 /* ARSLineProgressCustomizationObjcExt.swift */,
27E116271C55844300661F75 /* ARSLineProgress.swift */,
2734519C1DAA807000D53326 /* ARSInfiniteLoader.swift */,
273451AC1DAA85A500D53326 /* ARSProgressLoader.swift */,
273451AE1DAA85DE00D53326 /* ARSStatus.swift */,
Expand Down Expand Up @@ -190,6 +193,7 @@
273451A71DAA82C800D53326 /* ARSLineProgressHelpers.swift in Sources */,
27E116281C55844300661F75 /* ARSLineProgress.swift in Sources */,
273451AD1DAA85A500D53326 /* ARSProgressLoader.swift in Sources */,
938FA74420460F6D00B968F1 /* ARSLineProgressCustomizationObjcExt.swift in Sources */,
276406BB1C3832B600BCE105 /* AppDelegate.swift in Sources */,
273451AB1DAA84AE00D53326 /* ARSLineProgressExtensions.swift in Sources */,
);
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>ARSLineProgress.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
8 changes: 5 additions & 3 deletions Source/ARSInfiniteLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ final class ARSInfiniteLoader: ARSLoader {
@objc var backgroundBlurView: UIVisualEffectView
@objc var backgroundSimpleView: UIView
@objc var backgroundFullView: UIView
@objc var title: NSString
@objc var backgroundView: UIView {
switch ars_config.backgroundViewStyle {
case .blur:
Expand All @@ -32,6 +33,7 @@ final class ARSInfiniteLoader: ARSLoader {
@objc weak var targetView: UIView?

init() {
title = ""
backgroundBlurView = ARSBlurredBackgroundRect().view
backgroundSimpleView = ARSSimpleBackgroundRect().view
backgroundFullView = ARSFullBackgroundRect().view
Expand All @@ -51,9 +53,9 @@ final class ARSInfiniteLoader: ARSLoader {
ars_dispatchOnMainQueue {
if let loader = ars_currentLoader {
if let targetView = loader.targetView {
ars_createdFrameForBackgroundView(loader.backgroundView, onView: targetView)
ars_createdFrameForBackgroundView(loader.backgroundView, title:loader.title, onView: targetView)
} else {
ars_createdFrameForBackgroundView(loader.backgroundView, onView: nil)
ars_createdFrameForBackgroundView(loader.backgroundView, title:loader.title, onView: nil)
Copy link
Owner

Choose a reason for hiding this comment

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

Please keep the formatting the same way it was before.

}
}
}
Expand All @@ -64,7 +66,7 @@ final class ARSInfiniteLoader: ARSLoader {
extension ARSInfiniteLoader {

func ars_showOnView(_ view: UIView?, completionBlock: (() -> Void)?) {
if ars_createdFrameForBackgroundView(backgroundView, onView: view) == false { return }
if ars_createdFrameForBackgroundView(backgroundView, title:self.title, onView: view) == false { return }

targetView = view

Expand Down
11 changes: 9 additions & 2 deletions Source/ARSLineProgress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,23 @@ public final class ARSLineProgress: NSObject {
Will interrupt the current .Infinite loader progress and show success animation instead.
*/
public static func showSuccess() {
if !statusShown { ARSStatus.show(.success) }
if !statusShown { ARSStatus.show(.success, title: "") }
}

public static func showSuccess(title: NSString) {
if !statusShown { ARSStatus.show(.success, title: title) }
}

/**
Will interrupt the current .Infinite loader progress and show fail animation instead.
*/
public static func showFail() {
if !statusShown { ARSStatus.show(.fail) }
if !statusShown { ARSStatus.show(.success, title: "") }
Copy link
Owner

Choose a reason for hiding this comment

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

Why showFail method is using .success parameter inside of it?

}

public static func showFail(title: NSString) {
if !statusShown { ARSStatus.show(.success, title: title) }
Copy link
Owner

Choose a reason for hiding this comment

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

The same one here: fail method has success parameter? Why?

}

// MARK: Show Infinite Loader

Expand Down
5 changes: 5 additions & 0 deletions Source/ARSLineProgressConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ let ARS_CIRCLE_LINE_WIDTH: CGFloat = 2.0
let ARS_CIRCLE_START_ANGLE: CGFloat = -CGFloat.pi / 2
let ARS_CIRCLE_END_ANGLE: CGFloat = 0.0

let ARS_TITLE_SIZE: CGFloat = 12.0
let ARS_TITLE_MARGIN: CGFloat = 3.0
let ARS_TITLE_COLOR: UIColor = UIColor.white;


weak var ars_currentStatus: ARSLoader?
var ars_currentLoader: ARSLoader?
var ars_currentCompletionBlock: (() -> Void)?
144 changes: 144 additions & 0 deletions Source/ARSLineProgressCustomizationObjcExt.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
//
// ARSLineProgressCustomizationObjcExt.swift
// ARSLineProgress
//
// Created by Johnnie on 28/02/18.
// Copyright © 2018 Iaroslav Arsenkin. All rights reserved.
//

import UIKit

extension ARSLineProgressConfiguration {
@objc static func ars_setShowSuccessCheckmark(show : Bool){
showSuccessCheckmark = show;
}

// MARK: background view
@objc static func ars_setBackgroundViewDismissTransformScale(scale : CGFloat){
backgroundViewDismissTransformScale = scale;
}

@objc static func ars_setBackgroundViewColor(color : CGColor){
backgroundViewColor = color;
}


/// setBackgroundViewStyle
///
/// - Parameter style: 0:blur, 1:simple, 2:full, default:blur
@objc static func ars_setBackgroundViewStyle(style : NSInteger){
switch style {

case 0:
backgroundViewStyle = .blur;
break;

case 1:
backgroundViewStyle = .simple;
break;

case 2:
backgroundViewStyle = .full;
break;


default:
backgroundViewStyle = .blur;
break;
}
}

@objc static func ars_setBackgroundViewCornerRadius(radius : CGFloat){
backgroundViewCornerRadius = radius;
}

@objc static func ars_setBackgroundViewPresentAnimationDuration(duration : CFTimeInterval){
backgroundViewPresentAnimationDuration = duration;
}

@objc static func ars_setBackgroundViewDismissAnimationDuration(duration : CFTimeInterval){
backgroundViewDismissAnimationDuration = duration;
}

@objc static func ars_setBlurStyle(style : UIBlurEffectStyle){
blurStyle = style;
}

// MARK: circles
@objc static func ars_setcircleColorOuter(color : CGColor){
circleColorOuter = color;
}

@objc static func ars_setcircleColorMiddle(color : CGColor){
circleColorMiddle = color;
}

@objc static func ars_setCircleColorInner(color : CGColor){
circleColorInner = color;
}

@objc static func ars_setCircleRotationDurationOuter(duration : CFTimeInterval){
circleRotationDurationOuter = duration;
}

@objc static func ars_setCircleRotationDurationMiddle(duration : CFTimeInterval){
circleRotationDurationMiddle = duration;
}

@objc static func ars_setCircleRotationDurationInner(duration : CFTimeInterval){
circleRotationDurationInner = duration;
}


// MARK: check mark
@objc static func ars_setCheckmarkAnimationDrawDuration(duration : CFTimeInterval){
checkmarkAnimationDrawDuration = duration;
}

@objc static func ars_setCheckmarkLineWidth(width : CGFloat){
checkmarkLineWidth = width;
}

@objc static func ars_setCheckmarkColor(color : CGColor){
checkmarkColor = color;
}

// MARK: success circle
@objc static func ars_setSuccessCircleAnimationDrawDuration(duration : CFTimeInterval){
successCircleAnimationDrawDuration = duration;
}

@objc static func ars_setSuccessCircleLineWidth(width : CGFloat){
successCircleLineWidth = width;
}

@objc static func ars_setSuccessCircleColor(color : CGColor){
successCircleColor = color;
}

// MARK: fail cross
@objc static func ars_setFailCrossAnimationDrawDuration(duration : CFTimeInterval){
failCrossAnimationDrawDuration = duration;
}

@objc static func ars_setFailCrossLineWidth(width : CGFloat){
failCrossLineWidth = width;
}

@objc static func ars_setFailCrossColor(color : CGColor){
failCrossColor = color;
}

// MARK: fail circel
@objc static func ars_setFailCircleAnimationDrawDuration(duration : CFTimeInterval){
failCircleAnimationDrawDuration = duration;
}

@objc static func ars_setFailCircleLineWidth(width : CGFloat){
failCircleLineWidth = width;
}

@objc static func ars_setFailCircleColor(color : CGColor){
failCircleColor = color;
}
}
15 changes: 14 additions & 1 deletion Source/ARSLineProgressHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,22 @@ func ars_window() -> UIWindow? {
return targetWindow
}

@discardableResult func ars_createdFrameForBackgroundView(_ backgroundView: UIView, onView view: UIView?) -> Bool {
func sizeForTitle(_ title : NSString?) -> CGSize{
if title != nil{
Copy link
Owner

Choose a reason for hiding this comment

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

  • Space before curly brace.
  • For comprehension it is better to use guards.

return title!.boundingRect(with:CGSize(width:0, height:0),
options:NSStringDrawingOptions.usesLineFragmentOrigin,
attributes:[NSFontAttributeName: UIFont.systemFont(ofSize: ARS_TITLE_SIZE)],
context:nil)
.size
}

return CGSize(width:0, height:0)
}

@discardableResult func ars_createdFrameForBackgroundView(_ backgroundView: UIView, title: NSString?, onView view: UIView?) -> Bool {
let center: CGPoint
let bounds: CGRect
let lbSize = sizeForTitle(title)

if view == nil {
guard let window = ars_window() else { return false }
Expand Down
1 change: 1 addition & 0 deletions Source/ARSLineProgressProtocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import UIKit
@objc protocol ARSLoader {
var emptyView: UIView { get }
var backgroundView: UIView { get }
@objc var title: NSString { get set }
@objc optional var outerCircle: CAShapeLayer { get set }
@objc optional var middleCircle: CAShapeLayer { get set }
@objc optional var innerCircle: CAShapeLayer { get set }
Expand Down
12 changes: 7 additions & 5 deletions Source/ARSProgressLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ final class ARSProgressLoader: ARSLoader {
@objc var backgroundBlurView: UIView
@objc var backgroundSimpleView: UIView
@objc var backgroundFullView: UIView
@objc var title: NSString
@objc var backgroundView: UIView {
switch ars_config.backgroundViewStyle {
case .blur:
Expand All @@ -38,6 +39,7 @@ final class ARSProgressLoader: ARSLoader {
@objc weak var targetView: UIView?

init() {
title = ""
backgroundBlurView = ARSBlurredBackgroundRect().view
backgroundSimpleView = ARSSimpleBackgroundRect().view
backgroundFullView = ARSFullBackgroundRect().view
Expand All @@ -58,9 +60,9 @@ final class ARSProgressLoader: ARSLoader {
ars_dispatchOnMainQueue {
if let loader = ars_currentLoader {
if let targetView = loader.targetView {
ars_createdFrameForBackgroundView(loader.backgroundView, onView: targetView)
ars_createdFrameForBackgroundView(loader.backgroundView, title:loader.title, onView: targetView)
} else {
ars_createdFrameForBackgroundView(loader.backgroundView, onView: nil)
ars_createdFrameForBackgroundView(loader.backgroundView, title:loader.title, onView: nil)
}
}
}
Expand All @@ -73,7 +75,7 @@ extension ARSProgressLoader {
// MARK: Show/Cancel

func ars_showWithValue(_ value: CGFloat, onView view: UIView?, progress: Progress?, completionBlock: (() -> Void)?) {
if ars_createdFrameForBackgroundView(backgroundView, onView: view) == false { return }
if ars_createdFrameForBackgroundView(backgroundView, title:title, onView: view) == false { return }
if let progress = progress { self.progress = progress }

ars_currentCompletionBlock = completionBlock
Expand Down Expand Up @@ -188,7 +190,7 @@ extension ARSProgressLoader {

ars_dispatchAfter(0.9) {
if ARSLineProgressConfiguration.showSuccessCheckmark {
ARSStatus.show(.success)
ARSStatus.show(.success, title: self.title)

let dismissDelay = 0.5 + max(ARSLineProgressConfiguration.successCircleAnimationDrawDuration, ARSLineProgressConfiguration.checkmarkAnimationDrawDuration)

Expand All @@ -202,7 +204,7 @@ extension ARSProgressLoader {
}

func ars_failedLoading() {
ARSStatus.show(.fail)
ARSStatus.show(.fail, title: self.title)
let dismissDelay = 0.5 + max(ARSLineProgressConfiguration.failCircleAnimationDrawDuration, ARSLineProgressConfiguration.failCrossAnimationDrawDuration)

ars_dispatchAfter(dismissDelay) {
Expand Down
10 changes: 6 additions & 4 deletions Source/ARSStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ final class ARSStatus: ARSLoader {
@objc var backgroundBlurView: UIVisualEffectView
@objc var backgroundSimpleView: UIView
@objc var backgroundFullView: UIView
@objc var title: NSString
@objc var backgroundView: UIView {
switch ars_config.backgroundViewStyle {
case .blur:
Expand All @@ -33,10 +34,11 @@ final class ARSStatus: ARSLoader {
}

init() {
title = ""
backgroundBlurView = ARSBlurredBackgroundRect().view
backgroundSimpleView = ARSSimpleBackgroundRect().view
backgroundFullView = ARSFullBackgroundRect().view
ars_createdFrameForBackgroundView(backgroundView, onView: nil)
ars_createdFrameForBackgroundView(backgroundView, title:title, onView: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(ARSInfiniteLoader.orientationChanged(_:)),
name: NSNotification.Name.UIDeviceOrientationDidChange,
Expand All @@ -53,15 +55,15 @@ final class ARSStatus: ARSLoader {
ars_dispatchOnMainQueue {
if let loader = ars_currentLoader {
if let targetView = loader.targetView {
ars_createdFrameForBackgroundView(loader.backgroundView, onView: targetView)
ars_createdFrameForBackgroundView(loader.backgroundView, title:loader.title, onView: targetView)
} else {
ars_createdFrameForBackgroundView(loader.backgroundView, onView: nil)
ars_createdFrameForBackgroundView(loader.backgroundView, title:loader.title, onView: nil)
}
}
}
}

static func show(_ type: ARSStatusType) {
static func show(_ type: ARSStatusType, title: NSString) {
if let loader = ars_currentLoader {
ars_stopCircleAnimations(loader, completionBlock: {
drawStatus(type, loader: loader)
Expand Down