Skip to content

Commit

Permalink
Refactor keyboard toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsaidi committed Mar 4, 2024
1 parent 1e1cec4 commit 4d3cb44
Show file tree
Hide file tree
Showing 45 changed files with 167 additions and 1,957 deletions.
7 changes: 3 additions & 4 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ This release removes all deprecated code and cleans up the library somewhat.

### ✨ Features

* The new `richTextKeyboardToolbarConfig` view extension can be used to configure a `RichTextKeyboardToolbar`.
* The new `richTextKeyboardToolbarStyle` view extension can be used to style a `RichTextKeyboardToolbar`.
* The new `richTextKeyboardToolbarConfig` view extension can be used to configure the `RichTextKeyboardToolbar`.
* The new `richTextKeyboardToolbarStyle` view extension can be used to style the `RichTextKeyboardToolbar`.

### 💥 Breaking Changes

* All previously deprecated code has been deleted.

* `RichTextKeyboardToolbar`'s `style` and `config` is now applied with view extensions instead of with the initializer.
* `RichTextKeyboardToolbar`'s `leadingActions` and `trailingActions` are now specified with the configuration instead of the initializer.
* `RichTextKeyboardToolbar` is now configured with view extensions instead of with the initializer.



Expand Down
10 changes: 5 additions & 5 deletions Sources/RichTextKit/Actions/RichTextAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ public extension RichTextAction {
/// The action's standard icon.
var icon: Image {
switch self {
case .copy: .richTextActionCopy
case .dismissKeyboard: .richTextActionDismissKeyboard
case .copy: .richTextCopy
case .dismissKeyboard: .richTextDismissKeyboard
case .pasteImage: .richTextDocuments
case .pasteImages: .richTextDocuments
case .pasteText: .richTextDocuments
case .print: .richTextActionExport
case .redoLatestChange: .richTextActionRedo
case .print: .richTextPrint
case .redoLatestChange: .richTextRedo
case .selectRange: .richTextSelection
case .setAlignment(let val): val.icon
case .setAttributedString: .richTextDocument
Expand All @@ -108,7 +108,7 @@ public extension RichTextAction {
case .stepLineSpacing: .richTextLineSpacing
case .stepSuperscript(let val): .richTextStepSuperscript(val)
case .toggleStyle(let val): val.icon
case .undoLatestChange: .richTextActionUndo
case .undoLatestChange: .richTextUndo
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/RichTextKit/Data/RichTextDataFormat+Menu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct RichTextData_FormatMenu_Previews: PreviewProvider {
VStack {
RichTextDataFormat.Menu(
title: "Export...",
icon: .richTextActionExport,
icon: .richTextExport,
formatAction: { _ in },
pdfAction: {}
)
Expand Down
2 changes: 1 addition & 1 deletion Sources/RichTextKit/Export/RichTextExportMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public struct RichTextExportMenu: View {

public init(
title: String = RTKL10n.menuExportAs.text,
icon: Image = .richTextActionExport,
icon: Image = .richTextExport,
formats: [RichTextDataFormat] = RichTextDataFormat.libraryFormats,
formatAction: @escaping (RichTextDataFormat) -> Void,
pdfAction: (() -> Void)? = nil
Expand Down
16 changes: 8 additions & 8 deletions Sources/RichTextKit/Images/Image+RichText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import SwiftUI

public extension Image {

static let richTextActionCopy = symbol("doc.on.clipboard")
static let richTextActionDismissKeyboard = symbol("keyboard.chevron.compact.down")
static let richTextActionEdit = symbol("square.and.pencil")
static let richTextActionExport = symbol("square.and.arrow.up.on.square")
static let richTextActionPrint = symbol("printer")
static let richTextActionRedo = symbol("arrow.uturn.forward")
static let richTextActionShare = symbol("square.and.arrow.up")
static let richTextActionUndo = symbol("arrow.uturn.backward")
static let richTextCopy = symbol("doc.on.clipboard")
static let richTextDismissKeyboard = symbol("keyboard.chevron.compact.down")
static let richTextEdit = symbol("square.and.pencil")
static let richTextExport = symbol("square.and.arrow.up.on.square")
static let richTextPrint = symbol("printer")
static let richTextRedo = symbol("arrow.uturn.forward")
static let richTextShare = symbol("square.and.arrow.up")
static let richTextUndo = symbol("arrow.uturn.backward")

static let richTextAlignmentCenter = symbol("text.aligncenter")
static let richTextAlignmentJustified = symbol("text.justify")
Expand Down
73 changes: 73 additions & 0 deletions Sources/RichTextKit/Keyboard/RichTextKeyboardToolbar+Config.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//
// RichTextKeyboardToolbar+Config.swift
// RichTextKit
//
// Created by Ryan Jarvis on 2024-02-24.
//

#if iOS || macOS || os(visionOS)
import SwiftUI

/// This struct can configure a ``RichTextKeyboardToolbar``.
public struct RichTextKeyboardToolbarConfig {

/// Create a custom keyboard toolbar configuration.
///
/// - Parameters:
/// - alwaysDisplayToolbar: Whether or not to always show the toolbar, by default `false`.
/// - leadingActions: The leading actions, by default `.undo` and `.redo`.
/// - trailingActions: The trailing actions, by default `.dismissKeyboard`.
public init(
alwaysDisplayToolbar: Bool = false,
leadingActions: [RichTextAction] = [.undo, .redo],
trailingActions: [RichTextAction] = [.dismissKeyboard]
) {
self.alwaysDisplayToolbar = alwaysDisplayToolbar
self.leadingActions = leadingActions
self.trailingActions = trailingActions
}

/// Whether or not to always show the toolbar.
public var alwaysDisplayToolbar: Bool

/// The leading toolbar actions.
public var leadingActions: [RichTextAction]

/// The trailing toolbar actions.
public var trailingActions: [RichTextAction]
}

public extension RichTextKeyboardToolbarConfig {

/// A standard rich text keyboard toolbar configuration.
///
/// You can override this to change the global default.
static var standard = RichTextKeyboardToolbarConfig()
}

public extension View {

/// Apply a ``RichTextKeyboardToolbar`` configuration.
func richTextKeyboardToolbarConfig(
_ config: RichTextKeyboardToolbarConfig
) -> some View {
self.environment(\.richTextKeyboardToolbarConfig, config)
}
}

extension RichTextKeyboardToolbarConfig {

struct Key: EnvironmentKey {

public static var defaultValue: RichTextKeyboardToolbarConfig = .standard
}
}

public extension EnvironmentValues {

var richTextKeyboardToolbarConfig: RichTextKeyboardToolbarConfig {
get { self [RichTextKeyboardToolbarConfig.Key.self] }
set { self [RichTextKeyboardToolbarConfig.Key.self] = newValue }
}
}
#endif

This file was deleted.

Loading

0 comments on commit 4d3cb44

Please sign in to comment.