Skip to content

Commit 1c2278e

Browse files
committed
started offline container
1 parent cd24923 commit 1c2278e

File tree

7 files changed

+92
-43
lines changed

7 files changed

+92
-43
lines changed

ios-pwa-wrapper.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
2D504C0D1FA100E20019B279 /* ios-pwa-wrapperUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "ios-pwa-wrapperUITests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
4949
2D504C111FA100E20019B279 /* ios_pwa_wrapperUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ios_pwa_wrapperUITests.swift; sourceTree = "<group>"; };
5050
2D504C131FA100E20019B279 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
51+
2D64358A1FA62B5800ECC5D2 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Main.strings; sourceTree = "<group>"; };
5152
2DC96ADD1FA5DD32006B5881 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
5253
/* End PBXFileReference section */
5354

@@ -304,6 +305,7 @@
304305
isa = PBXVariantGroup;
305306
children = (
306307
2D504BF31FA100E20019B279 /* Base */,
308+
2D64358A1FA62B5800ECC5D2 /* en */,
307309
);
308310
name = Main.storyboard;
309311
sourceTree = "<group>";

ios-pwa-wrapper.xcodeproj/xcuserdata/kzb.xcuserdatad/xcschemes/xcschememanagement.plist

Lines changed: 0 additions & 32 deletions
This file was deleted.

ios-pwa-wrapper/Assets.xcassets/ic_cloud_off_black_48dp.imageset/Contents.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@
1919
"info" : {
2020
"version" : 1,
2121
"author" : "xcode"
22+
},
23+
"properties" : {
24+
"template-rendering-intent" : "template"
2225
}
2326
}

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,62 @@
1717
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
1818
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
1919
<subviews>
20+
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="P71-RQ-w3Y" userLabel="Offline View">
21+
<rect key="frame" x="0.0" y="64" width="375" height="603"/>
22+
<subviews>
23+
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="PAe-DD-sEP">
24+
<rect key="frame" x="0.0" y="200" width="375" height="132.5"/>
25+
<subviews>
26+
<imageView userInteractionEnabled="NO" contentMode="center" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="ic_cloud_off_black_48dp" translatesAutoresizingMaskIntoConstraints="NO" id="oc6-1O-6cw">
27+
<rect key="frame" x="118" y="0.0" width="139" height="72"/>
28+
</imageView>
29+
<label opaque="NO" userInteractionEnabled="NO" contentMode="center" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="You are offline." textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2o9-AL-VUQ">
30+
<rect key="frame" x="116.5" y="72" width="142" height="26.5"/>
31+
<fontDescription key="fontDescription" type="system" pointSize="22"/>
32+
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
33+
<nil key="highlightedColor"/>
34+
</label>
35+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="M9z-jX-53J">
36+
<rect key="frame" x="118" y="98.5" width="139" height="34"/>
37+
<fontDescription key="fontDescription" type="system" pointSize="18"/>
38+
<state key="normal" title="Tap here to retry!"/>
39+
<connections>
40+
<action selector="onOfflineButtonClick:" destination="BYZ-38-t0r" eventType="touchUpInside" id="rqj-bK-hyk"/>
41+
</connections>
42+
</button>
43+
</subviews>
44+
<constraints>
45+
<constraint firstItem="oc6-1O-6cw" firstAttribute="top" secondItem="PAe-DD-sEP" secondAttribute="top" id="44T-fD-cKO"/>
46+
<constraint firstItem="oc6-1O-6cw" firstAttribute="leading" secondItem="2o9-AL-VUQ" secondAttribute="trailing" constant="-140.5" id="Hr3-h7-6gE"/>
47+
<constraint firstItem="2o9-AL-VUQ" firstAttribute="leading" secondItem="M9z-jX-53J" secondAttribute="trailing" constant="-140.5" id="wdO-oV-eNf"/>
48+
</constraints>
49+
</stackView>
50+
</subviews>
51+
<constraints>
52+
<constraint firstAttribute="trailing" secondItem="PAe-DD-sEP" secondAttribute="trailing" id="2Hh-cQ-iwx"/>
53+
<constraint firstItem="PAe-DD-sEP" firstAttribute="leading" secondItem="P71-RQ-w3Y" secondAttribute="leading" id="Vx8-ru-pdt"/>
54+
<constraint firstItem="PAe-DD-sEP" firstAttribute="top" secondItem="P71-RQ-w3Y" secondAttribute="top" constant="200" id="ge0-AZ-Dbn"/>
55+
</constraints>
56+
</view>
2057
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="HnO-cS-a4I">
2158
<rect key="frame" x="0.0" y="64" width="375" height="603"/>
2259
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
2360
</view>
2461
</subviews>
2562
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
2663
<constraints>
64+
<constraint firstItem="HnO-cS-a4I" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="4Ug-Ri-DYo"/>
2765
<constraint firstItem="HnO-cS-a4I" firstAttribute="trailing" secondItem="6Tk-OE-BBY" secondAttribute="trailing" id="6t2-kT-aXm"/>
66+
<constraint firstItem="P71-RQ-w3Y" firstAttribute="bottom" secondItem="6Tk-OE-BBY" secondAttribute="bottom" id="7Mx-39-uRU"/>
67+
<constraint firstItem="HnO-cS-a4I" firstAttribute="bottom" secondItem="6Tk-OE-BBY" secondAttribute="bottom" id="JRX-v6-mMT"/>
2868
<constraint firstItem="HnO-cS-a4I" firstAttribute="bottom" secondItem="6Tk-OE-BBY" secondAttribute="bottom" id="NPb-ae-PDf"/>
69+
<constraint firstItem="P71-RQ-w3Y" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" id="Orj-az-JIO"/>
70+
<constraint firstItem="P71-RQ-w3Y" firstAttribute="trailing" secondItem="6Tk-OE-BBY" secondAttribute="trailing" id="TlA-35-iyi"/>
2971
<constraint firstItem="HnO-cS-a4I" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" id="YQr-yE-Fj0"/>
72+
<constraint firstItem="HnO-cS-a4I" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" id="YhM-LV-Tya"/>
73+
<constraint firstItem="HnO-cS-a4I" firstAttribute="trailing" secondItem="6Tk-OE-BBY" secondAttribute="trailing" id="Zu4-1h-MTC"/>
3074
<constraint firstItem="HnO-cS-a4I" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="ovE-sY-kNb"/>
75+
<constraint firstItem="P71-RQ-w3Y" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="wb5-bQ-9sI"/>
3176
</constraints>
3277
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
3378
</view>
@@ -45,6 +90,9 @@
4590
</navigationItem>
4691
<connections>
4792
<outlet property="leftButton" destination="mlw-cf-kRg" id="5PJ-wX-nGG"/>
93+
<outlet property="offlineButton" destination="M9z-jX-53J" id="wBQ-7m-k9x"/>
94+
<outlet property="offlineContainer" destination="PAe-DD-sEP" id="YD0-N1-y4z"/>
95+
<outlet property="offlineIcon" destination="oc6-1O-6cw" id="rvO-Bh-ce9"/>
4896
<outlet property="rightButton" destination="DBy-OS-v6d" id="A1c-Ll-cgP"/>
4997
<outlet property="webViewContainer" destination="HnO-cS-a4I" id="5NC-tb-0Ov"/>
5098
</connections>
@@ -72,4 +120,7 @@
72120
<point key="canvasLocation" x="113.59999999999999" y="476.76161919040482"/>
73121
</scene>
74122
</scenes>
123+
<resources>
124+
<image name="ic_cloud_off_black_48dp" width="72" height="72"/>
125+
</resources>
75126
</document>

ios-pwa-wrapper/Constants.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ let forceLargeTitle = false
2727
// Colors & Styles
2828
let useLightStatusBarStyle = true
2929
let navigationBarColor = getColorFromHex(hex: 0xF44336, alpha: 1.0)
30-
let navigationButtonColor = getColorFromHex(hex: 0xFFFFFF, alpha: 1.0)
3130
let navigationTitleColor = getColorFromHex(hex: 0xFFFFFF, alpha: 1.0)
31+
let navigationButtonColor = navigationTitleColor
3232
let progressBarColor = getColorFromHex(hex: 0x4CAF50, alpha: 1.0)
33+
let offlineIconColor = navigationBarColor
3334

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

ios-pwa-wrapper/ViewController.swift

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ class ViewController: UIViewController {
1515
@IBOutlet weak var leftButton: UIBarButtonItem!
1616
@IBOutlet weak var rightButton: UIBarButtonItem!
1717
@IBOutlet weak var webViewContainer: UIView!
18+
@IBOutlet weak var offlineContainer: UIStackView!
19+
@IBOutlet weak var offlineIcon: UIImageView!
20+
@IBOutlet weak var offlineButton: UIButton!
21+
1822
// MARK: Globals
1923
var webView: WKWebView!
2024
var progressBar : UIProgressView!
@@ -44,6 +48,11 @@ class ViewController: UIViewController {
4448
@IBAction func onRightButtonClick(_ sender: Any) {
4549
webView.evaluateJavaScript(menuButtonJavascript, completionHandler: nil)
4650
}
51+
@IBAction func onOfflineButtonClick(_ sender: Any) {
52+
offlineContainer.isHidden = true
53+
webViewContainer.isHidden = false
54+
loadAppUrl()
55+
}
4756

4857
// Observers for updating UI
4958
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
@@ -92,17 +101,22 @@ class ViewController: UIViewController {
92101
webView.addObserver(self, forKeyPath: #keyPath(WKWebView.estimatedProgress), options: NSKeyValueObservingOptions.new, context: nil)
93102
}
94103

95-
// Initialize UI
104+
// Initialize UI elements
96105
// call after WebView has been initialized
97106
func setupUI() {
98-
// UI elements
99107
// leftButton.isEnabled = false
108+
109+
// progress bar
100110
progressBar = UIProgressView(frame: CGRect(x: 0, y: 0, width: webViewContainer.frame.width, height: 40))
101111
progressBar.autoresizingMask = [.flexibleWidth]
102112
progressBar.progress = 0.0
103113
progressBar.tintColor = progressBarColor
104114
webView.addSubview(progressBar)
105115

116+
// offline container
117+
offlineIcon.tintColor = offlineIconColor
118+
offlineContainer.isHidden = true
119+
106120
// setup navigation
107121
navigationItem.title = appTitle
108122
if (forceLargeTitle) {
@@ -113,14 +127,17 @@ class ViewController: UIViewController {
113127
}
114128
}
115129

130+
// load startpage
131+
func loadAppUrl() {
132+
let urlRequest = URLRequest(url: webAppUrl!)
133+
webView.load(urlRequest)
134+
}
135+
116136
// Initialize App and start loading
117137
func setupApp() {
118138
setupWebView()
119139
setupUI()
120-
121-
// load startpage
122-
let urlRequest = URLRequest(url: webAppUrl!)
123-
webView.load(urlRequest)
140+
loadAppUrl()
124141
}
125142

126143
// Cleanup
@@ -144,10 +161,8 @@ extension ViewController: WKNavigationDelegate {
144161
// didFailProvisionalNavigation
145162
func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
146163
// show offline screen
147-
// @TODO
148-
let alert = UIAlertController(title: "You're offline", message: "didFailProvisionalNavigation", preferredStyle: .alert)
149-
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
150-
present(alert, animated: true, completion: nil)
164+
offlineContainer.isHidden = false
165+
webViewContainer.isHidden = true
151166
}
152167
}
153168

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
/* Class = "UINavigationItem"; title = "PWA Wrapper"; ObjectID = "COK-wh-4k6"; */
3+
"COK-wh-4k6.title" = "PWA Wrapper";
4+
5+
/* Class = "UIBarButtonItem"; title = "Menu"; ObjectID = "DBy-OS-v6d"; */
6+
"DBy-OS-v6d.title" = "Menu";
7+
8+
/* Class = "UIBarButtonItem"; title = "Back"; ObjectID = "mlw-cf-kRg"; */
9+
"mlw-cf-kRg.title" = "Back";

0 commit comments

Comments
 (0)