diff --git a/.spi.yml b/.spi.yml deleted file mode 100644 index 8d77fb6..0000000 --- a/.spi.yml +++ /dev/null @@ -1,5 +0,0 @@ -version: 1 -builder: - configs: - - platform: watchos - scheme: AttributedText_watchOS diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/AttributedText_watchOS.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/AttributedText_watchOS.xcscheme deleted file mode 100644 index 32040fc..0000000 --- a/.swiftpm/xcode/xcshareddata/xcschemes/AttributedText_watchOS.xcscheme +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Makefile b/Makefile index 3e16751..47b761d 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,6 @@ DESTINATION_MAC = platform=macOS DESTINATION_IOS = platform=iOS Simulator,name=iPhone 8 DESTINATION_TVOS = platform=tvOS Simulator,name=Apple TV -DESTINATION_WATCHOS = generic/platform=watchOS default: test @@ -15,9 +14,6 @@ test: xcodebuild test \ -scheme AttributedText \ -destination '$(DESTINATION_TVOS)' - xcodebuild \ - -scheme AttributedText_watchOS \ - -destination '$(DESTINATION_WATCHOS)' format: swift format --in-place --recursive . diff --git a/Sources/AttributedText/AttributedText.swift b/Sources/AttributedText/AttributedText.swift index 5cee25a..15513e1 100644 --- a/Sources/AttributedText/AttributedText.swift +++ b/Sources/AttributedText/AttributedText.swift @@ -1,52 +1,50 @@ -#if !os(watchOS) - import SwiftUI +import SwiftUI - /// A view that displays styled attributed text. - public struct AttributedText: View { - @StateObject private var textSizeViewModel = TextSizeViewModel() +/// A view that displays styled attributed text. +public struct AttributedText: View { + @StateObject private var textSizeViewModel = TextSizeViewModel() - private let attributedText: NSAttributedString - private let onOpenLink: ((URL) -> Void)? + private let attributedText: NSAttributedString + private let onOpenLink: ((URL) -> Void)? - /// Creates an attributed text view. - /// - Parameters: - /// - attributedText: An attributed string to display. - /// - onOpenLink: The action to perform when the user opens a link in the text. When not specified, - /// the view opens the links using the `OpenURLAction` from the environment. - public init(_ attributedText: NSAttributedString, onOpenLink: ((URL) -> Void)? = nil) { - self.attributedText = attributedText - self.onOpenLink = onOpenLink - } + /// Creates an attributed text view. + /// - Parameters: + /// - attributedText: An attributed string to display. + /// - onOpenLink: The action to perform when the user opens a link in the text. When not specified, + /// the view opens the links using the `OpenURLAction` from the environment. + public init(_ attributedText: NSAttributedString, onOpenLink: ((URL) -> Void)? = nil) { + self.attributedText = attributedText + self.onOpenLink = onOpenLink + } - /// Creates an attributed text view. - /// - Parameters: - /// - attributedText: A closure that creates the attributed string to display. - /// - onOpenLink: The action to perform when the user opens a link in the text. When not specified, - /// the view opens the links using the `OpenURLAction` from the environment. - public init(attributedText: () -> NSAttributedString, onOpenLink: ((URL) -> Void)? = nil) { - self.init(attributedText(), onOpenLink: onOpenLink) - } + /// Creates an attributed text view. + /// - Parameters: + /// - attributedText: A closure that creates the attributed string to display. + /// - onOpenLink: The action to perform when the user opens a link in the text. When not specified, + /// the view opens the links using the `OpenURLAction` from the environment. + public init(attributedText: () -> NSAttributedString, onOpenLink: ((URL) -> Void)? = nil) { + self.init(attributedText(), onOpenLink: onOpenLink) + } - public var body: some View { - GeometryReader { geometry in - AttributedTextImpl( - attributedText: attributedText, - maxLayoutWidth: geometry.maxWidth, - textSizeViewModel: textSizeViewModel, - onOpenLink: onOpenLink - ) - } - .frame( - idealWidth: textSizeViewModel.textSize?.width, - idealHeight: textSizeViewModel.textSize?.height + public var body: some View { + GeometryReader { geometry in + AttributedTextImpl( + attributedText: attributedText, + maxLayoutWidth: geometry.maxWidth, + textSizeViewModel: textSizeViewModel, + onOpenLink: onOpenLink ) - .fixedSize(horizontal: false, vertical: true) } + .frame( + idealWidth: textSizeViewModel.textSize?.width, + idealHeight: textSizeViewModel.textSize?.height + ) + .fixedSize(horizontal: false, vertical: true) } +} - extension GeometryProxy { - fileprivate var maxWidth: CGFloat { - size.width - safeAreaInsets.leading - safeAreaInsets.trailing - } +extension GeometryProxy { + fileprivate var maxWidth: CGFloat { + size.width - safeAreaInsets.leading - safeAreaInsets.trailing } -#endif +} diff --git a/Sources/AttributedText/AttributedTextImpl+UIKit.swift b/Sources/AttributedText/AttributedTextImpl+UIKit.swift index 905241f..969c95e 100644 --- a/Sources/AttributedText/AttributedTextImpl+UIKit.swift +++ b/Sources/AttributedText/AttributedTextImpl+UIKit.swift @@ -1,4 +1,4 @@ -#if canImport(UIKit) && !os(watchOS) +#if canImport(UIKit) import SwiftUI extension AttributedTextImpl: UIViewRepresentable { diff --git a/Sources/AttributedText/AttributedTextImpl.swift b/Sources/AttributedText/AttributedTextImpl.swift index f337acc..9d4fce9 100644 --- a/Sources/AttributedText/AttributedTextImpl.swift +++ b/Sources/AttributedText/AttributedTextImpl.swift @@ -1,10 +1,8 @@ -#if !os(watchOS) - import SwiftUI +import SwiftUI - struct AttributedTextImpl { - var attributedText: NSAttributedString - var maxLayoutWidth: CGFloat - var textSizeViewModel: TextSizeViewModel - var onOpenLink: ((URL) -> Void)? - } -#endif +struct AttributedTextImpl { + var attributedText: NSAttributedString + var maxLayoutWidth: CGFloat + var textSizeViewModel: TextSizeViewModel + var onOpenLink: ((URL) -> Void)? +} diff --git a/Sources/AttributedText/NSLineBreakMode+TruncationMode.swift b/Sources/AttributedText/NSLineBreakMode+TruncationMode.swift index 8e59441..b02f4e4 100644 --- a/Sources/AttributedText/NSLineBreakMode+TruncationMode.swift +++ b/Sources/AttributedText/NSLineBreakMode+TruncationMode.swift @@ -1,18 +1,16 @@ -#if !os(watchOS) - import SwiftUI +import SwiftUI - extension NSLineBreakMode { - init(truncationMode: Text.TruncationMode) { - switch truncationMode { - case .head: - self = .byTruncatingHead - case .tail: - self = .byTruncatingTail - case .middle: - self = .byTruncatingMiddle - @unknown default: - self = .byWordWrapping - } +extension NSLineBreakMode { + init(truncationMode: Text.TruncationMode) { + switch truncationMode { + case .head: + self = .byTruncatingHead + case .tail: + self = .byTruncatingTail + case .middle: + self = .byTruncatingMiddle + @unknown default: + self = .byWordWrapping } } -#endif +} diff --git a/Sources/AttributedText/TextSizeViewModel.swift b/Sources/AttributedText/TextSizeViewModel.swift index 11f8151..8f2dc62 100644 --- a/Sources/AttributedText/TextSizeViewModel.swift +++ b/Sources/AttributedText/TextSizeViewModel.swift @@ -1,11 +1,9 @@ -#if !os(watchOS) - import SwiftUI +import SwiftUI - final class TextSizeViewModel: ObservableObject { - @Published var textSize: CGSize? +final class TextSizeViewModel: ObservableObject { + @Published var textSize: CGSize? - func didUpdateTextView(_ textView: AttributedTextImpl.TextView) { - textSize = textView.intrinsicContentSize - } + func didUpdateTextView(_ textView: AttributedTextImpl.TextView) { + textSize = textView.intrinsicContentSize } -#endif +}