Skip to content

Commit 4f7d700

Browse files
author
David Seek
committed
Added Theming
1 parent e77e8b5 commit 4f7d700

File tree

10 files changed

+67
-15
lines changed

10 files changed

+67
-15
lines changed

ChangelogKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'ChangelogKit'
11-
s.version = '0.1.5'
11+
s.version = '0.1.6'
1212
s.summary = 'A library that offers tools to display a changelog using webviews and user defaults.'
1313

1414
# This description is used to generate tags and improve search results.

ChangelogKit/Classes/ChangelogKit.swift

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,46 @@ private enum Constants {
1717
static let bannerText = "You are now using the latest update!"
1818
}
1919

20+
public struct ChangelogKitTheme {
21+
let navigationBarTintColor: UIColor// = .systemBlue
22+
let backgroundColor: UIColor// = .white
23+
24+
public init(navigationBarTintColor: UIColor, backgroundColor: UIColor) {
25+
self.navigationBarTintColor = navigationBarTintColor
26+
self.backgroundColor = backgroundColor
27+
}
28+
29+
public static var defaultTheme: ChangelogKitTheme {
30+
if #available(iOS 13.0, *) {
31+
return ChangelogKitTheme(
32+
navigationBarTintColor: .systemBlue,
33+
backgroundColor: .systemBackground)
34+
} else {
35+
return ChangelogKitTheme(
36+
navigationBarTintColor: .systemBlue,
37+
backgroundColor: .white)
38+
}
39+
}
40+
}
41+
2042
public class ChangelogKit {
2143

2244
private static let defaults = UserDefaults.standard
2345
private static let banner = BannerView(
2446
text: Constants.bannerText,
2547
onAction: bannerViewActionHandler)
26-
48+
2749
private static var currentVersion: String?
2850
private static var controller: UIViewController?
51+
52+
public static var theme: ChangelogKitTheme = .defaultTheme {
53+
didSet {
54+
Log.error("Did set ChangelogKit theme to \(theme)")
55+
}
56+
}
2957
public static var changelogURL: String! {
3058
didSet {
31-
Log.error("Did initialize ChangelogKit with \(changelogURL ?? "nil")")
59+
Log.error("Did set ChangelogKit changelogURL to \(changelogURL ?? "nil")")
3260
}
3361
}
3462

@@ -86,7 +114,7 @@ public class ChangelogKit {
86114
return
87115
}
88116
/// Initiate the WebView controller
89-
let webController = WebViewController(url: url)
117+
let webController = WebViewController(url: url, theme: theme)
90118
/// Set the presentation style depending the OS
91119
if #available(iOS 13, *) {
92120
webController.modalPresentationStyle = .automatic

ChangelogKit/Classes/Views/WebViewController.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ private enum Constants {
1818
class WebViewController: UIViewController {
1919

2020
@IBOutlet weak var webViewContainer: UIView!
21+
@IBOutlet weak var theNavigationBar: UINavigationBar!
2122
@IBOutlet weak var theNavigationItem: UINavigationItem!
2223

2324
private let url: URL
25+
private let theme: ChangelogKitTheme
2426

2527
private lazy var webView: WKWebView = {
2628
let config = getConfig()
@@ -30,11 +32,13 @@ class WebViewController: UIViewController {
3032
webView.allowsBackForwardNavigationGestures = false
3133
webView.contentMode = .scaleToFill
3234
webView.scrollView.delegate = webViewScrollViewDelegate.shared
35+
webView.backgroundColor = theme.backgroundColor
3336
return webView
3437
}()
3538

36-
init(url: URL) {
39+
init(url: URL, theme: ChangelogKitTheme) {
3740
self.url = url
41+
self.theme = theme
3842
super.init(nibName: Constants.nibName, bundle: Bundle(for: type(of: self)))
3943
}
4044

@@ -44,6 +48,8 @@ class WebViewController: UIViewController {
4448

4549
override func viewDidLoad() {
4650
super.viewDidLoad()
51+
52+
view.backgroundColor = theme.backgroundColor
4753

4854
setNavigationBar()
4955
setWebView()
@@ -65,6 +71,11 @@ class WebViewController: UIViewController {
6571
barButtonSystemItem: .done,
6672
target: self,
6773
action: #selector(doneTapped))
74+
75+
theNavigationBar.setBackgroundImage(UIImage(), for: .default)
76+
theNavigationBar.shadowImage = UIImage()
77+
theNavigationBar.isTranslucent = true
78+
theNavigationBar.tintColor = theme.navigationBarTintColor
6879
}
6980

7081
/// Function to bootstrap the `WKWebView`

ChangelogKit/Classes/Views/WebViewController.xib

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="17701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="17506" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
33
<device id="retina6_1" orientation="portrait" appearance="light"/>
44
<dependencies>
55
<deployment identifier="iOS"/>
6-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17703"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17505"/>
77
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
88
<capability name="System colors in document resources" minToolsVersion="11.0"/>
99
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
1010
</dependencies>
1111
<objects>
1212
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="WebViewController" customModule="ChangelogKit" customModuleProvider="target">
1313
<connections>
14+
<outlet property="theNavigationBar" destination="vE3-XS-Ssx" id="fr4-HF-vnE"/>
1415
<outlet property="theNavigationItem" destination="jdZ-L1-RqD" id="3NA-FX-LzF"/>
1516
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
1617
<outlet property="webViewContainer" destination="4Aq-pp-uhw" id="JYZ-Xb-25s"/>

Example/ChangelogKit/AppDelegate.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1818
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
1919

2020
ChangelogKit.changelogURL = "https://voicepitchanalyzerchangelog.davidseek.md2site.com/"
21+
ChangelogKit.theme = ChangelogKitTheme(navigationBarTintColor: .white, backgroundColor: .black)
2122
return true
2223
}
2324
}

Example/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PODS:
2-
- ChangelogKit (0.1.0)
2+
- ChangelogKit (0.1.5)
33

44
DEPENDENCIES:
55
- ChangelogKit (from `../`)
@@ -9,7 +9,7 @@ EXTERNAL SOURCES:
99
:path: "../"
1010

1111
SPEC CHECKSUMS:
12-
ChangelogKit: b46592a901d62e4fa7e315c1279731fc70e78d80
12+
ChangelogKit: cb4566e7f80de000c01c6bc1dd38550312bdd78a
1313

1414
PODFILE CHECKSUM: 3a0b64bfe1be262873d0f3ec5a5c83a28748934d
1515

Example/Pods/Local Podspecs/ChangelogKit.podspec.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Manifest.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Target Support Files/ChangelogKit/ChangelogKit-Info.plist

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,21 @@ override func viewDidAppear(_ animated: Bool) {
2323
```
2424

2525
## API
26+
2627
- `useForce`
2728
- `true`, presents the Changelog in a modal
2829
- `false`, presents a banner, with action buttons. Close, and present Changelog.
2930

31+
## Theming
32+
33+
The `ChangelogKitTheme` object offers a simple way to customize the Changelog experience with your Application Corporate Identity.
34+
35+
```swift
36+
ChangelogKit.theme = ChangelogKitTheme(
37+
navigationBarTintColor: .white,
38+
backgroundColor: .black)
39+
```
40+
3041
## Example
3142

3243
To run the example project, clone the repo, and run `pod install` from the Example directory first.
@@ -42,7 +53,7 @@ pod 'ChangelogKit'
4253

4354
## Author
4455

45-
davidseek, david@davidseek.com
56+
[David Seek](https://twitter.com/DavidSeek)
4657

4758
## License
4859

0 commit comments

Comments
 (0)