Skip to content

Commit c23dbc6

Browse files
committed
Resolve tvOS related issues appearing in interface builder without tvOS support
1 parent 9f667de commit c23dbc6

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

Sources/Component/Action/ActionView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public final class ActionView<ContentView: StatefulViewProtocol>: StatefulView<A
5050

5151
button.layer.cornerRadius = view.layer.cornerRadius
5252

53-
if #available(iOS 11.0, *) {
53+
if #available(iOS 11.0, tvOS 11.0, *) {
5454
button.layer.maskedCorners = view.layer.maskedCorners
5555
}
5656
}

Sources/Component/Image/ImageView.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ public final class ImageView: StatefulView<Image> {
1414
private typealias ImageCallback = (UIImage) -> Void
1515

1616
private lazy var imageView: UIImageView = .init(frame: .zero)
17-
private lazy var activityIndicator: UIActivityIndicatorView = .init(style: .gray)
17+
private lazy var activityIndicator: UIActivityIndicatorView = .init(
18+
style: Self.defaultActivityIndicatorStyle()
19+
)
1820

1921
private var errorCallback: ErrorCallback?
2022

@@ -86,3 +88,13 @@ public final class ImageView: StatefulView<Image> {
8688
}.resume()
8789
}
8890
}
91+
92+
extension ImageView {
93+
private static func defaultActivityIndicatorStyle() -> UIActivityIndicatorView.Style {
94+
#if os(tvOS)
95+
return .white
96+
#else
97+
return .gray
98+
#endif
99+
}
100+
}

Sources/Container/Scroll/ScrollViewController.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ import UIKit
33

44
/// A container view controller that adds a scroll behaviour to its embedded content.
55
public final class ScrollViewController: ViewController {
6+
#if os(iOS)
67
public override var childForStatusBarStyle: UIViewController? { return contentViewController }
8+
79
public override var childForStatusBarHidden: UIViewController? { return contentViewController }
10+
#endif
11+
812
public override var navigationItem: UINavigationItem { return contentViewController.navigationItem }
913

1014
private var isContentViewBeingPresented: Bool = false
@@ -73,7 +77,7 @@ public final class ScrollViewController: ViewController {
7377
contentViewController.view.trailingAnchor.constraint(equalTo: contentView.trailingAnchor).isActive = true
7478
contentViewController.view.bottomAnchor.constraint(equalTo: contentView.bottomAnchor).isActive = true
7579

76-
if #available(iOS 11.0, *) {
80+
if #available(iOS 11.0, tvOS 11.0, *) {
7781
contentViewHeightConstraint = contentViewController.view.heightAnchor.constraint(
7882
greaterThanOrEqualTo: scrollView.safeAreaLayoutGuide.heightAnchor
7983
)
@@ -107,6 +111,8 @@ public final class ScrollViewController: ViewController {
107111
self.title = viewController.title
108112
}
109113
)
114+
115+
#if os(iOS)
110116
NotificationCenter.default.addObserver(
111117
self,
112118
selector: #selector(updateContentInsetForKeyboard(_:)),
@@ -119,6 +125,7 @@ public final class ScrollViewController: ViewController {
119125
name: UIResponder.keyboardWillChangeFrameNotification,
120126
object: nil
121127
)
128+
#endif
122129
}
123130

124131
private func removeObservers() {
@@ -129,16 +136,19 @@ public final class ScrollViewController: ViewController {
129136

130137
@objc
131138
private func updateContentInsetForKeyboard(_ notification: Notification) {
139+
#if os(iOS)
132140
if notification.name == UIResponder.keyboardWillHideNotification {
133141
scrollView.contentInset = .zero
134142
} else if let keyboardFrameValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue {
135143
let keyboardFrame = view.convert(keyboardFrameValue.cgRectValue, from: view.window)
136-
if #available(iOS 11.0, *) {
144+
145+
if #available(iOS 11.0, tvOS 11.0, *) {
137146
scrollView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: keyboardFrame.height - view.safeAreaInsets.bottom, right: 0)
138147
} else {
139148
scrollView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: keyboardFrame.height - view.layoutMargins.bottom, right: 0)
140149
}
141150
}
151+
#endif
142152

143153
scrollView.scrollIndicatorInsets = scrollView.contentInset
144154
}

0 commit comments

Comments
 (0)