Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[camera] Fix iOS rotation issue #3591

Merged
merged 11 commits into from
Mar 24, 2021
Merged
4 changes: 4 additions & 0 deletions packages/camera/camera/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.8.0-nullsafety.3

* Solved a rotation issue on iOS which caused the default preview to be displayed as landscape right instead of portrait.

## 0.8.0-nullsafety.2

* Solved delay when using the zoom feature on iOS.
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera/ios/Classes/CameraPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ - (instancetype)initWithCameraName:(NSString *)cameraName
if ([_captureDevice position] == AVCaptureDevicePositionFront) {
connection.videoMirrored = YES;
}
connection.videoOrientation = AVCaptureVideoOrientationLandscapeRight;
connection.videoOrientation = AVCaptureVideoOrientationPortrait;
[_captureSession addInputWithNoConnections:_captureVideoInput];
[_captureSession addOutputWithNoConnections:_captureVideoOutput];
[_captureSession addConnection:connection];
Expand Down
18 changes: 8 additions & 10 deletions packages/camera/camera/lib/src/camera_preview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import 'package:camera/camera.dart';
import 'package:camera_platform_interface/camera_platform_interface.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

Expand Down Expand Up @@ -41,26 +40,25 @@ class CameraPreview extends StatelessWidget {
: Container();
}

DeviceOrientation _getApplicableOrientation() {
return controller.value.isRecordingVideo
? controller.value.recordingOrientation!
: (controller.value.lockedCaptureOrientation ??
controller.value.deviceOrientation);
}

bool _isLandscape() {
return [DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]
.contains(_getApplicableOrientation());
}

int _getQuarterTurns() {
int platformOffset = defaultTargetPlatform == TargetPlatform.iOS ? 1 : 0;
Map<DeviceOrientation, int> turns = {
DeviceOrientation.portraitUp: 0,
DeviceOrientation.landscapeLeft: 1,
DeviceOrientation.portraitDown: 2,
DeviceOrientation.landscapeRight: 3,
};
return turns[_getApplicableOrientation()]! + platformOffset;
return turns[_getApplicableOrientation()]!;
}

DeviceOrientation _getApplicableOrientation() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm, there is no diff in this method right? The method was just moved down?

Copy link
Contributor Author

@mvanbeusekom mvanbeusekom Mar 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, it made more sense to me to keep it closer to where it was used. I see now that it causes a bit of noice

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keeping it close to where it was used makes sense to me!

return controller.value.isRecordingVideo
? controller.value.recordingOrientation!
: (controller.value.lockedCaptureOrientation ??
controller.value.deviceOrientation);
}
}
2 changes: 1 addition & 1 deletion packages/camera/camera/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: camera
description: A Flutter plugin for getting information about and controlling the
camera on Android and iOS. Supports previewing the camera feed, capturing images, capturing video,
and streaming image buffers to dart.
version: 0.8.0-nullsafety.2
version: 0.8.0-nullsafety.3
homepage: https://github.com/flutter/plugins/tree/master/packages/camera/camera

dependencies:
Expand Down