Skip to content

Commit

Permalink
Merge pull request #146 from danielsaidi/feature/theme
Browse files Browse the repository at this point in the history
[FEATURE] Add Theme to RichTextEditor init
  • Loading branch information
danielsaidi authored Mar 4, 2024
2 parents c1fe086 + 13c6219 commit 193727f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 5 additions & 0 deletions Sources/RichTextKit/RichTextEditor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ public struct RichTextEditor: ViewRepresentable {
text: Binding<NSAttributedString>,
context: RichTextContext,
config: RichTextView.Configuration = .standard,
theme: RichTextView.Theme = .standard,
format: RichTextDataFormat = .archivedData,
viewConfiguration: @escaping ViewConfiguration = { _ in }
) {
self.text = text
self.config = config
self.theme = theme
self._context = ObservedObject(wrappedValue: context)
self.format = format
self.viewConfiguration = viewConfiguration
Expand All @@ -74,6 +76,7 @@ public struct RichTextEditor: ViewRepresentable {

private var text: Binding<NSAttributedString>
private let config: RichTextView.Configuration
private let theme: RichTextView.Theme
private var format: RichTextDataFormat
private var viewConfiguration: ViewConfiguration

Expand Down Expand Up @@ -101,6 +104,7 @@ public struct RichTextEditor: ViewRepresentable {
public func makeUIView(context: Context) -> some UIView {
textView.setup(with: text.wrappedValue, format: format)
textView.configuration = config
textView.theme = theme
viewConfiguration(textView)
return textView
}
Expand All @@ -112,6 +116,7 @@ public struct RichTextEditor: ViewRepresentable {
public func makeNSView(context: Context) -> some NSView {
textView.setup(with: text.wrappedValue, format: format)
textView.configuration = config
textView.theme = theme
viewConfiguration(textView)
return scrollView
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,13 @@ final class RichTextCoordinatorIntegrationTests: XCTestCase {

textView.simulateTyping(of: firstTypingPart)

let attributes = textView.richTextAttributes

textContext.selectRange(NSRange(location: Self.initialAttributedString.length, length: firstTypingPart.count))
XCTAssertEqual(attributes[.font] as? FontRepresentable, FontRepresentable.systemFont(ofSize: 16))
XCTAssertEqual(attributes[.foregroundColor] as? ColorRepresentable, ColorRepresentable.red)
XCTAssertEqual(textView.richTextAttributes[.font] as? FontRepresentable, FontRepresentable.systemFont(ofSize: 16))
XCTAssertEqual(textView.richTextAttributes[.foregroundColor] as? ColorRepresentable, ColorRepresentable.red)

textView.setRichTextStyle(.strikethrough, to: true)
XCTAssertEqual(attributes[.strikethroughStyle] as? Int, 1)
XCTAssertEqual(textView.richTextAttributes[.strikethroughStyle] as? Int, 1)
}
}
#endif

0 comments on commit 193727f

Please sign in to comment.