diff --git a/CHANGELOG.md b/CHANGELOG.md index 18f478991..4272d8fb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ - [Ensure we respect both `frame` and `bounds` changes](https://github.com/kyleve/Listable/pull/227) to update the inner `CollectionView`'s frame. We previously used to only respect `frame` changes, but we should also respect `bounds` changes, as these are used by auto layout. +- [`Appearance.backgroundColor` now respects the current `UITraitCollection.userInterfaceStyle`](https://github.com/kyleve/Listable/pull/231). This means that the background color will default to `white` in light mode, and `black` in dark mode. + ### Added - [Introduce `onSelectionChanged` on `ListStateObserver`](https://github.com/kyleve/Listable/pull/223) to allow observing when the selected rows change. diff --git a/ListableUI/Sources/Appearance.swift b/ListableUI/Sources/Appearance.swift index 53b49f471..bccdc518c 100644 --- a/ListableUI/Sources/Appearance.swift +++ b/ListableUI/Sources/Appearance.swift @@ -22,7 +22,7 @@ public struct Appearance : Equatable /// Creates a new appearance object with the provided options. public init( - backgroundColor : UIColor = .white, + backgroundColor : UIColor = Self.defaultBackgroundColor, showsScrollIndicators : Bool = true, configure : (inout Self) -> () = { _ in } ) { @@ -32,4 +32,22 @@ public struct Appearance : Equatable configure(&self) } + + /// The default background color for the `Appearance`. + public static var defaultBackgroundColor : UIColor { + if #available(iOS 13.0, *) { + return UIColor { traits in + switch traits.userInterfaceStyle { + case .unspecified, .light: + return .white + case .dark: + return .black + @unknown default: + return .white + } + } + } else { + return .white + } + } } diff --git a/ListableUI/Tests/AppearanceTests.swift b/ListableUI/Tests/AppearanceTests.swift index 99bb9847e..e48c4ad63 100644 --- a/ListableUI/Tests/AppearanceTests.swift +++ b/ListableUI/Tests/AppearanceTests.swift @@ -16,7 +16,13 @@ class AppearanceTests: XCTestCase { let appearance = Appearance() - XCTAssertEqual(appearance.backgroundColor, .white) + if #available(iOS 13.0, *) { + XCTAssertEqual(appearance.backgroundColor.resolvedColor(with: .init(userInterfaceStyle: .dark)), .black) + XCTAssertEqual(appearance.backgroundColor.resolvedColor(with: .init(userInterfaceStyle: .light)), .white) + } else { + XCTAssertEqual(appearance.backgroundColor, .white) + } + XCTAssertEqual(appearance.showsScrollIndicators, true) } }