Skip to content

Commit db5d6ef

Browse files
committed
added activity indicator while app is loading
1 parent 46b352f commit db5d6ef

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

ios-pwa-wrapper/Base.lproj/Main.storyboard

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,38 @@
5454
<constraint firstItem="PAe-DD-sEP" firstAttribute="leading" secondItem="P71-RQ-w3Y" secondAttribute="leading" id="Vx8-ru-pdt"/>
5555
</constraints>
5656
</view>
57+
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="yda-zQ-zIG">
58+
<rect key="frame" x="0.0" y="94" width="375" height="573"/>
59+
<subviews>
60+
<activityIndicatorView opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" style="whiteLarge" translatesAutoresizingMaskIntoConstraints="NO" id="Khc-j7-EfD">
61+
<rect key="frame" x="169" y="268" width="37" height="37"/>
62+
</activityIndicatorView>
63+
</subviews>
64+
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
65+
<constraints>
66+
<constraint firstItem="Khc-j7-EfD" firstAttribute="centerY" secondItem="yda-zQ-zIG" secondAttribute="centerY" id="JFG-v5-tUo"/>
67+
<constraint firstItem="Khc-j7-EfD" firstAttribute="centerX" secondItem="yda-zQ-zIG" secondAttribute="centerX" id="Tth-E6-6fh"/>
68+
</constraints>
69+
</view>
5770
</subviews>
5871
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
5972
<constraints>
6073
<constraint firstItem="HnO-cS-a4I" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="4Ug-Ri-DYo"/>
6174
<constraint firstItem="HnO-cS-a4I" firstAttribute="trailing" secondItem="6Tk-OE-BBY" secondAttribute="trailing" id="6t2-kT-aXm"/>
6275
<constraint firstItem="P71-RQ-w3Y" firstAttribute="bottom" secondItem="6Tk-OE-BBY" secondAttribute="bottom" id="7Mx-39-uRU"/>
6376
<constraint firstItem="HnO-cS-a4I" firstAttribute="bottom" secondItem="6Tk-OE-BBY" secondAttribute="bottom" id="JRX-v6-mMT"/>
77+
<constraint firstItem="yda-zQ-zIG" firstAttribute="trailing" secondItem="6Tk-OE-BBY" secondAttribute="trailing" id="NI8-nf-K0C"/>
6478
<constraint firstItem="HnO-cS-a4I" firstAttribute="bottom" secondItem="6Tk-OE-BBY" secondAttribute="bottom" id="NPb-ae-PDf"/>
6579
<constraint firstItem="P71-RQ-w3Y" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" id="Orj-az-JIO"/>
80+
<constraint firstItem="yda-zQ-zIG" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" constant="30" id="PKU-aR-WIX"/>
6681
<constraint firstItem="P71-RQ-w3Y" firstAttribute="trailing" secondItem="6Tk-OE-BBY" secondAttribute="trailing" id="TlA-35-iyi"/>
6782
<constraint firstItem="HnO-cS-a4I" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" id="YQr-yE-Fj0"/>
6883
<constraint firstItem="HnO-cS-a4I" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" id="YhM-LV-Tya"/>
6984
<constraint firstItem="HnO-cS-a4I" firstAttribute="trailing" secondItem="6Tk-OE-BBY" secondAttribute="trailing" id="Zu4-1h-MTC"/>
85+
<constraint firstItem="yda-zQ-zIG" firstAttribute="bottom" secondItem="6Tk-OE-BBY" secondAttribute="bottom" id="iHx-Ip-sA5"/>
7086
<constraint firstItem="HnO-cS-a4I" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="ovE-sY-kNb"/>
7187
<constraint firstItem="P71-RQ-w3Y" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="wb5-bQ-9sI"/>
88+
<constraint firstItem="yda-zQ-zIG" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="wyR-np-tM4"/>
7289
</constraints>
7390
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
7491
</view>
@@ -85,6 +102,8 @@
85102
</barButtonItem>
86103
</navigationItem>
87104
<connections>
105+
<outlet property="activityIndicator" destination="Khc-j7-EfD" id="zH9-hm-Umn"/>
106+
<outlet property="activityIndicatorView" destination="yda-zQ-zIG" id="cm3-vM-rx8"/>
88107
<outlet property="leftButton" destination="mlw-cf-kRg" id="5PJ-wX-nGG"/>
89108
<outlet property="offlineButton" destination="M9z-jX-53J" id="wBQ-7m-k9x"/>
90109
<outlet property="offlineIcon" destination="oc6-1O-6cw" id="rvO-Bh-ce9"/>
@@ -95,7 +114,7 @@
95114
</viewController>
96115
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
97116
</objects>
98-
<point key="canvasLocation" x="1047" y="476"/>
117+
<point key="canvasLocation" x="1045.5999999999999" y="475.41229385307349"/>
99118
</scene>
100119
<!--Navigation Controller-->
101120
<scene sceneID="1sK-l5-PHi">

ios-pwa-wrapper/Constants.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ let navigationButtonColor = navigationTitleColor
3232
let progressBarColor = getColorFromHex(hex: 0x4CAF50, alpha: 1.0)
3333
let offlineIconColor = UIColor.darkGray
3434
let buttonColor = navigationBarColor
35+
let activityIndicatorColor = navigationBarColor
3536

3637
// Color Helper function
3738
func getColorFromHex(hex: UInt, alpha: CGFloat) -> UIColor {

ios-pwa-wrapper/ViewController.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class ViewController: UIViewController {
1818
@IBOutlet weak var offlineView: UIView!
1919
@IBOutlet weak var offlineIcon: UIImageView!
2020
@IBOutlet weak var offlineButton: UIButton!
21+
@IBOutlet weak var activityIndicatorView: UIView!
22+
@IBOutlet weak var activityIndicator: UIActivityIndicatorView!
2123

2224
// MARK: Globals
2325
var webView: WKWebView!
@@ -56,12 +58,13 @@ class ViewController: UIViewController {
5658

5759
// Observers for updating UI
5860
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
59-
/*
6061
if (keyPath == #keyPath(WKWebView.isLoading)) {
61-
// does not fire for PWAs if links are clicked
62-
// leftButton.isEnabled = webView.canGoBack
62+
// show activity indicator
63+
if (webView.isLoading) {
64+
activityIndicatorView.isHidden = false
65+
activityIndicator.startAnimating()
66+
}
6367
}
64-
*/
6568
if (keyPath == #keyPath(WKWebView.estimatedProgress)) {
6669
progressBar.progress = Float(webView.estimatedProgress)
6770
rightButton.isEnabled = (webView.estimatedProgress == 1)
@@ -120,6 +123,10 @@ class ViewController: UIViewController {
120123
progressBar.tintColor = progressBarColor
121124
webView.addSubview(progressBar)
122125

126+
// activity indicator
127+
activityIndicator.color = activityIndicatorColor
128+
activityIndicator.startAnimating()
129+
123130
// offline container
124131
offlineIcon.tintColor = offlineIconColor
125132
offlineButton.tintColor = buttonColor
@@ -173,6 +180,9 @@ extension ViewController: WKNavigationDelegate {
173180
}
174181
// hide progress bar after initial load
175182
progressBar.isHidden = true
183+
// hide activity indicator
184+
activityIndicatorView.isHidden = true
185+
activityIndicator.stopAnimating()
176186
}
177187
// didFailProvisionalNavigation
178188
func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {

0 commit comments

Comments
 (0)