-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from weiran/dark
Dark mode
- Loading branch information
Showing
66 changed files
with
851 additions
and
149 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// AppNavigationController.swift | ||
// Hackers | ||
// | ||
// Created by Weiran Zhang on 05/05/2018. | ||
// Copyright © 2018 Glass Umbrella. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class AppNavigationController: UINavigationController { | ||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
setupTheming() | ||
navigationBar.setValue(true, forKey: "hidesShadow") | ||
} | ||
} | ||
|
||
extension AppNavigationController: Themed { | ||
func applyTheme(_ theme: AppTheme) { | ||
navigationBar.barTintColor = theme.barBackgroundColor | ||
navigationBar.tintColor = theme.barForegroundColor | ||
let titleTextAttributes = [ | ||
NSAttributedStringKey.foregroundColor: theme.titleTextColor | ||
] | ||
navigationBar.titleTextAttributes = titleTextAttributes | ||
navigationBar.largeTitleTextAttributes = titleTextAttributes | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// CommentsHeaderView.swift | ||
// Hackers | ||
// | ||
// Created by Weiran Zhang on 05/05/2018. | ||
// Copyright © 2018 Glass Umbrella. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class CommentsHeaderView: UIView { | ||
@IBOutlet weak var titleLabel: UILabel! | ||
@IBOutlet weak var separatorView: UIView! | ||
|
||
override func awakeFromNib() { | ||
super.awakeFromNib() | ||
setupTheming() | ||
} | ||
} | ||
|
||
extension CommentsHeaderView: Themed { | ||
func applyTheme(_ theme: AppTheme) { | ||
backgroundColor = theme.backgroundColor | ||
titleLabel.textColor = theme.titleTextColor | ||
separatorView.backgroundColor = theme.separatorColor | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// ArrayExtensions.swift | ||
// Night Mode | ||
// | ||
// Created by Michael on 01/04/2018. | ||
// Copyright © 2018 Late Night Swift. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
extension Array { | ||
/// Move the last element of the array to the beginning | ||
/// - Returns: The element that was moved | ||
mutating func rotate() -> Element? { | ||
guard let lastElement = popLast() else { | ||
return nil | ||
} | ||
insert(lastElement, at: 0) | ||
return lastElement | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// SubscribableValue.swift | ||
// Night Mode | ||
// | ||
// Created by Michael on 01/04/2018. | ||
// Copyright © 2018 Late Night Swift. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
/// Stores a value of type T, and allows objects to subscribe to | ||
/// be notified with this value is changed. | ||
struct SubscribableValue<T> { | ||
private typealias Subscription = (object: Weak<AnyObject>, handler: (T) -> Void) | ||
|
||
private var subscriptions: [Subscription] = [] | ||
|
||
var value: T { | ||
didSet { | ||
for (object, handler) in subscriptions where object.value != nil { | ||
handler(value) | ||
} | ||
} | ||
} | ||
|
||
init(value: T) { | ||
self.value = value | ||
} | ||
|
||
mutating func subscribe(_ object: AnyObject, using handler: @escaping (T) -> Void) { | ||
subscriptions.append((Weak(value: object), handler)) | ||
cleanupSubscriptions() | ||
} | ||
|
||
/// Removes any subscriptions where the object has been deallocated | ||
/// and no longer exists | ||
private mutating func cleanupSubscriptions() { | ||
subscriptions = subscriptions.filter({ entry in | ||
return entry.object.value != nil | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// ThemedSafariViewController.swift | ||
// Hackers | ||
// | ||
// Created by Weiran Zhang on 05/05/2018. | ||
// Copyright © 2018 Glass Umbrella. All rights reserved. | ||
// | ||
|
||
import SafariServices | ||
|
||
class ThemedSafariViewController: SFSafariViewController { | ||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
setupTheming() | ||
} | ||
} | ||
|
||
extension ThemedSafariViewController: Themed { | ||
func applyTheme(_ theme: AppTheme) { | ||
preferredBarTintColor = theme.barBackgroundColor | ||
preferredControlTintColor = theme.appTintColor | ||
view.backgroundColor = theme.backgroundColor | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// UIColor+Extensions.swift | ||
// Hackers | ||
// | ||
// Created by Weiran Zhang on 05/05/2018. | ||
// Copyright © 2018 Glass Umbrella. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
extension UIColor { | ||
convenience init(red: Int, green: Int, blue: Int) { | ||
assert(red >= 0 && red <= 255, "Invalid red component") | ||
assert(green >= 0 && green <= 255, "Invalid green component") | ||
assert(blue >= 0 && blue <= 255, "Invalid blue component") | ||
|
||
self.init(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: 1.0) | ||
} | ||
|
||
convenience init(rgb: Int) { | ||
self.init( | ||
red: (rgb >> 16) & 0xFF, | ||
green: (rgb >> 8) & 0xFF, | ||
blue: rgb & 0xFF | ||
) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.