Skip to content

Commit

Permalink
Fix#5873 - Share sheet not in dark mode (#6024)
Browse files Browse the repository at this point in the history
* Fix#5873 - Share sheet not in dark mode

* #5873: Create theme for shareExtension
  • Loading branch information
yusadogru committed Mar 12, 2020
1 parent bacc7b5 commit 512e03c
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 11 deletions.
4 changes: 4 additions & 0 deletions Client.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@
E6F965121B2F1CF20034B023 /* Shared.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 288A2D861AB8B3260023ABC3 /* Shared.framework */; };
E6F9653C1B2F1D5D0034B023 /* NSURLExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6F9653B1B2F1D5D0034B023 /* NSURLExtensionsTests.swift */; };
E6FF6ACA1D873CFF0070C294 /* PageMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6FF6AC91D873CFF0070C294 /* PageMetadata.swift */; };
EA0EE87723D0F1DE002BEDAA /* Theme.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA0EE87423D0EFCA002BEDAA /* Theme.swift */; };
EB1C84BF212EFFBF001489DF /* BrowserViewController+ReaderMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB1C84B6212EFFBF001489DF /* BrowserViewController+ReaderMode.swift */; };
EB3A38A02032673E004C6E67 /* DatabaseFixtureTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB3A38912032673D004C6E67 /* DatabaseFixtureTest.swift */; };
EB63CA51228F0539005FD0EF /* DesktopModeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB63CA4F228F0538005FD0EF /* DesktopModeTests.swift */; };
Expand Down Expand Up @@ -1831,6 +1832,7 @@
E6F9653B1B2F1D5D0034B023 /* NSURLExtensionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSURLExtensionsTests.swift; sourceTree = "<group>"; };
E6FCC43C1C40565200DF6113 /* FirefoxBeta.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = FirefoxBeta.xcconfig; path = Configuration/FirefoxBeta.xcconfig; sourceTree = "<group>"; };
E6FF6AC91D873CFF0070C294 /* PageMetadata.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PageMetadata.swift; sourceTree = "<group>"; };
EA0EE87423D0EFCA002BEDAA /* Theme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Theme.swift; sourceTree = "<group>"; };
EB1C84B6212EFFBF001489DF /* BrowserViewController+ReaderMode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "BrowserViewController+ReaderMode.swift"; sourceTree = "<group>"; };
EB3A38912032673D004C6E67 /* DatabaseFixtureTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseFixtureTest.swift; sourceTree = "<group>"; };
EB63CA4F228F0538005FD0EF /* DesktopModeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DesktopModeTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3663,6 +3665,7 @@
E41A7D4A1A1BE04500245963 /* InitialViewController.swift */,
EB940747208134AF00702E05 /* UXConstants.swift */,
F8708D291A0970990051AB07 /* ShareViewController.swift */,
EA0EE87423D0EFCA002BEDAA /* Theme.swift */,
);
path = ShareTo;
sourceTree = "<group>";
Expand Down Expand Up @@ -5343,6 +5346,7 @@
D04CD74D216CF86F004FF5B0 /* DevicePickerViewController.swift in Sources */,
E418D0D91A251B3200CAE47A /* Profile.swift in Sources */,
DDA24A451FD84D630098F159 /* DefaultSearchPrefs.swift in Sources */,
EA0EE87723D0F1DE002BEDAA /* Theme.swift in Sources */,
F8708D321A0970B70051AB07 /* ShareViewController.swift in Sources */,
EB9407492081353100702E05 /* UXConstants.swift in Sources */,
E68F36AD1EA698650048CF44 /* PanelDataObservers.swift in Sources */,
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 12 additions & 8 deletions Extensions/ShareTo/ShareViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,19 @@ class ShareViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
setupUI()
}

view.backgroundColor = .white
func setupUI() {
view.backgroundColor = Theme.defaultBackground.color
view.subviews.forEach({ $0.removeFromSuperview() })

setupNavBar()
setupStackView()
setupRows()

guard let shareItem = shareItem else { return }

self.setupRows()

switch shareItem {
case .shareItem(let item):
self.pageInfoRowUrlLabel?.text = item.url
Expand Down Expand Up @@ -140,7 +143,7 @@ class ShareViewController: UIViewController {

private func makeSeparator(addTo parent: UIStackView) {
let view = UIView()
view.backgroundColor = UX.separatorColor
view.backgroundColor = Theme.separator.color
parent.addArrangedSubview(view)
view.snp.makeConstraints { make in
make.leading.trailing.equalToSuperview()
Expand Down Expand Up @@ -203,12 +206,12 @@ class ShareViewController: UIViewController {

let icon = UIImageView(image: UIImage(named: imageName)?.withRenderingMode(.alwaysTemplate))
icon.contentMode = .scaleAspectFit
icon.tintColor = UX.actionRowTextAndIconColor
icon.tintColor = Theme.actionRowTextAndIcon.color

let title = UILabel()
title.font = UX.baseFont
title.handleLongLabels()
title.textColor = UX.actionRowTextAndIconColor
title.textColor = Theme.actionRowTextAndIcon.color
title.text = label
[icon, title].forEach { row.addArrangedSubview($0) }

Expand All @@ -219,7 +222,7 @@ class ShareViewController: UIViewController {
if hasNavigation {
let navButton = UIImageView(image: UIImage(named: "menu-Disclosure")?.withRenderingMode(.alwaysTemplate))
navButton.contentMode = .scaleAspectFit
navButton.tintColor = UX.actionRowTextAndIconColor
navButton.tintColor = Theme.actionRowTextAndIcon.color
row.addArrangedSubview(navButton)
navButton.snp.makeConstraints { make in
make.width.equalTo(14)
Expand Down Expand Up @@ -256,7 +259,7 @@ class ShareViewController: UIViewController {
private func makeActionDoneRow(addTo parent: UIStackView) -> (row: UIStackView, label: UILabel) {
let stackView = UIStackView()
stackView.axis = .horizontal
stackView.addBackground(color: UX.doneLabelBackgroundColor)
stackView.addBackground(color: Theme.doneLabelBackground.color)
stackView.rightLeftEdges(inset: UX.rowInset)
parent.addArrangedSubview(stackView)

Expand Down Expand Up @@ -290,6 +293,7 @@ class ShareViewController: UIViewController {
navigationItem.titleView = UIImageView(image: UIImage(named: "Icon-Small"))
navigationItem.titleView?.contentMode = .scaleAspectFit
navigationItem.leftBarButtonItem = UIBarButtonItem(title: Strings.SendToCancelButton, style: .plain, target: self, action: #selector(finish))
navigationController?.navigationBar.barTintColor = Theme.defaultBackground.color
}

private func setupStackView() {
Expand Down
45 changes: 45 additions & 0 deletions Extensions/ShareTo/Theme.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import UIKit

private enum ColorScheme {
case dark
case light
}

public struct ModernColor {
var darkColor: UIColor
var lightColor: UIColor

public init(dark: UIColor, light: UIColor) {
self.darkColor = dark
self.lightColor = light
}

public var color: UIColor {
if #available(iOS 13, *) {
return UIColor { (traitCollection: UITraitCollection) -> UIColor in
if traitCollection.userInterfaceStyle == .dark {
return self.color(for: .dark)
} else {
return self.color(for: .light)
}
}
} else {
return color(for: .light)
}
}

private func color(for scheme: ColorScheme) -> UIColor {
return scheme == .dark ? darkColor : lightColor
}
}

struct Theme {
static let defaultBackground = ModernColor(dark: UIColor.Photon.Grey80, light: .white)
static let doneLabelBackground = ModernColor(dark: UIColor.Photon.Blue40, light: UIColor.Photon.Blue40)
static let separator = ModernColor(dark: UIColor.Photon.Grey10, light: UIColor.Photon.Grey30)
static let actionRowTextAndIcon = ModernColor(dark: .white, light: UIColor.Photon.Grey80)
}
3 changes: 0 additions & 3 deletions Extensions/ShareTo/UXConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ struct UX {
static let rowInset: CGFloat = 16
static let pageInfoRowLeftInset = UX.rowInset + 6
static let pageInfoLineSpacing: CGFloat = 2
static let doneLabelBackgroundColor = UIColor.Photon.Blue40
static let doneLabelFont = UIFont.boldSystemFont(ofSize: 17)
static let separatorColor = UIColor.Photon.Grey30
static let baseFont = UIFont.systemFont(ofSize: 15)
static let actionRowTextAndIconColor = UIColor.Photon.Grey80

static let navBarLandscapeShrinkage = 10 // iOS automatically shrinks nav bar in compact landscape
static let numberOfActionRows = 5 // One more row than this for the page info row.
Expand Down

0 comments on commit 512e03c

Please sign in to comment.