-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve CodeText usability and performance
- Loading branch information
Showing
9 changed files
with
272 additions
and
164 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import SwiftUI | ||
|
||
struct CodeTextCardView: View { | ||
let style: CardCodeTextStyle | ||
let color: Color? | ||
|
||
var body: some View { | ||
ZStack { | ||
if let color { | ||
RoundedRectangle(cornerRadius: style.cornerRadius, style: style.cornerStyle) | ||
.fill(color) | ||
} | ||
RoundedRectangle(cornerRadius: style.cornerRadius, style: style.cornerStyle) | ||
.stroke(AnyShapeStyle(style.stroke), lineWidth: style.lineWidth) | ||
} | ||
} | ||
} |
File renamed without changes.
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,53 @@ | ||
@available(iOS 16.1, tvOS 16.1, *) | ||
extension CodeText { | ||
/// Sets the code text style for this code text. | ||
public func codeTextStyle<S>(_ style: S) -> CodeText where S : CodeTextStyle { | ||
var content = self | ||
content.style = style | ||
return content | ||
} | ||
|
||
/// Sets the highlight color theme for this code text. | ||
public func codeTextColors(_ colors: CodeTextColors) -> CodeText { | ||
var content = self | ||
content.colors = colors | ||
return content | ||
} | ||
|
||
/// Sets the language detection mode for this code text. | ||
/// See also `highlightLanguage(_:)` to simply set a language. | ||
public func highlightMode(_ mode: HighlightMode) -> CodeText { | ||
var content = self | ||
content.mode = mode | ||
return content | ||
} | ||
|
||
/// Sets the language for this code text. | ||
/// Equivalent to `.highlightMode(.language(...))` | ||
public func highlightLanguage(_ language: HighlightLanguage) -> CodeText { | ||
var content = self | ||
content.mode = .language(language) | ||
return content | ||
} | ||
|
||
/// Adds an action to perform after the text has been highlighted or an error occurs. | ||
public func onHighlightResult(_ perform: @escaping ((Result<HighlightResult, Error>) -> Void)) -> CodeText { | ||
var content = self | ||
content.result = perform | ||
return content | ||
} | ||
|
||
/// Adds an action to perform if an error occurs while highlighting. | ||
public func onHighlightFailure(_ perform: @escaping ((Error) -> Void)) -> CodeText { | ||
var content = self | ||
content.failure = perform | ||
return content | ||
} | ||
|
||
/// Adds an action to perform after the text has been highlighted. | ||
public func onHighlightSuccess(_ perform: @escaping ((HighlightResult) -> Void)) -> CodeText { | ||
var content = self | ||
content.success = perform | ||
return content | ||
} | ||
} |
Oops, something went wrong.