Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ internal extension BottomSheetView {
if self.isIPad {
// On iPad use 30% of the width
return geometry.size.width * 0.3
} else if UIDevice.current.userInterfaceIdiom == .phone && UIDevice.current.orientation.isLandscape {
} else if UIDevice.current.userInterfaceIdiom == .phone && UIDevice.current.orientation.isLandscape && (bundleOrientationLock() == .unlocked || bundleOrientationLock() == .landscapeOnly) {
// On iPhone landscape use 40% of the width
return geometry.size.width * 0.4
} else {
Expand Down
53 changes: 53 additions & 0 deletions Sources/BottomSheet/Helper/OrientationHelper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// OrientationHelper.swift
// BottomSheet
//
// Created by Pedro Cavaleiro on 27/08/2025.
//

#if os(iOS)
import UIKit

enum BundleOrientationLock {
case portraitOnly
case landscapeOnly
case unlocked
}

func bundleOrientationLock() -> BundleOrientationLock {
let info = Bundle.main.infoDictionary

// Grab iPhone orientations first, fallback to iPad
let iPhoneOrientations = info?["UISupportedInterfaceOrientations"] as? [String] ?? []
let iPadOrientations = info?["UISupportedInterfaceOrientations~ipad"] as? [String] ?? []

let orientations = !iPhoneOrientations.isEmpty ? iPhoneOrientations : iPadOrientations

// Map strings into orientation masks
let masks: [UIInterfaceOrientationMask] = orientations.compactMap { str in
switch str {
case "UIInterfaceOrientationPortrait":
return .portrait
case "UIInterfaceOrientationPortraitUpsideDown":
return .portraitUpsideDown
case "UIInterfaceOrientationLandscapeLeft":
return .landscapeLeft
case "UIInterfaceOrientationLandscapeRight":
return .landscapeRight
default:
return nil
}
}

if masks.count == 1 {
if masks.contains(.portrait) || masks.contains(.portraitUpsideDown) {
return .portraitOnly
} else if masks.contains(.landscapeLeft) || masks.contains(.landscapeRight) {
return .landscapeOnly
}
}

return .unlocked
}

#endif