-
-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE] Extend configuration #141
Changes from 6 commits
7a1b1ef
6e4f9cf
6e24d66
cfef0f2
9f6b34e
84d93e6
ffcdd5c
3f3269c
da7f863
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,13 @@ | ||
// | ||
// RichTextView+Config.swift | ||
// RichTextKit | ||
// | ||
// Created by Daniel Saidi on 2024-01-16. | ||
// Copyright © 2024 Daniel Saidi. All rights reserved. | ||
// | ||
// Created by Dominik Bucher on 13.02.2024. | ||
// | ||
|
||
#if iOS || macOS || os(tvOS) || os(visionOS) | ||
import SwiftUI | ||
|
||
public extension RichTextView { | ||
|
||
/** | ||
This type can be used to configure a ``RichTextEditor``. | ||
*/ | ||
struct Configuration { | ||
|
||
/** | ||
Create a custom configuration. | ||
|
||
- Parameters: | ||
- isScrollingEnabled: Whether or not the editor should scroll, by default `true`. | ||
*/ | ||
public init( | ||
isScrollingEnabled: Bool = true | ||
) { | ||
self.isScrollingEnabled = isScrollingEnabled | ||
} | ||
|
||
/// Whether or not the editor should scroll. | ||
public var isScrollingEnabled: Bool | ||
} | ||
} | ||
import Foundation | ||
|
||
public extension RichTextView.Configuration { | ||
|
||
/// Get a standard rich text editor configuration. | ||
static var standard: Self { .init() } | ||
} | ||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// RichTextView+Config_AppKit.swift | ||
// | ||
// | ||
// Created by Dominik Bucher on 13.02.2024. | ||
// | ||
|
||
#if macOS | ||
import Foundation | ||
|
||
public extension RichTextView { | ||
|
||
/** | ||
This type can be used to configure a ``RichTextEditor``. | ||
*/ | ||
struct Configuration { | ||
|
||
/// Create a custom configuration | ||
/// - Parameters: | ||
/// - isScrollingEnabled: Whether or not the editor should scroll, by default `true`. | ||
/// - isContinuousSpellCheckingEnabled: Whether the editor spell-checks in realtime. Defaults to `true`. | ||
public init( | ||
isScrollingEnabled: Bool = true, | ||
isContinuousSpellCheckingEnabled: Bool = true | ||
) { | ||
self.isScrollingEnabled = isScrollingEnabled | ||
self.isContinuousSpellCheckingEnabled = isContinuousSpellCheckingEnabled | ||
} | ||
|
||
/// Whether or not the editor should scroll. | ||
public var isScrollingEnabled: Bool | ||
/// Whether the editor spell-checks in realtime. | ||
public var isContinuousSpellCheckingEnabled: Bool | ||
} | ||
} | ||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// RichTextView+Config_UIKit.swift | ||
// RichTextKit | ||
// | ||
// Created by Daniel Saidi on 2024-01-16. | ||
// Copyright © 2024 Daniel Saidi. All rights reserved. | ||
// | ||
|
||
#if iOS || os(tvOS) || os(visionOS) | ||
import SwiftUI | ||
|
||
public extension RichTextView { | ||
|
||
/** | ||
This type can be used to configure a ``RichTextEditor``. | ||
*/ | ||
struct Configuration { | ||
|
||
/** | ||
Create a custom configuration. | ||
|
||
- Parameters: | ||
- isScrollingEnabled: Whether or not the editor should scroll, by default `true`. | ||
- allowsEditingTextAttributes: If editor allows editing text attributes, by default `true`. | ||
- autocapitalizationType: Type of Auto capitalization, default is to `.sentences`. | ||
- spellCheckingType: Whether textView spell-Checks, default is `.no`. | ||
*/ | ||
public init( | ||
isScrollingEnabled: Bool = true, | ||
allowsEditingTextAttributes: Bool = true, | ||
autocapitalizationType: UITextAutocapitalizationType = .sentences, | ||
spellCheckingType: UITextSpellCheckingType = .no | ||
) { | ||
self.isScrollingEnabled = isScrollingEnabled | ||
self.allowsEditingTextAttributes = allowsEditingTextAttributes | ||
self.autocapitalizationType = autocapitalizationType | ||
self.spellCheckingType = spellCheckingType | ||
} | ||
|
||
/// Whether or not the editor should scroll. | ||
public var isScrollingEnabled: Bool | ||
/// Whether textView allows editting text attributes | ||
public var allowsEditingTextAttributes: Bool | ||
/// Kind of auto capitalization | ||
public var autocapitalizationType: UITextAutocapitalizationType | ||
/// If TextView spell-checks the text. | ||
public var spellCheckingType: UITextSpellCheckingType | ||
} | ||
} | ||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,9 +45,10 @@ final class RichTextViewComponentTests: XCTestCase { | |
func testSettingUpWithEmptyTextWorks() { | ||
let string = NSAttributedString(string: "") | ||
view.setup(with: string, format: .rtf) | ||
view.configuration = .standard | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This raises question if configuration shouldn't be passed to setup instead... This feels like API is all over the place, your thoughts @danielsaidi ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking we should inject it into the environment in SwiftUI. |
||
XCTAssertEqual(view.richText.string, "") | ||
#if iOS || os(tvOS) | ||
XCTAssertFalse(view.allowsEditingTextAttributes) | ||
XCTAssertTrue(view.allowsEditingTextAttributes) | ||
XCTAssertEqual(view.autocapitalizationType, .sentences) | ||
#endif | ||
XCTAssertEqual(view.backgroundColor, .clear) | ||
|
@@ -63,9 +64,10 @@ final class RichTextViewComponentTests: XCTestCase { | |
func testSettingUpWithNonEmptyTextWorks() { | ||
let string = NSAttributedString(string: "foo bar baz") | ||
view.setup(with: string, format: .rtf) | ||
view.configuration = .standard | ||
XCTAssertEqual(view.richText.string, "foo bar baz") | ||
#if iOS || os(tvOS) | ||
XCTAssertFalse(view.allowsEditingTextAttributes) | ||
XCTAssertTrue(view.allowsEditingTextAttributes) | ||
XCTAssertEqual(view.autocapitalizationType, .sentences) | ||
#endif | ||
XCTAssertEqual(view.backgroundColor, .clear) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can even keep this it is in dependent PR for themes (default text color etc.) Just a note 😅