From 487700f5b7978a234e0399f847f451078f7aaf2b Mon Sep 17 00:00:00 2001 From: Tommy Chow Date: Thu, 8 Jan 2026 00:06:18 -0500 Subject: [PATCH] add device orientation detection for optimal landscape rotation --- lib/screens/channel/video/video_overlay.dart | 38 +++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/lib/screens/channel/video/video_overlay.dart b/lib/screens/channel/video/video_overlay.dart index e6668b84..0ab9eafb 100644 --- a/lib/screens/channel/video/video_overlay.dart +++ b/lib/screens/channel/video/video_overlay.dart @@ -16,6 +16,7 @@ import 'package:frosty/widgets/live_indicator.dart'; import 'package:frosty/widgets/section_header.dart'; import 'package:frosty/widgets/uptime.dart'; import 'package:intl/intl.dart'; +import 'package:native_device_orientation/native_device_orientation.dart'; import 'package:provider/provider.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -172,12 +173,39 @@ class VideoOverlay extends StatelessWidget { color: surfaceColor, shadows: _iconShadow, ), - onPressed: () { + onPressed: () async { if (context.isPortrait) { - SystemChrome.setPreferredOrientations([ - DeviceOrientation.landscapeLeft, - DeviceOrientation.landscapeRight, - ]); + // Detect physical device tilt to rotate to optimal orientation + final physicalOrientation = + await NativeDeviceOrientationCommunicator() + .orientation(useSensor: true); + + // Map native orientation to Flutter's DeviceOrientation + // iOS: native landscapeLeft = notch left, needs swap to Flutter's landscapeRight + // Android: direct mapping works correctly + final needsSwap = Platform.isIOS; + + if (physicalOrientation == + NativeDeviceOrientation.landscapeLeft) { + SystemChrome.setPreferredOrientations([ + needsSwap + ? DeviceOrientation.landscapeRight + : DeviceOrientation.landscapeLeft, + ]); + } else if (physicalOrientation == + NativeDeviceOrientation.landscapeRight) { + SystemChrome.setPreferredOrientations([ + needsSwap + ? DeviceOrientation.landscapeLeft + : DeviceOrientation.landscapeRight, + ]); + } else { + // Not tilted to landscape yet, allow both + SystemChrome.setPreferredOrientations([ + DeviceOrientation.landscapeLeft, + DeviceOrientation.landscapeRight, + ]); + } } else { SystemChrome.setPreferredOrientations([ DeviceOrientation.portraitUp,