Skip to content

Instantly share code, notes, and snippets.

@drewolbrich
Last active June 26, 2024 04:44
Show Gist options
  • Save drewolbrich/84654461d6fcf93d5d58e0d38fe7183e to your computer and use it in GitHub Desktop.
Save drewolbrich/84654461d6fcf93d5d58e0d38fe7183e to your computer and use it in GitHub Desktop.
//
// VolumeBaseplateVisibility_visionOS2.swift
//
// Created by Drew Olbrich on 6/25/24.
// Copyright © 2024 Lunar Skydiving LLC. All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
import SwiftUI
extension View {
/// A wrapper around `volumeBaseplateVisibility` that applies it only on visionOS 2
/// and later, and is a no-op on visionOS 1.
///
/// This is necessary because there doesn't appear to be an easy way to
/// conditionally apply SwiftUI view modifiers or scene modifiers for specific OS
/// versions.
func volumeBaseplateVisibility_visionOS2(_ visibility: VolumeBaseplateVisibility_visionOS2) -> some View {
if #available(visionOS 2.0, *) {
return self.volumeBaseplateVisibility(visibility)
} else {
return self
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment