Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve dark mode and dynamic font support #14

Merged
merged 3 commits into from
Mar 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#### Enhancements

* None
* [QAMenuUIKit] Improved dark mode and dynamic font support (PR #14)

#### Bug Fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,8 @@ internal final class UnsupportedItemView: NibView, ItemUIRepresentable {

internal func setItem(_ item: Item) {
self.titleLabel.text = "Error: No UI representation is registered for item of type \(type(of: item))"
self.titleLabel.numberOfLines = 0
self.titleLabel.textColor = .systemRed
self.titleLabel.font = .preferredFont(forTextStyle: .body)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ extension FooterViewSupporting {
let label = UILabel()
label.tag = self.footerViewTag
label.numberOfLines = 0
label.textColor = .darkGray
label.textColor = .systemGray
label.font = .preferredFont(forTextStyle: .footnote)
return label
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ internal final class BooleanItemView: NibView, ItemView {

override internal func initFromNib() {
super.initFromNib()
self.applyStyle()
self.setupFooterView()
}

Expand All @@ -95,6 +96,16 @@ internal final class BooleanItemView: NibView, ItemView {
self.updateFooterView()
}

private func applyStyle() {
self.titleLabel.numberOfLines = 0
if #available(iOS 13.0, *) {
self.titleLabel.textColor = .label
} else {
self.titleLabel.textColor = .black
}
self.titleLabel.font = .preferredFont(forTextStyle: .body)
}

private func reload() {
self.updateViewContent()
self.delegate?.updateContainerHeight(for: self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ internal final class ButtonItemView: NibView, ItemView {

override internal func initFromNib() {
super.initFromNib()
self.applyStyle()
self.setupFooterView()
}

Expand All @@ -94,6 +95,24 @@ internal final class ButtonItemView: NibView, ItemView {
self.updateFooterView()
}

private func applyStyle() {
self.progressLabel.numberOfLines = 0
self.progressLabel.textColor = .systemGray
self.progressLabel.font = .preferredFont(forTextStyle: .body)
self.titleLabel.numberOfLines = 0
if #available(iOS 13.0, *) {
self.titleLabel.textColor = .link
} else {
self.titleLabel.textColor = .systemBlue
}
self.titleLabel.font = .preferredFont(forTextStyle: .body)
if #available(iOS 13.0, *) {
self.indicator.style = .medium
} else {
self.indicator.style = .gray
}
}

private func reload() {
self.updateViewContent()
self.delegate?.updateContainerHeight(for: self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ internal final class PickableStringItemView: NibView, ItemView, ShareInteraction

override internal func initFromNib() {
super.initFromNib()
self.titleLabel.numberOfLines = 0
self.applyStyle()
self.setupFooterView()

self.shareInteractionHandler = ShareInteractionHandler(
Expand Down Expand Up @@ -112,6 +112,16 @@ internal final class PickableStringItemView: NibView, ItemView, ShareInteraction
updateFooterView()
}

private func applyStyle() {
self.titleLabel.numberOfLines = 0
if #available(iOS 13.0, *) {
self.titleLabel.textColor = .label
} else {
self.titleLabel.textColor = .black
}
self.titleLabel.font = .preferredFont(forTextStyle: .body)
}

private func reload() {
self.updateViewContent()
self.delegate?.updateContainerHeight(for: self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ internal final class ProgressItemView: NibView, ItemView {

override internal func initFromNib() {
super.initFromNib()
self.applyStyle()
self.setupFooterView()
}

Expand All @@ -92,14 +93,24 @@ internal final class ProgressItemView: NibView, ItemView {
self.updateFooterView()
}

private func applyStyle() {
self.label.numberOfLines = 0
self.label.font = .preferredFont(forTextStyle: .body)
if #available(iOS 13.0, *) {
self.activityIndicator.style = .medium
} else {
self.activityIndicator.style = .gray
}
}

private func reload() {
self.updateViewContent()
self.delegate?.updateContainerHeight(for: self)
}

private func updateProgressViews(for status: ProgressItem.State?) {
let status = status ?? .idle
self.label.textColor = .darkGray
self.label.textColor = .systemGray
switch status {
case .idle:
self.label.text = nil
Expand All @@ -114,12 +125,17 @@ internal final class ProgressItemView: NibView, ItemView {
case .success(let message):
self.label.text = message
self.label.isHidden = message?.isEmpty != false
if #available(iOS 13.0, *) {
self.label.textColor = .label
} else {
self.label.textColor = .black
}
self.activityIndicator.stopAnimating()
self.activityIndicator.isHidden = true
case .failure(let message):
self.label.text = message
self.label.isHidden = message?.isEmpty != false
self.label.textColor = .red
self.label.textColor = .systemRed
self.activityIndicator.stopAnimating()
self.activityIndicator.isHidden = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ internal final class StringItemView: NibView, ItemView, ShareInteractionSupporti

override internal func initFromNib() {
super.initFromNib()
self.applyStyle()
self.setupFooterView()

self.shareInteractionHandler = ShareInteractionHandler(
Expand Down Expand Up @@ -120,7 +121,6 @@ internal final class StringItemView: NibView, ItemView, ShareInteractionSupporti
self.titleLabel.text = nil
self.valueLabel.text = nil
}
self.valueLabel.textColor = .darkGray

updateFooterView()
}
Expand Down Expand Up @@ -149,6 +149,17 @@ internal final class StringItemView: NibView, ItemView, ShareInteractionSupporti
self.textStackView.setNeedsLayout()
}

private func applyStyle() {
if #available(iOS 13.0, *) {
self.titleLabel.textColor = .label
} else {
self.titleLabel.textColor = .black
}
self.titleLabel.font = .preferredFont(forTextStyle: .body)
self.valueLabel.textColor = .systemGray
self.valueLabel.font = .preferredFont(forTextStyle: .body)
}

private func applyHorizontalLayout() {
self.textStackView.axis = .horizontal
self.textStackView.alignment = .fill
Expand Down
12 changes: 9 additions & 3 deletions Sources/QAMenuUIKit/Resources/ButtonItemView.xib
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="16097.2" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="17701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17703"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand Down Expand Up @@ -53,7 +54,7 @@
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="JeJ-Rv-3x2">
<rect key="frame" x="0.0" y="0.0" width="414" height="100"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" systemColor="linkColor" red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="textColor" systemColor="linkColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
Expand Down Expand Up @@ -85,4 +86,9 @@
<point key="canvasLocation" x="50.724637681159422" y="34.821428571428569"/>
</view>
</objects>
<resources>
<systemColor name="linkColor">
<color red="0.0" green="0.47843137254901963" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
</resources>
</document>
6 changes: 3 additions & 3 deletions Sources/QAMenuUIKit/Resources/PickableStringItemView.xib
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="17156" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="17701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17125"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17703"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand All @@ -19,7 +19,7 @@
<rect key="frame" x="0.0" y="0.0" width="414" height="100"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="equalSpacing" spacing="15" translatesAutoresizingMaskIntoConstraints="NO" id="rQ8-Be-LmF">
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="equalSpacing" translatesAutoresizingMaskIntoConstraints="NO" id="rQ8-Be-LmF">
<rect key="frame" x="0.0" y="0.0" width="393" height="100"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="751" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="suP-sd-BSz">
Expand Down