Skip to content

Commit

Permalink
Fixes an issue due to which the links in the settings weren't opened …
Browse files Browse the repository at this point in the history
…properly (#7)

* Now opens links in new controllers
  • Loading branch information
kayoslab authored Aug 24, 2020
1 parent a4ad97a commit 48f00a7
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 25 deletions.
4 changes: 2 additions & 2 deletions caffeine.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@
CODE_SIGN_ENTITLEMENTS = caffeine/caffeine.entitlements;
CODE_SIGN_IDENTITY = "Apple Development: Simon Krüger (ZHJYL9DGF3)";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = T2MU43SWN2;
FRAMEWORK_SEARCH_PATHS = "$(inherited)/**";
Expand All @@ -946,7 +946,7 @@
CODE_SIGN_ENTITLEMENTS = caffeine/caffeine.entitlements;
CODE_SIGN_IDENTITY = "Apple Distribution: Simon Krüger (T2MU43SWN2)";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = T2MU43SWN2;
FRAMEWORK_SEARCH_PATHS = "$(inherited)/**";
INFOPLIST_FILE = caffeine/Info.plist;
Expand Down
24 changes: 18 additions & 6 deletions caffeine/Generated/Scenes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,27 @@ import UIKit

// swiftlint:disable explicit_type_interface identifier_name line_length type_body_length type_name
internal enum StoryboardScene {
internal enum LaunchScreen: StoryboardType {
internal static let storyboardName = "LaunchScreen"
internal enum Consumption: StoryboardType {
internal static let storyboardName = "Consumption"

internal static let initialScene = InitialSceneType<UIKit.UIViewController>(storyboard: LaunchScreen.self)
internal static let initialScene = InitialSceneType<UIKit.UINavigationController>(storyboard: Consumption.self)
}
internal enum Main: StoryboardType {
internal static let storyboardName = "Main"
internal enum Input: StoryboardType {
internal static let storyboardName = "Input"

internal static let initialScene = InitialSceneType<UIKit.UITabBarController>(storyboard: Main.self)
internal static let initialScene = InitialSceneType<UIKit.UINavigationController>(storyboard: Input.self)
}
internal enum Settings: StoryboardType {
internal static let storyboardName = "Settings"

internal static let initialScene = InitialSceneType<UIKit.UINavigationController>(storyboard: Settings.self)

internal static let settingsWebViewController = SceneType<caffeine.SettingsWebViewController>(storyboard: Settings.self, identifier: "SettingsWebViewController")
}
internal enum Statistics: StoryboardType {
internal static let storyboardName = "Statistics"

internal static let initialScene = InitialSceneType<UIKit.UINavigationController>(storyboard: Statistics.self)
}
}
// swiftlint:enable explicit_type_interface identifier_name line_length type_body_length type_name
Expand Down
25 changes: 12 additions & 13 deletions caffeine/ViewController/Settings/Settings.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
</mask>
</variation>
<connections>
<segue destination="SzE-bs-qCh" kind="show" id="OxT-WF-ynr"/>
<action selector="didPressInfoButton" destination="L3q-1B-75g" eventType="touchUpInside" id="P1Q-gp-2MS"/>
</connections>
</button>
</subviews>
Expand Down Expand Up @@ -181,33 +181,32 @@
<!--Settings Web View Controller-->
<scene sceneID="Xl8-hE-FYN">
<objects>
<viewController id="SzE-bs-qCh" customClass="SettingsWebViewController" customModule="caffeine" customModuleProvider="target" sceneMemberID="viewController">
<viewController storyboardIdentifier="SettingsWebViewController" id="SzE-bs-qCh" customClass="SettingsWebViewController" customModule="caffeine" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="e3G-Pn-2CD">
<rect key="frame" x="0.0" y="0.0" width="414" height="808"/>
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<wkWebView contentMode="scaleToFill" customUserAgent="app-caffeine" translatesAutoresizingMaskIntoConstraints="NO" id="lXK-1R-Dmd">
<rect key="frame" x="0.0" y="0.0" width="414" height="774"/>
<color key="backgroundColor" red="0.12943631410000001" green="0.12935084099999999" blue="0.13333395119999999" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
<wkWebViewConfiguration key="configuration" allowsAirPlayForMediaPlayback="NO" allowsPictureInPictureMediaPlayback="NO" applicationNameForUserAgent="caffeine">
<dataDetectorTypes key="dataDetectorTypes"/>
<wkWebView contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="iUR-qa-GBP">
<rect key="frame" x="0.0" y="44" width="414" height="818"/>
<color key="backgroundColor" red="0.16078431369999999" green="0.16078431369999999" blue="0.16862745100000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<wkWebViewConfiguration key="configuration">
<audiovisualMediaTypes key="mediaTypesRequiringUserActionForPlayback" none="YES"/>
<wkPreferences key="preferences"/>
</wkWebViewConfiguration>
</wkWebView>
</subviews>
<color key="backgroundColor" red="0.12943631410000001" green="0.12935084099999999" blue="0.13333395119999999" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
<constraints>
<constraint firstItem="lXK-1R-Dmd" firstAttribute="top" secondItem="j8h-wh-BoV" secondAttribute="top" id="V5h-uD-bv2"/>
<constraint firstItem="lXK-1R-Dmd" firstAttribute="trailing" secondItem="j8h-wh-BoV" secondAttribute="trailing" id="n9m-Kc-WVR"/>
<constraint firstItem="lXK-1R-Dmd" firstAttribute="bottom" secondItem="j8h-wh-BoV" secondAttribute="bottom" id="rLN-Te-Xa0"/>
<constraint firstItem="lXK-1R-Dmd" firstAttribute="leading" secondItem="j8h-wh-BoV" secondAttribute="leading" id="xrr-CX-Phx"/>
<constraint firstItem="iUR-qa-GBP" firstAttribute="top" secondItem="j8h-wh-BoV" secondAttribute="top" id="8FM-XM-eYP"/>
<constraint firstItem="j8h-wh-BoV" firstAttribute="bottom" secondItem="iUR-qa-GBP" secondAttribute="bottom" id="d8h-cA-Sxs"/>
<constraint firstItem="j8h-wh-BoV" firstAttribute="trailing" secondItem="iUR-qa-GBP" secondAttribute="trailing" id="ejW-6z-5Yd"/>
<constraint firstItem="iUR-qa-GBP" firstAttribute="leading" secondItem="j8h-wh-BoV" secondAttribute="leading" id="vej-2k-IRK"/>
</constraints>
<viewLayoutGuide key="safeArea" id="j8h-wh-BoV"/>
</view>
<navigationItem key="navigationItem" id="msr-0f-Eg4"/>
<connections>
<outlet property="webView" destination="lXK-1R-Dmd" id="XBE-cF-jv5"/>
<outlet property="webView" destination="iUR-qa-GBP" id="pIY-4c-7Cd"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="SFH-qE-B3M" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
Expand Down
7 changes: 7 additions & 0 deletions caffeine/ViewController/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,11 @@ class SettingsViewController: UIViewController {
animated: animated
)
}

@IBAction private func didPressInfoButton() {
guard let url = URL(string: "https://caffeine.cr0ss.org/medical-information/") else { return }
let webViewController = StoryboardScene.Settings.settingsWebViewController.instantiate()
webViewController.url = url
navigationController?.pushViewController(webViewController, animated: true)
}
}
41 changes: 38 additions & 3 deletions caffeine/ViewController/Settings/SettingsWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,49 @@ import WebKit

class SettingsWebViewController: UIViewController {
@IBOutlet private weak var webView: WKWebView?
var url: URL? {
didSet {
guard let url = self.url else { return }

webView?.load(.init(url: url))
}
}

override func viewDidLoad() {
super.viewDidLoad()

guard
let url = URL(string: "https://caffeine.cr0ss.org/medical-information/")
else { return }
webView?.navigationDelegate = self

guard let url = self.url else { return }

webView?.load(.init(url: url))
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

guard let url = self.url else { return }

webView?.load(.init(url: url))
}
}

extension SettingsWebViewController: WKNavigationDelegate {

func webView(
_ webView: WKWebView,
decidePolicyFor navigationAction: WKNavigationAction,
decisionHandler: @escaping (WKNavigationActionPolicy) -> Void
) {
if navigationAction.navigationType == .linkActivated {
guard let url = navigationAction.request.url else { return decisionHandler(.allow) }
let webViewController = StoryboardScene.Settings.settingsWebViewController.instantiate()
webViewController.url = url
navigationController?.pushViewController(webViewController, animated: true)
decisionHandler(.cancel)
} else {
decisionHandler(.allow)
}
}

}
2 changes: 1 addition & 1 deletion swiftgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ xcassets:
- templateName: swift5
output: caffeine/Generated/Assets.swift
ib:
inputs: caffeine/Scenes
inputs: caffeine/ViewController
outputs:
- templateName: scenes-swift5
output: caffeine/Generated/Scenes.swift
Expand Down

0 comments on commit 48f00a7

Please sign in to comment.