Skip to content

Commit e1f8f75

Browse files
committed
fixed buld failure for tv and watch os
1 parent 908e6fb commit e1f8f75

File tree

7 files changed

+30
-93
lines changed

7 files changed

+30
-93
lines changed

RichEditorDemo/RichEditorDemo/ContentView.swift

+8
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,22 @@ struct ContentView: View {
5858
)
5959
#endif
6060
}
61+
#if iOS || macOS
6162
.inspector(isPresented: $isInspectorPresented) {
6263
RichTextFormat.Sidebar(context: state)
6364
#if os(macOS)
6465
.inspectorColumnWidth(min: 200, ideal: 200, max: 315)
6566
#endif
6667
}
68+
#endif
6769
.padding(10)
70+
#if iOS || os(macOS)
6871
.toolbar {
6972
ToolbarItemGroup(placement: .automatic) {
7073
toolBarGroup
7174
}
7275
}
76+
#endif
7377
.background(colorScheme == .dark ? .black : .gray.opacity(0.07))
7478
.navigationTitle("Rich Editor")
7579
.alert("Enter file name", isPresented: getBindingAlert()) {
@@ -80,6 +84,7 @@ struct ContentView: View {
8084
}
8185
.focusedValue(\.richEditorState, state)
8286
.toolbarRole(.automatic)
87+
#if iOS || macOS || os(visionOS)
8388
.richTextFormatSheetConfig(.init(colorPickers: colorPickers))
8489
.richTextFormatSidebarConfig(
8590
.init(
@@ -88,9 +93,11 @@ struct ContentView: View {
8893
)
8994
)
9095
.richTextFormatToolbarConfig(.init(colorPickers: []))
96+
#endif
9197
}
9298
}
9399

100+
#if iOS || os(macOS)
94101
var toolBarGroup: some View {
95102
return Group {
96103
RichTextExportMenu.init(
@@ -125,6 +132,7 @@ struct ContentView: View {
125132
#endif
126133
}
127134
}
135+
#endif
128136

129137
func getBindingAlert() -> Binding<Bool> {
130138
.init(

Sources/RichEditorSwiftUI/Data/Models/RichAttributes+RichTextAttributes.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ extension RichAttributes {
1717
func toAttributes(font: FontRepresentable? = nil) -> RichTextAttributes {
1818
var attributes: RichTextAttributes = [:]
1919

20+
var defaultFont: FontRepresentable = .standardRichTextFont
21+
#if !os(watchOS)
22+
defaultFont = RichTextView.Theme.standard.font
23+
#endif
2024
// Set the font size and handle headers
21-
var font = font ?? RichTextView.Theme.standard.font
25+
var font = font ?? defaultFont
2226
if let headerType = self.header?.getTextSpanStyle() {
2327
font = font
2428
.updateFontSize(

Sources/RichEditorSwiftUI/UI/Context/RichEditorState.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,13 @@ public class RichEditorState: ObservableObject {
157157
tempSpans.forEach { span in
158158
str.addAttributes(span.attributes?.toAttributes(font: .standardRichTextFont) ?? [:], range: span.spanRange)
159159
if span.attributes?.color == nil {
160-
str.addAttributes([.foregroundColor: RichTextView.Theme.standard.fontColor], range: span.spanRange)
160+
var color: ColorRepresentable = .clear
161+
#if os(watchOS)
162+
color = .black
163+
#else
164+
color = RichTextView.Theme.standard.fontColor
165+
#endif
166+
str.addAttributes([.foregroundColor: color], range: span.spanRange)
161167
}
162168
}
163169

Sources/RichEditorSwiftUI/UI/Editor/RichEditorState+UITextView.swift

-89
This file was deleted.

Sources/RichEditorSwiftUI/UI/Editor/RichTextSpanStyle.swift

+8
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,18 @@ public enum RichTextSpanStyle: Equatable, CaseIterable, Hashable {
125125
size: .standardRichTextFontSize
126126
) ?? font
127127
} else {
128+
#if os(watchOS)
129+
return CGFloat.standardRichTextFontSize
130+
#else
128131
return RichTextView.Theme.standard.font
132+
#endif
129133
}
130134
case .color:
135+
#if os(watchOS)
136+
return Color.primary
137+
#else
131138
return RichTextView.Theme.standard.fontColor
139+
#endif
132140
case .background:
133141
return ColorRepresentable.white
134142
case .align:

Sources/RichEditorSwiftUI/UI/Extensions/View+BackportSupportExtension.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import SwiftUI
1010
extension View {
1111
nonisolated public func onChangeBackPort<V>(of value: V, _ action: @escaping (_ newValue: V) -> Void) -> some View where V : Equatable {
1212
Group {
13-
if #available(iOS 17.0, macOS 14.0, *) {
13+
if #available(iOS 17.0, macOS 14.0, watchOS 10.0, *) {
1414
self
1515
//iOS17~
1616
.onChange(of: value) { oldValue, newValue in

Sources/RichEditorSwiftUI/UI/TextViewUI/RichTextView+Config_UIKit.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by Divyesh Vekariya on 21/10/24.
66
//
77

8-
#if canImport(UIKit) || os(tvOS) || os(visionOS)
8+
#if iOS || os(tvOS) || os(visionOS)
99
import SwiftUI
1010

1111
public extension RichTextView {

0 commit comments

Comments
 (0)