-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08ee3b0
commit ff06b04
Showing
4 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
Sources/LiveViewNative/Modifiers/Text Input and Output Modifiers/StrikethroughModifier.swift
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,80 @@ | ||
// | ||
// StrikethroughModifier.swift | ||
// LiveViewNative | ||
// | ||
// Created by Carson Katri on 4/6/2023. | ||
// | ||
|
||
import SwiftUI | ||
|
||
/// Adds a line through ``Text``. | ||
/// | ||
/// The line can be customized with the ``pattern`` and ``color`` arguments. | ||
/// | ||
/// ```html | ||
/// <Text modifiers={strikethrough(@native, color: :red, pattern: :dash_dot)}> | ||
/// Hello, world! | ||
/// </Text> | ||
/// ``` | ||
/// | ||
/// ## Arguments | ||
/// * [`is_active`](doc:StrikethroughModifier/isActive) | ||
/// * ``pattern`` | ||
/// * ``color`` | ||
#if swift(>=5.8) | ||
@_documentation(visibility: public) | ||
#endif | ||
struct StrikethroughModifier: ViewModifier, Decodable { | ||
/// `is_active`, enables/disables the effect. | ||
#if swift(>=5.8) | ||
@_documentation(visibility: public) | ||
#endif | ||
private let isActive: Bool | ||
|
||
/// The pattern to use for the line. Defaults to `solid`. | ||
/// | ||
/// Possible values: | ||
/// * `dash` | ||
/// * `dash_dot` | ||
/// * `dash_dot_dot` | ||
/// * `dot` | ||
/// * `solid` | ||
#if swift(>=5.8) | ||
@_documentation(visibility: public) | ||
#endif | ||
private let pattern: SwiftUI.Text.LineStyle.Pattern | ||
|
||
/// The color of the line. Defaults to `nil`. | ||
/// | ||
/// See ``LiveViewNative/SwiftUI/Color`` for details on creating colors. | ||
#if swift(>=5.8) | ||
@_documentation(visibility: public) | ||
#endif | ||
private let color: SwiftUI.Color? | ||
|
||
init(from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: CodingKeys.self) | ||
|
||
self.isActive = try container.decode(Bool.self, forKey: .isActive) | ||
switch try container.decode(String.self, forKey: .pattern) { | ||
case "dash": self.pattern = .dash | ||
case "dash_dot": self.pattern = .dashDot | ||
case "dash_dot_dot": self.pattern = .dashDotDot | ||
case "dot": self.pattern = .dot | ||
case "solid": self.pattern = .solid | ||
case let `default`: throw DecodingError.dataCorrupted(.init(codingPath: container.codingPath, debugDescription: "unknown pattern '\(`default`)'")) | ||
} | ||
|
||
self.color = try container.decodeIfPresent(SwiftUI.Color.self, forKey: .color) | ||
} | ||
|
||
func body(content: Content) -> some View { | ||
content.strikethrough(isActive, pattern: pattern, color: color) | ||
} | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case isActive = "is_active" | ||
case pattern | ||
case color | ||
} | ||
} |
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,11 @@ | ||
defmodule LiveViewNativeSwiftUi.Modifiers.Strikethrough do | ||
use LiveViewNativePlatform.Modifier | ||
|
||
alias LiveViewNativeSwiftUi.Types.Color | ||
|
||
modifier_schema "strikethrough" do | ||
field :is_active, :boolean, default: true | ||
field :pattern, Ecto.Enum, values: ~w(dash dash_dot dash_dot_dot dot solid)a, default: :solid | ||
field :color, Color | ||
end | ||
end |
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