Skip to content

Commit 8897878

Browse files
committed
Deprecate line
1 parent 057e7fb commit 8897878

8 files changed

+46
-82
lines changed

RELEASE_NOTES.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ Until then, minor updates may remove deprecated features and introduce breaking
88

99
## 1.2
1010

11+
This version makes a first step towards removing library-specific types in favor of native types, to avoid having to add custom types and logic to the library, where native alternatives exist.
12+
13+
This version deprecates the `RichTextAlignment` type and instead
14+
1115
This version adds key path-based paragraph functions to the `RichTextViewComponent`. This means that you can now get and set the following values with a single set of functions, pickers, steppers and toggles:
1216

1317
`alignment`, `allowsDefaultTighteningForTruncation`, `baseWritingDirection`, `defaultTabInterval`, `firstLineHeadIndent`, `headIndent`, `hyphenationFactor`, `lineBreakMode`, `lineBreakStrategy`, `lineHeightMultiple`, `lineSpacing`, `maximumLineHeight`, `minimumLineHeight`, `paragraphSpacing`, `paragraphSpacingBefore`, `tabStops`, `tailIndent`, `usesDefaultHyphenation`.
@@ -37,8 +41,8 @@ As a result, all parts of the library that handled individual value types have b
3741

3842
### 🗑️ Deprecations
3943

40-
* `RichTextAlignment` has been deprecated due to the new paragraph-based features.
41-
* `RichTextAlignment.Picker` has been deprecated due to the new `Picker` capabilities.
44+
* `RichTextAlignment` and all nested types have been deprecated due to the new paragraph-based features.
45+
* `RichTextLine` and all nested types have been deprecated due to the new paragraph-based features.
4246

4347

4448

Sources/RichTextKit/Paragraph/Stepper+RichTextParagraphValue.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import SwiftUI
1010

11+
#if iOS || os(macOS) || os(visionOS)
1112
public extension Stepper {
1213

1314
/// Creates a stepper for a paragraph style value in the
@@ -73,3 +74,4 @@ public extension Stepper {
7374

7475
return Preview()
7576
}
77+
#endif

Sources/RichTextKit/RichTextKit.docc/RichTextKit.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,6 @@ RichTextKit is available under the MIT license.
149149
- ``RichTextKeyboardToolbarMenu``
150150
- ``RichTextKeyboardToolbarStyle``
151151

152-
### Line
153-
154-
- ``RichTextLine``
155-
156152
### Localization
157153

158154
- ``RTKL10n``

Sources/RichTextKit/_Deprecated/RichTextAlignment.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import SwiftUI
1010

11-
@available(*, deprecated, message: "Use native NSTextAlignment directly")
11+
@available(*, deprecated, message: "Use native NSTextAlignment directly instead.")
1212
public enum RichTextAlignment: String, CaseIterable, Codable, Equatable, Identifiable, RichTextLabelValue {
1313

1414
/// Create a rich text alignment with a native alignment.
@@ -38,13 +38,13 @@ public enum RichTextAlignment: String, CaseIterable, Codable, Equatable, Identif
3838
case right
3939
}
4040

41-
@available(*, deprecated, message: "Use native NSTextAlignment instead")
41+
@available(*, deprecated, message: "Use native NSTextAlignment directly instead.")
4242
public extension Collection where Element == RichTextAlignment {
4343

4444
static var all: [Element] { RichTextAlignment.allCases }
4545
}
4646

47-
@available(*, deprecated, message: "Use native NSTextAlignment instead")
47+
@available(*, deprecated, message: "Use native NSTextAlignment directly instead.")
4848
public extension RichTextAlignment {
4949

5050
/// The unique alignment ID.

Sources/RichTextKit/Line/RichTextLine+SpacingPicker.swift renamed to Sources/RichTextKit/_Deprecated/RichTextLine+SpacingPicker.swift

Lines changed: 28 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,46 @@
88

99
import SwiftUI
1010

11+
@available(*, deprecated, message: "Use SwiftUI Picker with native NSParagraphStyle directly instead.")
1112
public extension RichTextLine {
12-
13+
1314
/**
1415
This picker can be used to pick a font size.
15-
16+
1617
The view returns a plain SwiftUI `Picker` view that can
1718
be styled and configured with plain SwiftUI.
18-
19+
1920
You can configure this picker by applying a config view
2021
modifier to your view hierarchy:
21-
22+
2223
```swift
2324
VStack {
24-
RichTextLine.SpacingPicker(...)
25-
...
25+
RichTextLine.SpacingPicker(...)
26+
...
2627
}
2728
.richTextLineSpacingPickerConfig(...)
2829
```
2930
*/
3031
struct SpacingPicker: View {
31-
32+
3233
/**
3334
Create a line spacing picker.
34-
35+
3536
- Parameters:
36-
- selection: The selected font size.
37+
- selection: The selected font size.
3738
*/
3839
public init(
3940
selection: Binding<CGFloat>
4041
) {
4142
self._selection = selection
4243
}
43-
44+
4445
@Binding
4546
private var selection: CGFloat
46-
47+
4748
@Environment(\.richTextLineSpacingPickerConfig)
4849
private var config
49-
50+
5051
public var body: some View {
5152
Picker(RTKL10n.lineSpacing.text, selection: $selection) {
5253
ForEach(values(
@@ -58,46 +59,21 @@ public extension RichTextLine {
5859
}
5960
}
6061
}
61-
}
62-
}
63-
64-
public extension RichTextLine.SpacingPicker {
65-
66-
/// Get a list of values for a certain selection.
67-
func values(
68-
for values: [CGFloat],
69-
selection: CGFloat
70-
) -> [CGFloat] {
71-
let values = values + [selection]
72-
return Array(Set(values)).sorted()
73-
}
74-
}
75-
76-
private extension RichTextLine.SpacingPicker {
77-
78-
func text(
79-
for fontSize: CGFloat
80-
) -> some View {
81-
Text(String(format: "%.1f", fontSize))
82-
.fixedSize(horizontal: true, vertical: false)
83-
}
84-
}
85-
86-
#Preview {
87-
88-
struct Preview: View {
89-
90-
@State
91-
private var selection: CGFloat = 2.0
92-
93-
var body: some View {
94-
RichTextLine.SpacingPicker(
95-
selection: $selection
96-
)
97-
.withPreviewPickerStyles()
98-
.richTextLineSpacingPickerConfig(.init(values: [1, 2, 3]))
62+
63+
/// Get a list of values for a certain selection.
64+
func values(
65+
for values: [CGFloat],
66+
selection: CGFloat
67+
) -> [CGFloat] {
68+
let values = values + [selection]
69+
return Array(Set(values)).sorted()
70+
}
71+
72+
func text(
73+
for fontSize: CGFloat
74+
) -> some View {
75+
Text(String(format: "%.1f", fontSize))
76+
.fixedSize(horizontal: true, vertical: false)
9977
}
10078
}
101-
102-
return Preview()
10379
}

Sources/RichTextKit/Line/RichTextLine+SpacingPickerConfig.swift renamed to Sources/RichTextKit/_Deprecated/RichTextLine+SpacingPickerConfig.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import SwiftUI
1010

11+
@available(*, deprecated, message: "Use SwiftUI Picker with native NSParagraphStyle directly instead.")
1112
public extension RichTextLine {
1213

1314
/// This can be used with a ``RichTextLine/SpacingPicker``.
@@ -28,12 +29,14 @@ public extension RichTextLine {
2829
}
2930
}
3031

32+
@available(*, deprecated, message: "Use SwiftUI Picker with native NSParagraphStyle directly instead.")
3133
public extension RichTextLine.SpacingPickerConfig {
3234

3335
/// The standard line spacing picker configuration.
3436
static var standard: Self { .init() }
3537
}
3638

39+
@available(*, deprecated, message: "Use SwiftUI Picker with native NSParagraphStyle directly instead.")
3740
public extension View {
3841

3942
/// Apply a ``RichTextLine`` spacing picker configuration.
@@ -44,6 +47,7 @@ public extension View {
4447
}
4548
}
4649

50+
@available(*, deprecated, message: "Use SwiftUI Picker with native NSParagraphStyle directly instead.")
4751
private extension RichTextLine.SpacingPickerConfig {
4852

4953
struct Key: EnvironmentKey {
@@ -54,6 +58,7 @@ private extension RichTextLine.SpacingPickerConfig {
5458
}
5559
}
5660

61+
@available(*, deprecated, message: "Use SwiftUI Picker with native NSParagraphStyle directly instead.")
5762
public extension EnvironmentValues {
5863

5964
/// This value can bind to a line spacing picker config.

Sources/RichTextKit/Line/RichTextLine+SpacingPickerStack.swift renamed to Sources/RichTextKit/_Deprecated/RichTextLine+SpacingPickerStack.swift

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#if iOS || macOS || os(visionOS)
1010
import SwiftUI
1111

12+
@available(*, deprecated, message: "Use SwiftUI Picker with native NSParagraphStyle directly instead.")
1213
public extension RichTextLine {
1314

1415
/**
@@ -63,24 +64,4 @@ public extension RichTextLine {
6364
}
6465
}
6566
}
66-
67-
#Preview {
68-
69-
struct Preview: View {
70-
71-
@StateObject
72-
private var context = RichTextContext()
73-
74-
var body: some View {
75-
VStack {
76-
Text("Spacing: \(context.paragraphStyle[keyPath: \.lineSpacing])")
77-
RichTextLine.SpacingPickerStack(context: context)
78-
}
79-
.buttonStyle(.bordered)
80-
.padding()
81-
}
82-
}
83-
84-
return Preview()
85-
}
8667
#endif

Sources/RichTextKit/Line/RichTextLine.swift renamed to Sources/RichTextKit/_Deprecated/RichTextLine.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88

99
import Foundation
1010

11-
/// This is a namespace for line-related types and views.
11+
@available(*, deprecated, message: "Use native NSParagraphStyle directly instead.")
1212
public struct RichTextLine {}

0 commit comments

Comments
 (0)