-
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move RichTextAlignment views into enum namespace
- Loading branch information
1 parent
85b3b60
commit 7e3d4a6
Showing
14 changed files
with
183 additions
and
93 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
97 changes: 97 additions & 0 deletions
97
Sources/RichTextKit/Alignment/RichTextAlignment+Picker.swift
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,97 @@ | ||
// | ||
// RichTextAlignment+Picker.swift | ||
// RichTextKit | ||
// | ||
// Created by Daniel Saidi on 2022-05-30. | ||
// Copyright © 2022-2024 Daniel Saidi. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
public extension RichTextAlignment { | ||
|
||
/** | ||
This picker can be used to pick rich text alignments. | ||
|
||
The view returns a plain SwiftUI `Picker` view that can | ||
be styled and configured with plain SwiftUI. | ||
*/ | ||
struct Picker: View { | ||
|
||
/** | ||
Create a rich text alignment picker. | ||
|
||
- Parameters: | ||
- selection: The binding to update with the picker. | ||
- style: The style to apply, by default `.standard`. | ||
- values: The pickable alignments, by default `.allCases`. | ||
*/ | ||
public init( | ||
selection: Binding<RichTextAlignment>, | ||
style: Style = .standard, | ||
values: [RichTextAlignment] = RichTextAlignment.allCases | ||
) { | ||
self._selection = selection | ||
self.style = style | ||
self.values = values | ||
} | ||
|
||
let style: Style | ||
let values: [RichTextAlignment] | ||
|
||
@Binding | ||
private var selection: RichTextAlignment | ||
|
||
public var body: some View { | ||
SwiftUI.Picker("", selection: $selection) { | ||
ForEach(RichTextAlignment.allCases) { value in | ||
value.icon | ||
.foregroundColor(style.iconColor) | ||
.accessibilityLabel(value.title) | ||
.tag(value) | ||
} | ||
} | ||
.accessibilityLabel(RTKL10n.textAlignment.text) | ||
} | ||
} | ||
} | ||
|
||
public extension RichTextAlignment.Picker { | ||
|
||
/// This style can be used to style an alignment picker. | ||
struct Style { | ||
|
||
public init( | ||
iconColor: Color = .primary | ||
) { | ||
self.iconColor = iconColor | ||
} | ||
|
||
public var iconColor: Color | ||
} | ||
} | ||
|
||
public extension RichTextAlignment.Picker.Style { | ||
|
||
static var standard = Self.init() | ||
} | ||
|
||
struct RichTextAlignment_Picker_Previews: PreviewProvider { | ||
|
||
struct Preview: View { | ||
|
||
@State | ||
private var alignment = RichTextAlignment.left | ||
|
||
var body: some View { | ||
RichTextAlignment.Picker( | ||
selection: $alignment, | ||
values: .all | ||
) | ||
} | ||
} | ||
|
||
static var previews: some View { | ||
Preview() | ||
} | ||
} |
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
46 changes: 0 additions & 46 deletions
46
Sources/RichTextKit/Alignment/RichTextAlignmentPicker.swift
This file was deleted.
Oops, something went wrong.
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
4 changes: 4 additions & 0 deletions
4
Sources/RichTextKit/_Deprecated/RichTextAlignment+Deprecated.swift
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,4 @@ | ||
import SwiftUI | ||
|
||
@available(*, deprecated, renamed: "RichTextAlignment.Picker") | ||
public typealias RichTextAlignmentPicker = RichTextAlignment.Picker |
Oops, something went wrong.