Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

jobs:
build:
name: Build (${{ matrix.name }})
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
include:
- name: macOS
destination: "platform=macOS"
- name: iOS
destination: "generic/platform=iOS"
- name: Mac Catalyst
destination: "generic/platform=macOS,variant=Mac Catalyst"

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest

- name: Build
run: |
xcodebuild build \
-scheme RichText \
-destination "${{ matrix.destination }}"
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extension AttributeContainer {
mergePolicy: AttributedString.AttributeMergePolicy = .keepNew,
perform transform: (NSMutableParagraphStyle) -> Void
) {
#if canImport(AppKit)
#if os(macOS)
let paragraphStyle = self[keyPath: \.appKit.paragraphStyle] ?? .init()
#elseif canImport(UIKit)
let paragraphStyle = self[keyPath: \.uiKit.paragraphStyle] ?? .init()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final public class InlineHostingAttachment: NSTextAttachment {
var rootView: AnyView
var sizing: HostedAttachmentSizing

#if canImport(AppKit)
#if os(macOS)
private var hostingController: NSHostingController<AnyView>?
#endif

Expand Down Expand Up @@ -167,7 +167,7 @@ final public class InlineHostingAttachment: NSTextAttachment {

@MainActor
lazy var hostingView: PlatformView = {
#if canImport(AppKit)
#if os(macOS)
let hostingController = NSHostingController(rootView: hostingRootView)
hostingController.sizingOptions = .intrinsicContentSize
self.hostingController = hostingController
Expand All @@ -190,7 +190,7 @@ final public class InlineHostingAttachment: NSTextAttachment {
self.replacement = attachment.replacement
self.sizing = attachment.sizing

#if canImport(AppKit)
#if os(macOS)
hostingController?.rootView = hostingRootView
#elseif canImport(UIKit)
hostingController?.rootView = hostingRootView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

extension AttributeScopes {
struct RichTextAttributes : AttributeScope {
#if canImport(AppKit)
#if os(macOS)
let appKit: AttributeScopes.AppKitAttributes
#else
let uiKit: AttributeScopes.UIKitAttributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Yanan Li on 2026/6/20.
//

#if canImport(AppKit)
#if os(macOS)

import AppKit

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extension InlineAttachmentTextView {
cachedContentHeight = nil
invalidateIntrinsicContentSize()

#if canImport(AppKit)
#if os(macOS)
needsLayout = true
setNeedsDisplay(bounds)
#elseif canImport(UIKit)
Expand Down
4 changes: 2 additions & 2 deletions Sources/RichText/Text View/InlineAttachmentTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ fileprivate extension NSMutableAttributedString {
options: []
) { attrs, range, _ in
if attrs[.foregroundColor] == nil {
#if canImport(AppKit)
#if os(macOS)
addAttribute(.foregroundColor, value: NSColor.labelColor, range: range)
#elseif canImport(UIKit)
addAttribute(.foregroundColor, value: UIColor.label, range: range)
Expand All @@ -170,7 +170,7 @@ fileprivate extension NSMutableAttributedString {

func _fixFont(_ font: PlatformFont?, in range: NSRange) {
let font: PlatformFont = font ?? {
#if canImport(AppKit)
#if os(macOS)
return NSFont.systemFont(ofSize: NSFont.systemFontSize)
#elseif canImport(UIKit)
return UIFont.preferredFont(forTextStyle: .body)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import CoreText
import SwiftUI

#if canImport(AppKit)
#if os(macOS)
typealias ViewRepresentable = NSViewRepresentable
typealias RepresentableContext = NSViewRepresentableContext
typealias PlatformColor = NSColor
Expand Down Expand Up @@ -126,7 +126,7 @@ enum TextAttributeConverter {

var attributes = AttributeContainer()
if intent.contains(.strikethrough) {
#if canImport(AppKit)
#if os(macOS)
attributes.appKit.strikethroughStyle = .single
#elseif canImport(UIKit)
attributes.uiKit.strikethroughStyle = .single
Expand All @@ -151,7 +151,7 @@ enum TextAttributeConverter {
_ textView: PlatformTextView,
configuration: TextViewRenderConfiguration
) {
#if canImport(AppKit)
#if os(macOS)
textView.baseWritingDirection = NSWritingDirection(configuration.layoutDirection)
textView.alignment = NSTextAlignment(
configuration.multilineTextAlignment,
Expand Down
2 changes: 1 addition & 1 deletion Sources/RichText/Text View/SwiftUI/_TextView_AppKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Yanan Li on 2025/8/24.
//

#if canImport(AppKit)
#if os(macOS)
import SwiftUI

struct _TextView_AppKit: NSViewRepresentable {
Expand Down
2 changes: 1 addition & 1 deletion Sources/RichText/TextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public struct TextView: View {
}

public var body: some View {
#if canImport(AppKit)
#if os(macOS)
_TextView_AppKit(content: content)
#elseif canImport(UIKit)
_TextView_UIKit(content: content)
Expand Down