Skip to content

Commit

Permalink
Fix tinting issues (trustwallet#570)
Browse files Browse the repository at this point in the history
* Fix tinting issues

* Set completion in initializer

* Use makeShareController func
  • Loading branch information
MillerApps authored and vikmeup committed Apr 5, 2018
1 parent d18d63c commit 2b4f545
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 30 deletions.
4 changes: 4 additions & 0 deletions Trust.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@
903682F6204A71B000013479 /* Bookmark.swift in Sources */ = {isa = PBXBuildFile; fileRef = 903682F5204A71B000013479 /* Bookmark.swift */; };
903682F8204AC52F00013479 /* BookmarksViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 903682F7204AC52F00013479 /* BookmarksViewModel.swift */; };
90DDF48520518AE50016E6D4 /* BookmarkViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90DDF48420518AE50016E6D4 /* BookmarkViewModel.swift */; };
A24CE7122074807400726D43 /* ActivityViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A24CE7112074807400726D43 /* ActivityViewController.swift */; };
A2B7ECAA2038122200828E7D /* ExportPrivateKeyCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = A2B7ECA92038122200828E7D /* ExportPrivateKeyCoordinator.swift */; };
A2B7ECAC2038FFBC00828E7D /* ExportPrivateKeyViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A2B7ECAB2038FFBC00828E7D /* ExportPrivateKeyViewModel.swift */; };
A2B7ECAE2039001300828E7D /* ExportPrivateKeyViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A2B7ECAD2039001300828E7D /* ExportPrivateKeyViewController.swift */; };
Expand Down Expand Up @@ -877,6 +878,7 @@
903682F5204A71B000013479 /* Bookmark.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bookmark.swift; sourceTree = "<group>"; };
903682F7204AC52F00013479 /* BookmarksViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarksViewModel.swift; sourceTree = "<group>"; };
90DDF48420518AE50016E6D4 /* BookmarkViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarkViewModel.swift; sourceTree = "<group>"; };
A24CE7112074807400726D43 /* ActivityViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActivityViewController.swift; sourceTree = "<group>"; };
A2B7ECA92038122200828E7D /* ExportPrivateKeyCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExportPrivateKeyCoordinator.swift; sourceTree = "<group>"; };
A2B7ECAB2038FFBC00828E7D /* ExportPrivateKeyViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExportPrivateKeyViewModel.swift; sourceTree = "<group>"; };
A2B7ECAD2039001300828E7D /* ExportPrivateKeyViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExportPrivateKeyViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1205,6 +1207,7 @@
771D53722059337100C79485 /* TokenImageView.swift */,
7374ED2D2059A6A3004A8BC2 /* SectionHeader.swift */,
77CB8399206CEED7006F34A8 /* Size.swift */,
A24CE7112074807400726D43 /* ActivityViewController.swift */,
);
path = UI;
sourceTree = "<group>";
Expand Down Expand Up @@ -3264,6 +3267,7 @@
7721A6D0202EFD07004DB16C /* AddCustomNetworkCoordinator.swift in Sources */,
2996F1461F6C98B3005C33AE /* SettingsViewController.swift in Sources */,
73F2FF3C20557C020021976E /* TrustOperation.swift in Sources */,
A24CE7122074807400726D43 /* ActivityViewController.swift in Sources */,
2963B6AD1F981A96003063C1 /* TransactionAppearance.swift in Sources */,
77B1EAFF20639DEB007970AA /* NFTokenViewController.swift in Sources */,
29850D2B1F6B30FF00791A49 /* TransactionViewController.swift in Sources */,
Expand Down
12 changes: 4 additions & 8 deletions Trust/Browser/ViewControllers/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,13 @@ class BrowserViewController: UIViewController {
return alertController
}

private func makeShareController(url: URL) -> UIActivityViewController {
return UIActivityViewController(activityItems: [url], applicationActivities: nil)
}

private func share() {
guard let url = webView.url else { return }
guard let navigationController = navigationController else { return }
let controller = makeShareController(url: url)
controller.popoverPresentationController?.sourceView = navigationController.view
controller.popoverPresentationController?.sourceRect = navigationController.view.centerRect
navigationController.present(controller, animated: true, completion: nil)
let activityViewController = ActivityViewController.makeShareController(url: url, navigationController: navigationController)
activityViewController.popoverPresentationController?.sourceView = navigationController.view
activityViewController.popoverPresentationController?.sourceRect = navigationController.view.centerRect
navigationController.present(activityViewController, animated: true, completion: nil)
}

private func addBookmark() {
Expand Down
5 changes: 1 addition & 4 deletions Trust/Export/Coordinators/BackupCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ class BackupCoordinator: Coordinator {
return completion(.failure(AnyError(error)))
}

let activityViewController = UIActivityViewController(
activityItems: [url],
applicationActivities: nil
)
let activityViewController = ActivityViewController.makeShareController(url: url, navigationController: navigationController)
activityViewController.completionWithItemsHandler = { _, result, _, error in
do { try FileManager.default.removeItem(at: url)
} catch { }
Expand Down
6 changes: 2 additions & 4 deletions Trust/Settings/Coordinators/HelpUsCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ class HelpUsCoordinator: Coordinator {
}

func presentSharing(in viewController: UIViewController, from sender: UIView) {
let activityViewController = UIActivityViewController(
activityItems: viewModel.activityItems,
applicationActivities: nil
)
guard let navigation = viewController.navigationController else { return }
let activityViewController = ActivityViewController.makeShareController(url: viewModel.activityItems, navigationController: navigation)
activityViewController.popoverPresentationController?.sourceView = sender
activityViewController.popoverPresentationController?.sourceRect = sender.centerRect
viewController.present(activityViewController, animated: true, completion: nil)
Expand Down
4 changes: 3 additions & 1 deletion Trust/Style/AppStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func applyStyle() {
UINavigationBar.appearance().isTranslucent = false
}
UINavigationBar.appearance().tintColor = AppStyle.navigationBarTintColor
UINavigationBar.appearance().setBackgroundImage(.filled(with: Colors.darkBlue), for: .default)
UINavigationBar.appearance().barTintColor = Colors.darkBlue

UINavigationBar.appearance().titleTextAttributes = [
.foregroundColor: UIColor.white,
Expand Down Expand Up @@ -47,6 +47,8 @@ struct Colors {
struct AppStyle {
static let navigationBarTintColor = UIColor.white
static let docPickerNavigationBarTintColor = Colors.blue
static let activityViewControllerNavigationBarText = UIColor.white
static let activityViewControllerNavigationBarTintColor = Colors.darkBlue
}

struct StyleLayout {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,8 @@ class TransactionViewController: UIViewController {
}

@objc func share(_ sender: UIBarButtonItem) {
guard let item = viewModel.shareItem else { return }
let activityViewController = UIActivityViewController(
activityItems: [
item,
],
applicationActivities: nil
)
guard let item = viewModel.shareItem, let navigation = navigationController else { return }
let activityViewController = ActivityViewController.makeShareController(url: item, navigationController: navigation)
activityViewController.popoverPresentationController?.barButtonItem = sender
navigationController?.present(activityViewController, animated: true, completion: nil)
}
Expand Down
7 changes: 1 addition & 6 deletions Trust/Transfer/Coordinators/RequestCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,7 @@ class RequestCoordinator: Coordinator {
}

@objc func share(_ sender: UIBarButtonItem) {
let activityViewController = UIActivityViewController(
activityItems: [
viewModel.shareMyAddressText,
],
applicationActivities: nil
)
let activityViewController = ActivityViewController.makeShareController(url: viewModel.shareMyAddressText, navigationController: navigationController)
activityViewController.popoverPresentationController?.barButtonItem = sender
navigationController.present(activityViewController, animated: true, completion: nil)
}
Expand Down
29 changes: 29 additions & 0 deletions Trust/UI/ActivityViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright SIX DAY LLC. All rights reserved.

import UIKit

class ActivityViewController: UIActivityViewController {
override func viewWillAppear(_ animated: Bool) {
UINavigationBar.appearance().barTintColor = nil // This fixes the issue with notes
UINavigationBar.appearance().titleTextAttributes = nil // This makes the text black for messages and mail
}

init(activityItems: [Any], applicationActivities: [UIActivity]?, navigation: UINavigationController) {
super.init(activityItems: activityItems, applicationActivities: applicationActivities)
// Set a default completion
self.completionWithItemsHandler = { _, _, _, _ in
// Set the tint globally via appearance proxy
UINavigationBar.appearance().barTintColor = AppStyle.activityViewControllerNavigationBarTintColor
UINavigationBar.appearance().titleTextAttributes = [
.foregroundColor: AppStyle.activityViewControllerNavigationBarText,
]
navigation.navigationBar.barTintColor = AppStyle.activityViewControllerNavigationBarTintColor
navigation.navigationBar.titleTextAttributes = [
.foregroundColor: AppStyle.activityViewControllerNavigationBarText,
] // Used to manually set the navBar tint/text back look at this for more info on why https://stackoverflow.com/a/21653004
}
}
static func makeShareController(url: Any, navigationController: UINavigationController) -> ActivityViewController {
return ActivityViewController(activityItems: [url], applicationActivities: nil, navigation: navigationController)
}
}

0 comments on commit 2b4f545

Please sign in to comment.