Use asset catalog for tint colour. Update Sentry. (#705)

Sentry had a bug where the colour was being ignored due to access of the main screen.
This commit is contained in:
Doug
2023-03-16 12:32:14 +00:00
committed by GitHub
parent b51489e432
commit 9887219783
6 changed files with 152 additions and 8 deletions

View File

@@ -113,8 +113,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/getsentry/sentry-cocoa",
"state" : {
"revision" : "71fd3032635fed58ae1c1ba22bb7ffa158dbb5ee",
"version" : "7.30.2"
"revision" : "2e7899aff930ed3b8d81be1909492f7684bbd481",
"version" : "8.3.1"
}
},
{

View File

@@ -0,0 +1,78 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.133",
"green" : "0.114",
"red" : "0.106"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.949",
"green" : "0.933",
"red" : "0.922"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "contrast",
"value" : "high"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.129",
"green" : "0.110",
"red" : "0.102"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
},
{
"appearance" : "contrast",
"value" : "high"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.969",
"green" : "0.961",
"red" : "0.949"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -22,10 +22,6 @@ struct Application: App {
private let applicationCoordinator: AppCoordinatorProtocol
init() {
// Set the tint colour app-wide. Using UIView ensures that alerts, confirmation dialogs
// and Xcode previews all take on the tint colour, similar to defining it in an asset catalog.
UIView.appearance().tintColor = .element.accent
if Tests.isRunningUITests {
applicationCoordinator = UITestsAppCoordinator()
} else {

View File

@@ -13,6 +13,8 @@
#endif
// Deprecated typealiases
@available(*, deprecated, renamed: "ColorAsset.Color", message: "This typealias will be removed in SwiftGen 7.0")
internal typealias AssetColorTypeAlias = ColorAsset.Color
@available(*, deprecated, renamed: "ImageAsset.Image", message: "This typealias will be removed in SwiftGen 7.0")
internal typealias AssetImageTypeAlias = ImageAsset.Image
@@ -22,6 +24,9 @@ internal typealias AssetImageTypeAlias = ImageAsset.Image
// swiftlint:disable identifier_name line_length nesting type_body_length type_name
internal enum Asset {
internal enum Colors {
internal static let accentColor = ColorAsset(name: "Colors/AccentColor")
}
internal enum Images {
internal static let analyticsCheckmark = ImageAsset(name: "Images/AnalyticsCheckmark")
internal static let analyticsLogo = ImageAsset(name: "Images/AnalyticsLogo")
@@ -42,6 +47,70 @@ internal enum Asset {
// MARK: - Implementation Details
internal final class ColorAsset {
internal fileprivate(set) var name: String
#if os(macOS)
internal typealias Color = NSColor
#elseif os(iOS) || os(tvOS) || os(watchOS)
internal typealias Color = UIColor
#endif
@available(iOS 11.0, tvOS 11.0, watchOS 4.0, macOS 10.13, *)
internal private(set) lazy var color: Color = {
guard let color = Color(asset: self) else {
fatalError("Unable to load color asset named \(name).")
}
return color
}()
#if os(iOS) || os(tvOS)
@available(iOS 11.0, tvOS 11.0, *)
internal func color(compatibleWith traitCollection: UITraitCollection) -> Color {
let bundle = BundleToken.bundle
guard let color = Color(named: name, in: bundle, compatibleWith: traitCollection) else {
fatalError("Unable to load color asset named \(name).")
}
return color
}
#endif
#if canImport(SwiftUI)
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
internal private(set) lazy var swiftUIColor: SwiftUI.Color = {
SwiftUI.Color(asset: self)
}()
#endif
fileprivate init(name: String) {
self.name = name
}
}
internal extension ColorAsset.Color {
@available(iOS 11.0, tvOS 11.0, watchOS 4.0, macOS 10.13, *)
convenience init?(asset: ColorAsset) {
let bundle = BundleToken.bundle
#if os(iOS) || os(tvOS)
self.init(named: asset.name, in: bundle, compatibleWith: nil)
#elseif os(macOS)
self.init(named: NSColor.Name(asset.name), bundle: bundle)
#elseif os(watchOS)
self.init(named: asset.name)
#endif
}
}
#if canImport(SwiftUI)
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
internal extension SwiftUI.Color {
init(asset: ColorAsset) {
let bundle = BundleToken.bundle
self.init(asset.name, bundle: bundle)
}
}
#endif
internal struct ImageAsset {
internal fileprivate(set) var name: String

View File

@@ -1 +1 @@
Fix accent colour not being applied to Alerts etc.
Use a local copy of the accent colour in the asset catalog so it is applied to Alerts, Xcode previews etc.

View File

@@ -21,6 +21,7 @@ options:
settings:
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED: YES
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME: "Colors/AccentColor"
ENABLE_BITCODE: NO
BASE_APP_GROUP_IDENTIFIER: io.element
APP_GROUP_IDENTIFIER: group.$(BASE_APP_GROUP_IDENTIFIER)
@@ -88,7 +89,7 @@ packages:
majorVersion: 1.3.0
Sentry:
url: https://github.com/getsentry/sentry-cocoa
majorVersion: 7.15.0
majorVersion: 8.3.1
SnapshotTesting:
url: https://github.com/pointfreeco/swift-snapshot-testing
majorVersion: 1.10.0