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

Commit

Permalink
Fix watchOS builds
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzalezreal committed Dec 20, 2020
1 parent b3a8994 commit 041f5b2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .spi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: 1
builder:
configs:
- platform: watchos
scheme: AttributedText_watchOS
18 changes: 11 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
DESTINATION_MAC = platform=macOS
DESTINATION_IOS = platform=iOS Simulator,name=iPhone 8
DESTINATION_TVOS = platform=tvOS Simulator,name=Apple TV
DESTINATION_IOS = generic/platform=ios
DESTINATION_TVOS = generic/platform=tvos
DESTINATION_WATCHOS = generic/platform=watchOS

default: test
default: build

test:
xcodebuild test \
build:
xcodebuild \
-scheme AttributedText \
-destination '$(DESTINATION_MAC)'
xcodebuild test \
xcodebuild \
-scheme AttributedText \
-destination '$(DESTINATION_IOS)'
xcodebuild test \
xcodebuild \
-scheme AttributedText \
-destination '$(DESTINATION_TVOS)'
xcodebuild \
-scheme AttributedText_watchOS \
-destination '$(DESTINATION_WATCHOS)'

format:
swiftformat .
Expand Down
34 changes: 19 additions & 15 deletions Sources/AttributedText/NSAttributedString+TextAttachment.swift
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
#if os(macOS)
import AppKit
#elseif canImport(UIKit)
import UIKit
#endif
#if !os(watchOS)

#if os(macOS)
import AppKit
#elseif canImport(UIKit)
import UIKit
#endif

extension NSAttributedString {
func updateImageTextAttachments(maxWidth: CGFloat) {
enumerateAttribute(.attachment, in: NSRange(location: 0, length: length), options: []) { value, _, _ in
guard let attachment = value as? NSTextAttachment,
let image = attachment.image else { return }
extension NSAttributedString {
func updateImageTextAttachments(maxWidth: CGFloat) {
enumerateAttribute(.attachment, in: NSRange(location: 0, length: length), options: []) { value, _, _ in
guard let attachment = value as? NSTextAttachment,
let image = attachment.image else { return }

let aspectRatio = image.size.width / image.size.height
let width = min(maxWidth, image.size.width)
let height = width / aspectRatio
let aspectRatio = image.size.width / image.size.height
let width = min(maxWidth, image.size.width)
let height = width / aspectRatio

attachment.bounds = CGRect(x: 0, y: 0, width: width, height: height)
attachment.bounds = CGRect(x: 0, y: 0, width: width, height: height)
}
}
}
}

#endif

0 comments on commit 041f5b2

Please sign in to comment.