Skip to content

Commit

Permalink
added activity indicator while app is loading
Browse files Browse the repository at this point in the history
  • Loading branch information
xtools-at committed Nov 5, 2017
1 parent 46b352f commit db5d6ef
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
21 changes: 20 additions & 1 deletion ios-pwa-wrapper/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,38 @@
<constraint firstItem="PAe-DD-sEP" firstAttribute="leading" secondItem="P71-RQ-w3Y" secondAttribute="leading" id="Vx8-ru-pdt"/>
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="yda-zQ-zIG">
<rect key="frame" x="0.0" y="94" width="375" height="573"/>
<subviews>
<activityIndicatorView opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" style="whiteLarge" translatesAutoresizingMaskIntoConstraints="NO" id="Khc-j7-EfD">
<rect key="frame" x="169" y="268" width="37" height="37"/>
</activityIndicatorView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="Khc-j7-EfD" firstAttribute="centerY" secondItem="yda-zQ-zIG" secondAttribute="centerY" id="JFG-v5-tUo"/>
<constraint firstItem="Khc-j7-EfD" firstAttribute="centerX" secondItem="yda-zQ-zIG" secondAttribute="centerX" id="Tth-E6-6fh"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="HnO-cS-a4I" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="4Ug-Ri-DYo"/>
<constraint firstItem="HnO-cS-a4I" firstAttribute="trailing" secondItem="6Tk-OE-BBY" secondAttribute="trailing" id="6t2-kT-aXm"/>
<constraint firstItem="P71-RQ-w3Y" firstAttribute="bottom" secondItem="6Tk-OE-BBY" secondAttribute="bottom" id="7Mx-39-uRU"/>
<constraint firstItem="HnO-cS-a4I" firstAttribute="bottom" secondItem="6Tk-OE-BBY" secondAttribute="bottom" id="JRX-v6-mMT"/>
<constraint firstItem="yda-zQ-zIG" firstAttribute="trailing" secondItem="6Tk-OE-BBY" secondAttribute="trailing" id="NI8-nf-K0C"/>
<constraint firstItem="HnO-cS-a4I" firstAttribute="bottom" secondItem="6Tk-OE-BBY" secondAttribute="bottom" id="NPb-ae-PDf"/>
<constraint firstItem="P71-RQ-w3Y" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" id="Orj-az-JIO"/>
<constraint firstItem="yda-zQ-zIG" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" constant="30" id="PKU-aR-WIX"/>
<constraint firstItem="P71-RQ-w3Y" firstAttribute="trailing" secondItem="6Tk-OE-BBY" secondAttribute="trailing" id="TlA-35-iyi"/>
<constraint firstItem="HnO-cS-a4I" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" id="YQr-yE-Fj0"/>
<constraint firstItem="HnO-cS-a4I" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" id="YhM-LV-Tya"/>
<constraint firstItem="HnO-cS-a4I" firstAttribute="trailing" secondItem="6Tk-OE-BBY" secondAttribute="trailing" id="Zu4-1h-MTC"/>
<constraint firstItem="yda-zQ-zIG" firstAttribute="bottom" secondItem="6Tk-OE-BBY" secondAttribute="bottom" id="iHx-Ip-sA5"/>
<constraint firstItem="HnO-cS-a4I" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="ovE-sY-kNb"/>
<constraint firstItem="P71-RQ-w3Y" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="wb5-bQ-9sI"/>
<constraint firstItem="yda-zQ-zIG" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="wyR-np-tM4"/>
</constraints>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
Expand All @@ -85,6 +102,8 @@
</barButtonItem>
</navigationItem>
<connections>
<outlet property="activityIndicator" destination="Khc-j7-EfD" id="zH9-hm-Umn"/>
<outlet property="activityIndicatorView" destination="yda-zQ-zIG" id="cm3-vM-rx8"/>
<outlet property="leftButton" destination="mlw-cf-kRg" id="5PJ-wX-nGG"/>
<outlet property="offlineButton" destination="M9z-jX-53J" id="wBQ-7m-k9x"/>
<outlet property="offlineIcon" destination="oc6-1O-6cw" id="rvO-Bh-ce9"/>
Expand All @@ -95,7 +114,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1047" y="476"/>
<point key="canvasLocation" x="1045.5999999999999" y="475.41229385307349"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="1sK-l5-PHi">
Expand Down
1 change: 1 addition & 0 deletions ios-pwa-wrapper/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ let navigationButtonColor = navigationTitleColor
let progressBarColor = getColorFromHex(hex: 0x4CAF50, alpha: 1.0)
let offlineIconColor = UIColor.darkGray
let buttonColor = navigationBarColor
let activityIndicatorColor = navigationBarColor

// Color Helper function
func getColorFromHex(hex: UInt, alpha: CGFloat) -> UIColor {
Expand Down
18 changes: 14 additions & 4 deletions ios-pwa-wrapper/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class ViewController: UIViewController {
@IBOutlet weak var offlineView: UIView!
@IBOutlet weak var offlineIcon: UIImageView!
@IBOutlet weak var offlineButton: UIButton!
@IBOutlet weak var activityIndicatorView: UIView!
@IBOutlet weak var activityIndicator: UIActivityIndicatorView!

// MARK: Globals
var webView: WKWebView!
Expand Down Expand Up @@ -56,12 +58,13 @@ class ViewController: UIViewController {

// Observers for updating UI
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
/*
if (keyPath == #keyPath(WKWebView.isLoading)) {
// does not fire for PWAs if links are clicked
// leftButton.isEnabled = webView.canGoBack
// show activity indicator
if (webView.isLoading) {
activityIndicatorView.isHidden = false
activityIndicator.startAnimating()
}
}
*/
if (keyPath == #keyPath(WKWebView.estimatedProgress)) {
progressBar.progress = Float(webView.estimatedProgress)
rightButton.isEnabled = (webView.estimatedProgress == 1)
Expand Down Expand Up @@ -120,6 +123,10 @@ class ViewController: UIViewController {
progressBar.tintColor = progressBarColor
webView.addSubview(progressBar)

// activity indicator
activityIndicator.color = activityIndicatorColor
activityIndicator.startAnimating()

// offline container
offlineIcon.tintColor = offlineIconColor
offlineButton.tintColor = buttonColor
Expand Down Expand Up @@ -173,6 +180,9 @@ extension ViewController: WKNavigationDelegate {
}
// hide progress bar after initial load
progressBar.isHidden = true
// hide activity indicator
activityIndicatorView.isHidden = true
activityIndicator.stopAnimating()
}
// didFailProvisionalNavigation
func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
Expand Down

0 comments on commit db5d6ef

Please sign in to comment.