-
-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add font picker config environment value
- Loading branch information
1 parent
5dcb98d
commit ee3134b
Showing
15 changed files
with
196 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// | ||
// RichTextFont+PickerConfig.swift | ||
// RichTextKit | ||
// | ||
// Created by Daniel Saidi on 2024-03-04. | ||
// Copyright © 2024 Daniel Saidi. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
public extension RichTextFont { | ||
|
||
/// This struct can configure a ``RichTextFont/Picker``. | ||
/// | ||
/// This configuration contains configuration properties | ||
/// for many different font pickers types. Some of these | ||
/// properties are not used in some pickers. | ||
struct PickerConfig { | ||
|
||
/// Create a custom rich text font picker config. | ||
/// | ||
/// - Parameters: | ||
/// - fonts: The fonts to display in the list, by default `all`. | ||
/// - fontSize: The font size to use in the list items, by default `20`. | ||
/// - dismissAfterPick: Whether or not to dismiss the picker after a font is selected, by default `false`. | ||
/// - moveSelectionTopmost: Whether or not to place the selected font topmost, by default `true`. | ||
public init( | ||
fonts: [RichTextFont.PickerFont] = .all, | ||
fontSize: CGFloat = 20, | ||
dismissAfterPick: Bool = false, | ||
moveSelectionTopmost: Bool = true | ||
) { | ||
self.fonts = fonts | ||
self.fontSize = fontSize | ||
self.dismissAfterPick = dismissAfterPick | ||
self.moveSelectionTopmost = moveSelectionTopmost | ||
} | ||
|
||
/// The fonts to display in the list. | ||
public var fonts: [RichTextFont.PickerFont] | ||
|
||
/// The font size to use in the list items. | ||
public var fontSize: CGFloat | ||
|
||
/// Whether or not to dismiss the picker after a font is selected. | ||
public var dismissAfterPick: Bool | ||
|
||
/// Whether or not to move the selected font topmost | ||
public var moveSelectionTopmost: Bool | ||
} | ||
} | ||
|
||
public extension RichTextFont.PickerConfig { | ||
|
||
/// The standard rich text font picker configuration. | ||
/// | ||
/// You can set a new value to change the global default. | ||
static var standard = Self() | ||
} | ||
|
||
public extension View { | ||
|
||
/// Apply a ``RichTextFont`` picker configuration. | ||
func richTextFontPickerConfig( | ||
_ config: RichTextFont.PickerConfig | ||
) -> some View { | ||
self.environment(\.richTextFontPickerConfig, config) | ||
} | ||
} | ||
|
||
private extension RichTextFont.PickerConfig { | ||
|
||
struct Key: EnvironmentKey { | ||
|
||
public static var defaultValue: RichTextFont.PickerConfig = .standard | ||
} | ||
} | ||
|
||
public extension EnvironmentValues { | ||
|
||
var richTextFontPickerConfig: RichTextFont.PickerConfig { | ||
get { self [RichTextFont.PickerConfig.Key.self] } | ||
set { self [RichTextFont.PickerConfig.Key.self] = newValue } | ||
} | ||
} |
Oops, something went wrong.