Skip to content

Commit 24abd7a

Browse files
Merge pull request #8 from codelathe/visionos_support
visionOS support
2 parents 6523567 + e687f18 commit 24abd7a

File tree

8 files changed

+65
-11
lines changed

8 files changed

+65
-11
lines changed

Example/ContainerControllerSwift.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,8 +1309,11 @@
13091309
MODULE_NAME = ExampleApp;
13101310
PRODUCT_BUNDLE_IDENTIFIER = mrustaa.ContainerController;
13111311
PRODUCT_NAME = ContainerController;
1312+
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator xros xrsimulator";
1313+
SUPPORTS_MACCATALYST = NO;
13121314
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
13131315
SWIFT_VERSION = 5.0;
1316+
TARGETED_DEVICE_FAMILY = "1,2,7";
13141317
};
13151318
name = Debug;
13161319
};
@@ -1325,8 +1328,11 @@
13251328
MODULE_NAME = ExampleApp;
13261329
PRODUCT_BUNDLE_IDENTIFIER = mrustaa.ContainerController;
13271330
PRODUCT_NAME = ContainerController;
1331+
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator xros xrsimulator";
1332+
SUPPORTS_MACCATALYST = NO;
13281333
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
13291334
SWIFT_VERSION = 5.0;
1335+
TARGETED_DEVICE_FAMILY = "1,2,7";
13301336
};
13311337
name = Release;
13321338
};

Example/ContainerControllerSwift/Framework/Utils/UIView+Positioning.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,11 @@ public extension UIView {
187187

188188
// MARK: - Private Methods
189189
fileprivate func _pixelIntegral(_ pointValue: CGFloat) -> CGFloat {
190+
#if os(iOS)
190191
let scale = UIScreen.main.scale
191192
return (round(pointValue * scale) / scale)
193+
#else
194+
return pointValue
195+
#endif
192196
}
193197
}

Example/ContainerControllerSwift/Maps/MapManager/MapViewManager.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ class MapViewManager: NSObject {
5050
self.locationManager = CLLocationManager()
5151
self.locationManager?.delegate = self
5252
self.locationManager?.desiredAccuracy = kCLLocationAccuracyBest
53+
#if os(iOS)
5354
self.locationManager?.requestAlwaysAuthorization()
55+
#endif
5456
self.locationManager?.startUpdatingLocation()
5557
}
5658
}

Example/ContainerControllerSwift/Maps/MapsViewController.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ class MapsViewController: StoryboardController, MapsContainerControllerDelegate,
4444
override func viewDidLoad() {
4545
super.viewDidLoad()
4646

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

4951
updateMapManager()
5052

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

6264
navigationController?.navigationBar.isTranslucent = false
6365

66+
#if os(iOS)
6467
setNeedsStatusBarAppearanceUpdate()
68+
#endif
6569

6670
navBar(hide: true)
6771
if !showOnce {
@@ -105,12 +109,14 @@ class MapsViewController: StoryboardController, MapsContainerControllerDelegate,
105109

106110
// MARK: - Rotation Callback
107111

112+
#if os(iOS)
108113
@objc func rotated() {
109114

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

112117
updateMapViewTopPadding()
113118
}
119+
#endif
114120

115121
func updateMapViewTopPadding() {
116122

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

337+
#if os(iOS)
331338
setNeedsStatusBarAppearanceUpdate()
339+
#endif
332340
}
333341

334342
// MARK: - Show Maps-Container

Example/ContainerControllerSwift/Maps/UI/View/Maps/HeaderSearchBarView/HeaderSearchBarView.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ class HeaderSearchBarView: XibView {
2727
searchBar.placeholder = _L("LNG_MAPS_SEARCH_PLACE_ADDRESS")
2828

2929
let textFieldInsideSearchBar = searchBar.value(forKey: "searchField") as? UITextField
30-
let imageV = textFieldInsideSearchBar?.leftView as! UIImageView
31-
imageV.image = imageV.image?.withRenderingMode(UIImage.RenderingMode.alwaysTemplate)
32-
// imageV.image = imageV.image?.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
33-
imageV.tintColor = Colors.rgb(128, 128, 128)
30+
if let imageV = textFieldInsideSearchBar?.leftView as? UIImageView
31+
{
32+
imageV.image = imageV.image?.withRenderingMode(UIImage.RenderingMode.alwaysTemplate)
33+
// imageV.image = imageV.image?.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
34+
imageV.tintColor = Colors.rgb(128, 128, 128)
35+
}
3436
}
3537

3638
func set(darkStyle: Bool) {

Example/Pods/Pods.xcodeproj/project.pbxproj

Lines changed: 12 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/ContainerController/ContainerController.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,9 @@ open class ContainerController: NSObject {
183183
self.controller = controller
184184
set(layout: layout)
185185

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

188190
createShadowButton()
189191
createContainerView()
@@ -214,6 +216,7 @@ open class ContainerController: NSObject {
214216

215217
// MARK: - Rotated
216218

219+
#if os(iOS)
217220
@objc func rotated() {
218221

219222
if !UIDevice.current.orientation.isRotateAllowed { return }
@@ -230,6 +233,7 @@ open class ContainerController: NSObject {
230233

231234
move(type: moveType, from: .rotation)
232235
}
236+
#endif
233237

234238
// MARK: - Update Layout
235239

Sources/ContainerController/ContainerDevice.swift

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,20 @@ open class ContainerDevice {
2323

2424
// MARK: - Size
2525

26-
class public var width: CGFloat { UIScreen.main.bounds.size.width }
27-
class public var height: CGFloat { UIScreen.main.bounds.size.height }
26+
class public var width: CGFloat {
27+
#if os(iOS)
28+
UIScreen.main.bounds.size.width
29+
#else
30+
UIApplication.shared.connectedScenes.compactMap { ($0 as? UIWindowScene)?.keyWindow }.last?.bounds.size.width ?? 0
31+
#endif
32+
}
33+
class public var height: CGFloat {
34+
#if os(iOS)
35+
UIScreen.main.bounds.size.height
36+
#else
37+
UIApplication.shared.connectedScenes.compactMap { ($0 as? UIWindowScene)?.keyWindow }.last?.bounds.size.height ?? 0
38+
#endif
39+
}
2840

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

@@ -37,7 +49,13 @@ open class ContainerDevice {
3749

3850
static public let isIpad = UIDevice.current.userInterfaceIdiom == .pad
3951
static public let isIphone = UIDevice.current.userInterfaceIdiom == .phone
40-
static public let isRetina = UIScreen.main.scale >= 2.0
52+
static public let isRetina = {
53+
#if os(iOS)
54+
UIScreen.main.scale >= 2.0
55+
#else
56+
true
57+
#endif
58+
}
4159

4260
class public var isIphone4: Bool { (isIphone && screenMax < 568.0) }
4361
class public var isIphone5: Bool { (isIphone && screenMax == 568.0) } // SE
@@ -75,6 +93,7 @@ open class ContainerDevice {
7593

7694
var portrait: Bool = false
7795

96+
#if os(iOS)
7897
let size: CGSize = UIScreen.main.bounds.size
7998
if size.width / size.height > 1 {
8099
portrait = false
@@ -89,6 +108,7 @@ open class ContainerDevice {
89108
portrait = true
90109
default: break
91110
}
111+
#endif
92112

93113
return portrait
94114
}

0 commit comments

Comments
 (0)