Skip to content

Commit

Permalink
Adds a bit more clarity to how the success blocks are used within the…
Browse files Browse the repository at this point in the history
… class
  • Loading branch information
soberman committed Jan 24, 2016
1 parent 952bea9 commit 47770df
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
6 changes: 4 additions & 2 deletions ARSLineProgress/ARSLineProgress/ARSLineProgress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public final class ARSLineProgress {
InfiniteLoader().showOnView(nil, completionBlock: nil)
}

static func showWithCompetionBlock(block: () -> Void) {
static func showWithPresentCompetionBlock(block: () -> Void) {
InfiniteLoader().showOnView(nil, completionBlock: block)
}

Expand Down Expand Up @@ -271,13 +271,15 @@ private extension ProgressLoader {
if createdFrameForBackgroundView(backgroundView, onView: view) == false { return }
if let progress = progress { self.progress = progress }

currentCompletionBlock = completionBlock

createCircles(outerCircle: outerCircle,
middleCircle: middleCircle,
innerCircle: innerCircle,
onView: backgroundView.contentView,
loaderType: .Progress)
animateCircles(outerCircle: outerCircle, middleCircle: middleCircle, innerCircle: innerCircle)
presentLoader(self, onView: view, completionBlock: completionBlock)
presentLoader(self, onView: view, completionBlock: nil)
launchTimer()
}

Expand Down
11 changes: 11 additions & 0 deletions ARSLineProgress/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@
<action selector="showProgressLoaderWithSuccess:" destination="BYZ-38-t0r" eventType="touchUpInside" id="ADJ-c9-zTf"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="W26-F9-oNZ">
<rect key="frame" x="140" y="430" width="321" height="30"/>
<state key="normal" title="Show Progress Loader Without Final Animation">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="showProgressWithoutAnimation:" destination="BYZ-38-t0r" eventType="touchUpInside" id="xJ2-sq-d0F"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="EWM-RC-RUO">
<rect key="frame" x="192" y="320" width="217" height="30"/>
<state key="normal" title="Show Progress Loader With Fail">
Expand All @@ -50,11 +59,13 @@
</subviews>
<color key="backgroundColor" red="0.96078431369999995" green="0.35686274509999999" blue="0.38823529410000002" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstItem="W26-F9-oNZ" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="2Cj-jB-90b"/>
<constraint firstItem="EWM-RC-RUO" firstAttribute="top" secondItem="09r-nG-K4g" secondAttribute="bottom" constant="80" id="4VH-MA-Yb8"/>
<constraint firstItem="Yix-sF-EUZ" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="JOS-uC-f4S"/>
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="Yix-sF-EUZ" secondAttribute="bottom" id="Lpb-FX-fdt"/>
<constraint firstItem="09r-nG-K4g" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="PY9-Ie-QOs"/>
<constraint firstItem="EWM-RC-RUO" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="TOP-Ko-aUm"/>
<constraint firstItem="W26-F9-oNZ" firstAttribute="top" secondItem="EWM-RC-RUO" secondAttribute="bottom" constant="80" id="TQb-SB-1mo"/>
<constraint firstItem="C6W-fh-tOi" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="XLH-VV-Bf4"/>
<constraint firstAttribute="trailing" secondItem="Yix-sF-EUZ" secondAttribute="trailing" id="Ycu-UQ-mCR"/>
<constraint firstItem="09r-nG-K4g" firstAttribute="top" secondItem="C6W-fh-tOi" secondAttribute="bottom" constant="80" id="ami-Dz-Sp4"/>
Expand Down
23 changes: 16 additions & 7 deletions ARSLineProgress/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@
import UIKit

final class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
}

@IBAction func showInfiniteLoader(sender: AnyObject) {
ARSLineProgress.showWithCompetionBlock { () -> Void in
ARSLineProgress.showWithPresentCompetionBlock { () -> Void in
print("Showed with completion block")
}

Expand All @@ -26,10 +22,12 @@ final class ViewController: UIViewController {
})
}

// MARK: In case you want, you can use regular CGFloat value with showWithProgress(initialValue: 1.0) method.

@IBAction func showProgressLoaderWithSuccess(sender: AnyObject) {
progressObject = NSProgress(totalUnitCount: 100)
ARSLineProgress.showWithProgressObject(progressObject!, completionBlock: {
print("Showed with completion block")
print("Success completion block")
})

progressDemoHelper(success: true)
Expand All @@ -38,13 +36,24 @@ final class ViewController: UIViewController {
@IBAction func showProgressLoaderWithFail(sender: AnyObject) {
progressObject = NSProgress(totalUnitCount: 100)
ARSLineProgress.showWithProgressObject(progressObject!, completionBlock: {
print("Showed with completion block")
print("This copmletion block is going to be overriden by cancel completion block in launchTimer() method.")
})

progressDemoHelper(success: false)
}


@IBAction func showProgressWithoutAnimation(sender: AnyObject) {
ARSLineProgressConfiguration.showSuccessCheckmark = false

progressObject = NSProgress(totalUnitCount: 100)
ARSLineProgress.showWithProgressObject(progressObject!, completionBlock: {
print("Success completion block")
})

progressDemoHelper(success: true)
}

}


Expand Down

0 comments on commit 47770df

Please sign in to comment.