Skip to content

Commit

Permalink
Support tvos
Browse files Browse the repository at this point in the history
  • Loading branch information
lkzhao committed Apr 7, 2023
1 parent 62186de commit d351dde
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import PackageDescription
let package = Package(
name: "UIComponent",
platforms: [
.iOS("13.0")
.iOS("13.0"),
.tvOS("15.0")
],
products: [
.library(
Expand Down
2 changes: 2 additions & 0 deletions Sources/UIComponent/Components/View/PrimaryMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import UIKit

#if !os(tvOS)
@available(iOS 14.0, *)
public struct PrimaryMenuComponent: ViewComponent {
let component: Component
Expand Down Expand Up @@ -163,3 +164,4 @@ extension PrimaryMenu: UIPointerInteractionDelegate {
return UIPointerStyle(effect: .automatic(UITargetedPreview(view: contentView)), shape: nil)
}
}
#endif
8 changes: 8 additions & 0 deletions Sources/UIComponent/Components/View/TappableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ open class TappableView: ComponentView {
$0.numberOfTapsRequired = 2
}
public private(set) lazy var longPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(didLongPress))
#if !os(tvOS)
public private(set) lazy var contextMenuInteraction = UIContextMenuInteraction(delegate: self)
#endif

public var previewBackgroundColor: UIColor?
public var onTap: ((TappableView) -> Void)? {
Expand Down Expand Up @@ -59,6 +61,7 @@ open class TappableView: ComponentView {
}
}

#if !os(tvOS)
private var dropInteraction: UIDropInteraction?
public weak var dropDelegate: UIDropInteractionDelegate? {
didSet {
Expand Down Expand Up @@ -102,6 +105,7 @@ open class TappableView: ComponentView {
get { _pointerStyleProvider as? () -> UIPointerStyle? }
set { _pointerStyleProvider = newValue }
}
#endif

open var isHighlighted: Bool = false {
didSet {
Expand All @@ -114,9 +118,11 @@ open class TappableView: ComponentView {
public override init(frame: CGRect) {
super.init(frame: frame)
accessibilityTraits = .button
#if !os(tvOS)
if #available(iOS 13.4, *) {
addInteraction(UIPointerInteraction(delegate: self))
}
#endif
}

required public init?(coder: NSCoder) {
Expand Down Expand Up @@ -153,6 +159,7 @@ open class TappableView: ComponentView {
}
}

#if !os(tvOS)
@available(iOS 13.4, *)
extension TappableView: UIPointerInteractionDelegate {
public func pointerInteraction(_ interaction: UIPointerInteraction, styleFor region: UIPointerRegion) -> UIPointerStyle? {
Expand Down Expand Up @@ -206,6 +213,7 @@ extension TappableView: UIContextMenuInteractionDelegate {
}
}
}
#endif

extension Component {
public func tappableView(
Expand Down
6 changes: 6 additions & 0 deletions Sources/UIComponent/Components/View/Text.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

import UIKit

#if os(tvOS)
extension UIFont {
public static let systemFontSize: Double = 16.0
}
#endif

public struct Text: ViewComponent {
public let attributedString: NSAttributedString
public let numberOfLines: Int
Expand Down

0 comments on commit d351dde

Please sign in to comment.