Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Remove watchOS scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzalezreal committed Oct 8, 2021
1 parent 6622cac commit 744dc58
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 151 deletions.
5 changes: 0 additions & 5 deletions .spi.yml

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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 .
Expand Down
82 changes: 40 additions & 42 deletions Sources/AttributedText/AttributedText.swift
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion Sources/AttributedText/AttributedTextImpl+UIKit.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if canImport(UIKit) && !os(watchOS)
#if canImport(UIKit)
import SwiftUI

extension AttributedTextImpl: UIViewRepresentable {
Expand Down
16 changes: 7 additions & 9 deletions Sources/AttributedText/AttributedTextImpl.swift
Original file line number Diff line number Diff line change
@@ -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)?
}
28 changes: 13 additions & 15 deletions Sources/AttributedText/NSLineBreakMode+TruncationMode.swift
Original file line number Diff line number Diff line change
@@ -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
}
14 changes: 6 additions & 8 deletions Sources/AttributedText/TextSizeViewModel.swift
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 744dc58

Please sign in to comment.