Skip to content
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

Add visionOS support #706

Closed
theedov opened this issue Jun 22, 2023 · 9 comments · Fixed by #743
Closed

Add visionOS support #706

theedov opened this issue Jun 22, 2023 · 9 comments · Fixed by #743
Labels

Comments

@theedov
Copy link

theedov commented Jun 22, 2023

Screenshot 2023-06-22 at 10 32 30 am
@barnard-b
Copy link

There are two build errors for visionOS: This one in Graphics.swift and another in ImageDecoders+Video.swift

As a temporary solution you can open those files in Visual Studio Code and edit them (you will need to select overwrite when saving). To be clear, this is only a temporary solution and the scale value is just a guess, but it should allow it to compile.

struct Screen {
    #if os(xrOS)
    /// 2 is just a guess, do not depend on it.
    static var scale: CGFloat { 2 }
    #elseif os(iOS) || os(tvOS)
    /// Returns the current screen scale.
    static var scale: CGFloat { UIScreen.main.scale }
    #elseif os(watchOS)
    /// Returns the current screen scale.
    static var scale: CGFloat { WKInterfaceDevice.current().screenScale }
    #elseif os(macOS)
    /// Always returns 1.
    static var scale: CGFloat { 1 }
    #endif
}

(UIScreen is not available in xrOS)

private func makePreview(for data: Data) -> PlatformImage? {
    #if os(xrOS)
    return nil
    #else
    let asset = AVDataAsset(data: data)
    let generator = AVAssetImageGenerator(asset: asset)
    guard let cgImage = try? generator.copyCGImage(at: CMTime(value: 0, timescale: 1), actualTime: nil) else {
        return nil
    }
    return PlatformImage(cgImage: cgImage)
    #endif
}

(copyCGImage is not available in xrOS)

@kean
Copy link
Owner

kean commented Jun 22, 2023

I wonder if there is a way to ship it without introducing warnings on Xcode 14.

Screenshot 2023-06-21 at 10 08 36 PM

I'll create a branch for now.

@theedov
Copy link
Author

theedov commented Jun 22, 2023

They might even change it to visionOS in the upcoming betas.

@kean
Copy link
Owner

kean commented Jun 22, 2023

Do you know if SPM is supported? I can't get the package manifest to compile after adding .xrOS(.v1) – doesn't recognize it.

@kean
Copy link
Owner

kean commented Jun 22, 2023

Preliminary xrOS support is now available in xcode-15 branch.

@kean kean added the feature label Jul 22, 2023
@frlefebvre
Copy link

The last Xcode beta seems to have introduced a few more issues. At first glance, they seem to mostly be due to using AppKit instead of UIKit. Like here:

Screenshot 2023-08-10 at 12 02 19

@kean kean changed the title 'UIScreen' is unavailable in xrOS Add visionOS support Aug 10, 2023
@drmarkpowell
Copy link

Just putting it out there that the prompt attention you are giving this issue encouraged me to become a sponsor! Keep up the great work :) Looking forward to using Nuke in my visionOS app soon.

@kean
Copy link
Owner

kean commented Aug 10, 2023

I appreciate it, @drmarkpowell. It is in the works. I already have the latest Xcode beta and was planning to push the new pre-release version soon.

@kean
Copy link
Owner

kean commented Aug 11, 2023

Version 12.2 (Beta 2) fixes the new compilation errors in Xcode 15 Beta 6.

The plan for the future version is to remove as many of the #if os(...) checks as possible and replace them with #if canImport(...).

I'm yet to figure out how to add SPM support, especially in a way that won't break Xcode 14 compatibility. Any information on that is welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants