From 0f49c1bd3fce4991cd9afc547f32a565876a99a4 Mon Sep 17 00:00:00 2001 From: Daniel Saidi Date: Mon, 22 Jan 2024 23:33:35 +0100 Subject: [PATCH] Make rich text color picker add quick reset button --- RELEASE_NOTES.md | 6 +++++- .../RichTextKit/Colors/RichTextColor+Picker.swift | 14 +++++++++++--- Sources/RichTextKit/Colors/RichTextColor.swift | 14 +++----------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 8c13bd40f..ccec4cd18 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -14,6 +14,7 @@ This release starts moving types and views that relate to other types into the t * `RichTextAlignment.Picker` has a new style parameter. * `RichTextCommand` is a new namespace for command-related views. +* `RichTextColorPicker` now shows a quick button to reset the color. * `RichTextLabelValue` is a new protocol to harmonize label-compatible label values. ### 💡 Adjustments @@ -21,9 +22,12 @@ This release starts moving types and views that relate to other types into the t * Many value types implement `RichTextLabelValue` to get a `label` property. * All types that implement `RichTextLabelValue` get a `label` that has improved accessibility. +* `RichTextColor` `.adjust` now takes an optional + ### 🐛 Bug Fixes -* `Image.symbol(...)` removes `palette` rendering mode. +* `Image.symbol(...)` removes `palette` rendering mode to fix incorrect color scheme behavior. +* `RichTextColorPicker` no longer auto-adjusts black and white to make it possible to actually set those colors. ### 🗑️ Deprecations diff --git a/Sources/RichTextKit/Colors/RichTextColor+Picker.swift b/Sources/RichTextKit/Colors/RichTextColor+Picker.swift index c8278bb1f..70d1b37d9 100644 --- a/Sources/RichTextKit/Colors/RichTextColor+Picker.swift +++ b/Sources/RichTextKit/Colors/RichTextColor+Picker.swift @@ -59,7 +59,11 @@ public extension RichTextColor { iconView picker if hasColors { - quickPickerDivider + HStack(spacing: spacing) { + quickPickerDivider + quickPickerButton(for: nil) + quickPickerDivider + } quickPicker } } @@ -126,11 +130,15 @@ private extension RichTextColor.Picker { }.frame(maxWidth: .infinity) } - func quickPickerButton(for color: Color) -> some View { + func quickPickerButton(for color: Color?) -> some View { Button { value = type.adjust(color, for: colorScheme) } label: { - color + if let color { + color + } else { + Image(systemName: "circle.slash") + } } .buttonStyle(ColorButtonStyle()) } diff --git a/Sources/RichTextKit/Colors/RichTextColor.swift b/Sources/RichTextKit/Colors/RichTextColor.swift index afd9d6f68..2ca21df70 100644 --- a/Sources/RichTextKit/Colors/RichTextColor.swift +++ b/Sources/RichTextKit/Colors/RichTextColor.swift @@ -65,20 +65,12 @@ public extension RichTextColor { /// Adjust a `color` for a certain `colorScheme`. func adjust( - _ color: Color, + _ color: Color?, for scheme: ColorScheme ) -> Color { switch self { - case .background: - if (color == .black && scheme == .dark) || (color == .white && scheme == .light) { - return .clear - } - return color - default: - if (color == .white && scheme == .dark) || (color == .black && scheme == .light) { - return .primary - } - return color + case .background: return color ?? .clear + default: return color ?? .primary } } }