Skip to content

Commit

Permalink
Merge pull request #231 from kyleve/kve/dark-mode-bg
Browse files Browse the repository at this point in the history
Change the default BG color for dark mode.
  • Loading branch information
kyleve authored Nov 19, 2020
2 parents 4d96646 + b243497 commit 42d0198
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 19 additions & 1 deletion ListableUI/Sources/Appearance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
) {
Expand All @@ -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
}
}
}
8 changes: 7 additions & 1 deletion ListableUI/Tests/AppearanceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 42d0198

Please sign in to comment.