Skip to content

Resolve tvOS related issues appearing in interface builder #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion Sources/Component/Action/ActionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public final class ActionView<ContentView: StatefulViewProtocol>: StatefulView<A

button.layer.cornerRadius = view.layer.cornerRadius

if #available(iOS 11.0, *) {
if #available(iOS 11.0, tvOS 11.0, *) {
button.layer.maskedCorners = view.layer.maskedCorners
}
}
Expand Down
14 changes: 13 additions & 1 deletion Sources/Component/Image/ImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ public final class ImageView: StatefulView<Image> {
private typealias ImageCallback = (UIImage) -> Void

private lazy var imageView: UIImageView = .init(frame: .zero)
private lazy var activityIndicator: UIActivityIndicatorView = .init(style: .gray)
private lazy var activityIndicator: UIActivityIndicatorView = .init(
style: Self.defaultActivityIndicatorStyle()
)

private var errorCallback: ErrorCallback?

Expand Down Expand Up @@ -86,3 +88,13 @@ public final class ImageView: StatefulView<Image> {
}.resume()
}
}

extension ImageView {
private static func defaultActivityIndicatorStyle() -> UIActivityIndicatorView.Style {
#if os(tvOS)
return .white
#else
return .gray
#endif
}
}
14 changes: 12 additions & 2 deletions Sources/Container/Scroll/ScrollViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ import UIKit

/// A container view controller that adds a scroll behaviour to its embedded content.
public final class ScrollViewController: ViewController {
#if os(iOS)
public override var childForStatusBarStyle: UIViewController? { return contentViewController }

public override var childForStatusBarHidden: UIViewController? { return contentViewController }
#endif

public override var navigationItem: UINavigationItem { return contentViewController.navigationItem }

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

if #available(iOS 11.0, *) {
if #available(iOS 11.0, tvOS 11.0, *) {
contentViewHeightConstraint = contentViewController.view.heightAnchor.constraint(
greaterThanOrEqualTo: scrollView.safeAreaLayoutGuide.heightAnchor
)
Expand Down Expand Up @@ -107,6 +111,8 @@ public final class ScrollViewController: ViewController {
self.title = viewController.title
}
)

#if os(iOS)
NotificationCenter.default.addObserver(
self,
selector: #selector(updateContentInsetForKeyboard(_:)),
Expand All @@ -119,6 +125,7 @@ public final class ScrollViewController: ViewController {
name: UIResponder.keyboardWillChangeFrameNotification,
object: nil
)
#endif
}

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

@objc
private func updateContentInsetForKeyboard(_ notification: Notification) {
#if os(iOS)
if notification.name == UIResponder.keyboardWillHideNotification {
scrollView.contentInset = .zero
} else if let keyboardFrameValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue {
let keyboardFrame = view.convert(keyboardFrameValue.cgRectValue, from: view.window)
if #available(iOS 11.0, *) {

if #available(iOS 11.0, tvOS 11.0, *) {
scrollView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: keyboardFrame.height - view.safeAreaInsets.bottom, right: 0)
} else {
scrollView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: keyboardFrame.height - view.layoutMargins.bottom, right: 0)
}
}
#endif

scrollView.scrollIndicatorInsets = scrollView.contentInset
}
Expand Down