Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support customisation in Objective-C #27

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion Demo/ARSLineProgress.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +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
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)?
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