This PR contains all the work related to setting up this project as required to implement the [Assignment](https://repo.rock-n-code.com/rock-n-code/deep-linking-assignment/wiki/Assignment) on top, as intended. To summarise this work: - [x] created a new **Xcode** project; - [x] cloned the `Wikipedia` app and inserted it into the **Xcode** project; - [x] created the `Locations` app and also, its `Libraries` package; - [x] created the `Shared` package to share dependencies between the apps; - [x] added a `Makefile` file and implemented some **environment** and **help** commands. Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Reviewed-on: rock-n-code/deep-linking-assignment#1
46 lines
1.5 KiB
Swift
46 lines
1.5 KiB
Swift
import UIKit
|
|
|
|
open class ExtensionViewController: UIViewController, Themeable {
|
|
public final var theme: Theme = Theme.widgetLight
|
|
|
|
open func apply(theme: Theme) {
|
|
self.theme = theme
|
|
}
|
|
|
|
var isFirstLayout = true
|
|
|
|
open override func viewWillLayoutSubviews() {
|
|
super.viewWillLayoutSubviews()
|
|
updateThemeFromTraitCollection(force: isFirstLayout)
|
|
isFirstLayout = false
|
|
}
|
|
|
|
private func updateThemeFromTraitCollection(force: Bool = false) {
|
|
let compatibleTheme = Theme.widgetThemeCompatible(with: traitCollection)
|
|
guard theme !== compatibleTheme else {
|
|
if force {
|
|
apply(theme: theme)
|
|
}
|
|
return
|
|
}
|
|
apply(theme: compatibleTheme)
|
|
}
|
|
|
|
override open func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
|
|
super.traitCollectionDidChange(previousTraitCollection)
|
|
updateThemeFromTraitCollection()
|
|
}
|
|
|
|
public func openAppInActivity(with activityType: WMFUserActivityType) {
|
|
self.extensionContext?.open(NSUserActivity.wmf_baseURLForActivity(of: activityType))
|
|
}
|
|
|
|
public func openApp(with url: URL?, fallback fallbackURL: URL? = nil) {
|
|
guard let wikipediaSchemeURL = url?.replacingSchemeWithWikipediaScheme ?? fallbackURL else {
|
|
openAppInActivity(with: .explore)
|
|
return
|
|
}
|
|
self.extensionContext?.open(wikipediaSchemeURL)
|
|
}
|
|
}
|