fix: Fix basic Orientation on iOS (#2000)

* fix: Fix basic Orientation on iOS

* ci: Use macOS 13 runner for latest Xcode 15

* chore: Remove Xcode 15 checks

* Format
This commit is contained in:
Marc Rousavy 2023-10-14 13:17:14 +02:00 committed by GitHub
parent fab5bdc0cd
commit ea98112a21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 38 deletions

View File

@ -21,7 +21,7 @@ on:
jobs: jobs:
build: build:
name: Build iOS Example App name: Build iOS Example App
runs-on: macOS-latest runs-on: macOS-13
defaults: defaults:
run: run:
working-directory: package/example/ios working-directory: package/example/ios
@ -80,7 +80,7 @@ jobs:
build-no-frame-processors: build-no-frame-processors:
name: Build iOS Example App without Frame Processors name: Build iOS Example App without Frame Processors
runs-on: macOS-latest runs-on: macOS-13
defaults: defaults:
run: run:
working-directory: package/example/ios working-directory: package/example/ios

View File

@ -27,7 +27,7 @@ jobs:
env: env:
WORKING_DIRECTORY: ios WORKING_DIRECTORY: ios
SwiftFormat: SwiftFormat:
runs-on: macOS-latest runs-on: macOS-13
defaults: defaults:
run: run:
working-directory: ./package/ios working-directory: ./package/ios

View File

@ -39,17 +39,12 @@ class CameraDevicesManager: RCTEventEmitter {
override func constantsToExport() -> [AnyHashable: Any]! { override func constantsToExport() -> [AnyHashable: Any]! {
let devices = getDevicesJson() let devices = getDevicesJson()
let preferredDevice: [String: Any]? let preferredDevice: [String: Any]?
// TODO: Remove this #if once Xcode 15 is rolled out
#if swift(>=5.9)
if #available(iOS 17.0, *), if #available(iOS 17.0, *),
let userPreferred = AVCaptureDevice.userPreferredCamera { let userPreferred = AVCaptureDevice.userPreferredCamera {
preferredDevice = userPreferred.toDictionary() preferredDevice = userPreferred.toDictionary()
} else { } else {
preferredDevice = devices.first preferredDevice = devices.first
} }
#else
preferredDevice = devices.first
#endif
return [ return [
"availableCameraDevices": devices, "availableCameraDevices": devices,

View File

@ -30,23 +30,22 @@ extension AVCaptureOutput {
- For Videos, the buffers are physically rotated if available, since we use an AVCaptureVideoDataOutput instead of an AVCaptureMovieFileOutput. - For Videos, the buffers are physically rotated if available, since we use an AVCaptureVideoDataOutput instead of an AVCaptureMovieFileOutput.
*/ */
func setOrientation(_ orientation: Orientation) { func setOrientation(_ orientation: Orientation) {
// Camera Sensors are always in 90deg rotation.
// We are setting the target rotation here, so we need to rotate by 90deg once.
let cameraOrientation = orientation.rotateRight()
// Set orientation for each connection // Set orientation for each connection
connections.forEach { connection in connections.forEach { connection in
// TODO: Use this once Xcode 15 is rolled out if #available(iOS 17.0, *) {
// if #available(iOS 17.0, *) { // Camera Sensors are always in landscape rotation (90deg).
// let degrees = cameraOrientation.toDegrees() // We are setting the target rotation here, so we need to rotate by landscape once.
// if connection.isVideoRotationAngleSupported(degrees) { let cameraOrientation = orientation.rotateBy(orientation: .landscapeLeft)
// connection.videoRotationAngle = degrees let degrees = cameraOrientation.toDegrees()
// }
// } else { if connection.isVideoRotationAngleSupported(degrees) {
connection.videoRotationAngle = degrees
}
} else {
if connection.isVideoOrientationSupported { if connection.isVideoOrientationSupported {
connection.videoOrientation = cameraOrientation.toAVCaptureVideoOrientation() connection.videoOrientation = orientation.toAVCaptureVideoOrientation()
} }
// } }
} }
} }
} }

View File

@ -38,6 +38,19 @@ enum Orientation: String, JSUnionValue {
} }
} }
init(degrees: Double) {
switch degrees {
case 45 ..< 135:
self = .landscapeLeft
case 135 ..< 225:
self = .portraitUpsideDown
case 225 ..< 315:
self = .landscapeRight
default:
self = .portrait
}
}
var jsValue: String { var jsValue: String {
return rawValue return rawValue
} }
@ -68,16 +81,9 @@ enum Orientation: String, JSUnionValue {
} }
} }
func rotateRight() -> Orientation { func rotateBy(orientation: Orientation) -> Orientation {
switch self { let added = toDegrees() + orientation.toDegrees()
case .portrait: let degress = added.truncatingRemainder(dividingBy: 360)
return .landscapeLeft return Orientation(degrees: degress)
case .landscapeLeft:
return .portraitUpsideDown
case .portraitUpsideDown:
return .landscapeRight
case .landscapeRight:
return .portrait
}
} }
} }