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 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
8 changes: 6 additions & 2 deletions 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,16 +89,17 @@
276406B91C3832B600BCE105 /* ARSLineProgress */ = {
isa = PBXGroup;
children = (
27E116271C55844300661F75 /* ARSLineProgress.swift */,
2734519E1DAA807000D53326 /* ARSLineProgressCustomization.swift */,
938FA74320460F6D00B968F1 /* ARSLineProgressCustomizationObjcExt.swift */,
27E116271C55844300661F75 /* ARSLineProgress.swift */,
273451A41DAA81FB00D53326 /* ARSLineProgressProtocols.swift */,
2734519C1DAA807000D53326 /* ARSInfiniteLoader.swift */,
273451AC1DAA85A500D53326 /* ARSProgressLoader.swift */,
273451AE1DAA85DE00D53326 /* ARSStatus.swift */,
273451A61DAA82C800D53326 /* ARSLineProgressHelpers.swift */,
273451A81DAA831500D53326 /* ARSLineProgressConstants.swift */,
273451AA1DAA84AE00D53326 /* ARSLineProgressExtensions.swift */,
273451A21DAA80CD00D53326 /* ARSLineProgressTypeAliases.swift */,
273451A41DAA81FB00D53326 /* ARSLineProgressProtocols.swift */,
276406BC1C3832B600BCE105 /* ViewController.swift */,
276406BA1C3832B600BCE105 /* AppDelegate.swift */,
276406BE1C3832B700BCE105 /* Main.storyboard */,
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,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "../Source/ARSInfiniteLoader.swift"
timestampString = "541594035.350356"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "89"
endingLineNumber = "89"
landmarkName = "ars_showOnView(_:title:completionBlock:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "../Source/ARSLineProgress.swift"
timestampString = "541594035.35042"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "26"
endingLineNumber = "26"
landmarkName = "showSuccess()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "../Source/ARSStatus.swift"
timestampString = "541594035.350492"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "81"
endingLineNumber = "81"
landmarkName = "drawStatus(_:title:loader:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "../Source/ARSStatus.swift"
timestampString = "541594035.3507921"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "68"
endingLineNumber = "68"
landmarkName = "show(_:title:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
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>
17 changes: 10 additions & 7 deletions Demo/ARSLineProgress/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ final class ViewController: UIViewController {

@IBAction func showInfiniteLoader(_ sender: AnyObject) {
if ARSLineProgress.shown { return }

ARSLineProgress.showWithPresentCompetionBlock { () -> Void in
ARSLineProgress.showWithPresentCompetionBlock("I am title") {
print("Showed with completion block")
}


DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(3 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC), execute: { () -> Void in
ARSLineProgress.hideWithCompletionBlock({ () -> Void in
print("Hidden with completion block")
})

ARSLineProgress.showSuccess()
// ARSLineProgress.hideWithCompletionBlock({ () -> Void in
// print("Hidden with completion block")
// })
})
}

Expand Down Expand Up @@ -65,11 +68,11 @@ final class ViewController: UIViewController {
}

@IBAction func didTapShowSuccessButton(_ sender: AnyObject) {
ARSLineProgress.showSuccess()
ARSLineProgress.showSuccess("Success")
}

@IBAction func didTapShowFailButton(_ sender: AnyObject) {
ARSLineProgress.showFail()
ARSLineProgress.showFail("Fail")
}

@IBAction func showFullBackgroundLoader(_ sender: AnyObject) {
Expand Down
31 changes: 26 additions & 5 deletions Source/ARSInfiniteLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ final class ARSInfiniteLoader: ARSLoader {
@objc var backgroundBlurView: UIVisualEffectView
@objc var backgroundSimpleView: UIView
@objc var backgroundFullView: UIView
@objc var lbTitle: UILabel = UILabel()
@objc var title: String
@objc var backgroundView: UIView {
switch ars_config.backgroundViewStyle {
case .blur:
Expand All @@ -32,9 +34,14 @@ final class ARSInfiniteLoader: ARSLoader {
@objc weak var targetView: UIView?

init() {
title = ""
backgroundBlurView = ARSBlurredBackgroundRect().view
backgroundSimpleView = ARSSimpleBackgroundRect().view
backgroundFullView = ARSFullBackgroundRect().view

lbTitle.textColor = ARS_TITLE_COLOR
lbTitle.font = UIFont.systemFont(ofSize: ARS_TITLE_SIZE)

NotificationCenter.default.addObserver(self,
selector: #selector(ARSInfiniteLoader.orientationChanged(_:)),
name: NSNotification.Name.UIDeviceOrientationDidChange,
Expand All @@ -51,9 +58,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 @@ -63,14 +70,28 @@ final class ARSInfiniteLoader: ARSLoader {

extension ARSInfiniteLoader {

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

func ars_showOnView(_ view: UIView?, title: String, completionBlock: (() -> Void)?) {
self.title = title

if ars_createdFrameForBackgroundView(backgroundView, title:self.title, onView: view) == false { return }

if(title.count > 0){
lbTitle.text = self.title;
lbTitle.sizeToFit();
let parentView = ((backgroundView as? UIVisualEffectView)?.contentView) ?? backgroundView;
parentView.addSubview(lbTitle);

lbTitle.center = CGPoint(x:parentView.center.x,
y:parentView.frame.origin.y + backgroundView.frame.size.height - ARS_TITLE_MARGIN - lbTitle.frame.size.height);
}


targetView = view

ars_createCircles(outerCircle,
middleCircle: middleCircle,
innerCircle: innerCircle,
title: title,
onView: ((backgroundView as? UIVisualEffectView)?.contentView) ?? backgroundView,
loaderType: .infinite)
ars_animateCircles(outerCircle, middleCircle: middleCircle, innerCircle: innerCircle)
Expand Down
41 changes: 35 additions & 6 deletions Source/ARSLineProgress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,63 @@ 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) }
showSuccess("")
}

public static func showSuccess(_ title: String) {
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) }
showFail("")
}

public static func showFail(_ title: String) {
if !statusShown { ARSStatus.show(.fail, title: title) }
}

// MARK: Show Infinite Loader


public static func show() {
if !shown { ARSInfiniteLoader().ars_showOnView(nil, completionBlock: nil) }
show("")
}

public static func show(_ title: String) {
if !shown { ARSInfiniteLoader().ars_showOnView(nil, title:title, completionBlock: nil) }
}



public static func showWithPresentCompetionBlock(_ block: @escaping () -> Void) {
if !shown { ARSInfiniteLoader().ars_showOnView(nil, completionBlock: block) }
showWithPresentCompetionBlock("", block: block)
}

public static func showWithPresentCompetionBlock(_ title: String, block: @escaping () -> Void) {
if !shown { ARSInfiniteLoader().ars_showOnView(nil, title:title, completionBlock: block) }
}



public static func ars_showOnView(_ view: UIView) {
if !shown { ARSInfiniteLoader().ars_showOnView(view, completionBlock: nil) }
ars_showOnView(view, title:"")
}

public static func ars_showOnView(_ view: UIView, title: String) {
if !shown { ARSInfiniteLoader().ars_showOnView(view, title: title, completionBlock: nil) }
}



public static func ars_showOnView(_ view: UIView, completionBlock: @escaping () -> Void) {
if !shown { ARSInfiniteLoader().ars_showOnView(view, completionBlock: completionBlock) }
ars_showOnView(view, title:"", completionBlock:completionBlock)
}

public static func ars_showOnView(_ view: UIView, title: String, completionBlock: @escaping () -> Void) {
if !shown { ARSInfiniteLoader().ars_showOnView(view, title: title, completionBlock: completionBlock) }
}


Expand Down
9 changes: 7 additions & 2 deletions Source/ARSLineProgressConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

import UIKit

let ARS_BACKGROUND_VIEW_SIDE_LENGTH: CGFloat = 125.0
let ARS_STATUS_PATH_SIDE_LENGTH: CGFloat = 125.0
let ARS_BACKGROUND_VIEW_SIDE_LENGTH: CGFloat = 110.0
let ARS_STATUS_PATH_SIDE_LENGTH: CGFloat = 110.0

let ARS_CIRCLE_ROTATION_TO_VALUE = 2 * CGFloat.pi
let ARS_CIRCLE_ROTATION_REPEAT_COUNT = Float(UINT64_MAX)
Expand All @@ -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)?
Loading