feat: Add support for LiDAR, TrueDepth, External (USB) and Continuity Camera Devices (iOS 17) (#1824)

* feat: Add support for LiDAR, TrueDepth, External (USB) and Continuity Camera Devices (iOS 17)

* Rename `devices` -> `physicalDevices`

* fix: Comment out iOS 17 cameras for now

* fix: Move `supportsDepthCapture` to `format`

* fix: Fall back to `wide-angle-camera` for any unknown types

* Update CameraPage.tsx

* `descriptor` -> `physicalDeviceDescriptor`

* Update CameraDevice.ts

* Format

* feat: Expose `userPreferredCameraDevice`

Uses the new iOS 17 API where the user can prefer a default device, otherwise fall back to the first device of the available ones

* fix: Expose as property

* Add TODO comments

* fix: Format code

* fix: Compile below Swift 5.9
This commit is contained in:
Marc Rousavy
2023-09-21 16:29:46 +02:00
committed by GitHub
parent 8864866f80
commit cf4882b152
14 changed files with 136 additions and 85 deletions

View File

@@ -1,38 +0,0 @@
//
// AVCaptureDevice.DeviceType+descriptor.swift
// mrousavy
//
// Created by Marc Rousavy on 15.12.20.
// Copyright © 2020 mrousavy. All rights reserved.
//
import AVFoundation
import Foundation
extension AVCaptureDevice.DeviceType {
var descriptor: String {
if #available(iOS 13.0, *) {
switch self {
case .builtInDualWideCamera:
return "dual-wide-camera"
case .builtInTripleCamera:
return "triple-camera"
case .builtInUltraWideCamera:
return "ultra-wide-angle-camera"
default:
break
}
}
switch self {
case .builtInDualCamera:
return "dual-camera"
case .builtInTelephotoCamera:
return "telephoto-camera"
case .builtInWideAngleCamera:
return "wide-angle-camera"
default:
// e.g. `.builtInTrueDepthCamera`
fatalError("AVCaptureDevice.Position has unknown state.")
}
}
}

View File

@@ -0,0 +1,33 @@
//
// AVCaptureDevice.DeviceType+physicalDeviceDescriptor.swift
// mrousavy
//
// Created by Marc Rousavy on 15.12.20.
// Copyright © 2020 mrousavy. All rights reserved.
//
import AVFoundation
import Foundation
extension AVCaptureDevice.DeviceType {
/**
Gets a descriptor if this is a physical device (wide, ultra-wide and telephoto), or "unknown-camera" otherwise (TrueDepth, LiDAR, InfraRed, USB, ..)
*/
var physicalDeviceDescriptor: String {
if #available(iOS 13.0, *) {
if self == .builtInUltraWideCamera {
return "ultra-wide-angle-camera"
}
}
switch self {
case .builtInTelephotoCamera:
return "telephoto-camera"
case .builtInWideAngleCamera:
return "wide-angle-camera"
default:
// e.g. Infra-Red, LiDAR, Depth Data, USB or Continuity Camera Devices
ReactLogger.log(level: .error, message: "Unknown AVCaptureDevice.DeviceType (\(rawValue))! Falling back to wide-angle-camera..")
return "wide-angle-camera"
}
}
}