Skip to content

visionOS support #14

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 2 commits into
base: master
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
6 changes: 6 additions & 0 deletions Example/ContainerControllerSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1309,8 +1309,11 @@
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = mrustaa.ContainerController;
PRODUCT_NAME = ContainerController;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator xros xrsimulator";
SUPPORTS_MACCATALYST = NO;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,7";
};
name = Debug;
};
Expand All @@ -1325,8 +1328,11 @@
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = mrustaa.ContainerController;
PRODUCT_NAME = ContainerController;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator xros xrsimulator";
SUPPORTS_MACCATALYST = NO;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,7";
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ public extension UIView {

// MARK: - Private Methods
fileprivate func _pixelIntegral(_ pointValue: CGFloat) -> CGFloat {
#if os(iOS)
let scale = UIScreen.main.scale
return (round(pointValue * scale) / scale)
#else
return pointValue
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ class MapViewManager: NSObject {
self.locationManager = CLLocationManager()
self.locationManager?.delegate = self
self.locationManager?.desiredAccuracy = kCLLocationAccuracyBest
#if os(iOS)
self.locationManager?.requestAlwaysAuthorization()
#endif
self.locationManager?.startUpdatingLocation()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ class MapsViewController: StoryboardController, MapsContainerControllerDelegate,
override func viewDidLoad() {
super.viewDidLoad()

#if os(iOS)
NotificationCenter.default.addObserver(self, selector: #selector(rotated), name: UIDevice.orientationDidChangeNotification, object: nil)
#endif

updateMapManager()

Expand All @@ -61,7 +63,9 @@ class MapsViewController: StoryboardController, MapsContainerControllerDelegate,

navigationController?.navigationBar.isTranslucent = false

#if os(iOS)
setNeedsStatusBarAppearanceUpdate()
#endif

navBar(hide: true)
if !showOnce {
Expand Down Expand Up @@ -105,12 +109,14 @@ class MapsViewController: StoryboardController, MapsContainerControllerDelegate,

// MARK: - Rotation Callback

#if os(iOS)
@objc func rotated() {

if !UIDevice.current.orientation.isRotateAllowed { return }

updateMapViewTopPadding()
}
#endif

func updateMapViewTopPadding() {

Expand Down Expand Up @@ -328,7 +334,9 @@ class MapsViewController: StoryboardController, MapsContainerControllerDelegate,
let style: UIBlurEffect.Style = darkStyle ? .systemUltraThinMaterialDark : .regular
statusBlur.effect = UIBlurEffect(style: style)

#if os(iOS)
setNeedsStatusBarAppearanceUpdate()
#endif
}

// MARK: - Show Maps-Container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ class HeaderSearchBarView: XibView {
searchBar.placeholder = _L("LNG_MAPS_SEARCH_PLACE_ADDRESS")

let textFieldInsideSearchBar = searchBar.value(forKey: "searchField") as? UITextField
let imageV = textFieldInsideSearchBar?.leftView as! UIImageView
imageV.image = imageV.image?.withRenderingMode(UIImage.RenderingMode.alwaysTemplate)
// imageV.image = imageV.image?.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
imageV.tintColor = Colors.rgb(128, 128, 128)
if let imageV = textFieldInsideSearchBar?.leftView as? UIImageView
{
imageV.image = imageV.image?.withRenderingMode(UIImage.RenderingMode.alwaysTemplate)
// imageV.image = imageV.image?.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
imageV.tintColor = Colors.rgb(128, 128, 128)
}
}

func set(darkStyle: Bool) {
Expand Down
16 changes: 12 additions & 4 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Sources/ContainerController/ContainerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ open class ContainerController: NSObject {
self.controller = controller
set(layout: layout)

#if os(iOS)
NotificationCenter.default.addObserver(self, selector: #selector(rotated), name: UIDevice.orientationDidChangeNotification, object: nil)
#endif

createShadowButton()
createContainerView()
Expand Down Expand Up @@ -209,6 +211,7 @@ open class ContainerController: NSObject {

// MARK: - Rotated

#if os(iOS)
@objc func rotated() {

if !UIDevice.current.orientation.isRotateAllowed { return }
Expand All @@ -225,6 +228,7 @@ open class ContainerController: NSObject {

move(type: moveType, from: .rotation)
}
#endif

// MARK: - Update Layout

Expand Down
26 changes: 23 additions & 3 deletions Sources/ContainerController/ContainerDevice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,20 @@ open class ContainerDevice {

// MARK: - Size

class public var width: CGFloat { UIScreen.main.bounds.size.width }
class public var height: CGFloat { UIScreen.main.bounds.size.height }
class public var width: CGFloat {
#if os(iOS)
UIScreen.main.bounds.size.width
#else
UIApplication.shared.connectedScenes.compactMap { ($0 as? UIWindowScene)?.keyWindow }.last?.bounds.size.width ?? 0
#endif
}
class public var height: CGFloat {
#if os(iOS)
UIScreen.main.bounds.size.height
#else
UIApplication.shared.connectedScenes.compactMap { ($0 as? UIWindowScene)?.keyWindow }.last?.bounds.size.height ?? 0
#endif
}

class public var frame: CGRect { CGRect(x: 0, y: 0, width: width, height: height) }

Expand All @@ -36,7 +48,13 @@ open class ContainerDevice {

static public let isIpad = UIDevice.current.userInterfaceIdiom == .pad
static public let isIphone = UIDevice.current.userInterfaceIdiom == .phone
static public let isRetina = UIScreen.main.scale >= 2.0
static public let isRetina = {
#if os(iOS)
UIScreen.main.scale >= 2.0
#else
true
#endif
}

class public var isIphone4: Bool { (isIphone && screenMax < 568.0) }
class public var isIphone5: Bool { (isIphone && screenMax == 568.0) } // SE
Expand Down Expand Up @@ -74,6 +92,7 @@ open class ContainerDevice {

var portrait: Bool = false

#if os(iOS)
let size: CGSize = UIScreen.main.bounds.size
if size.width / size.height > 1 {
portrait = false
Expand All @@ -88,6 +107,7 @@ open class ContainerDevice {
portrait = true
default: break
}
#endif

return portrait
}
Expand Down