{"id":26591565,"url":"https://github.com/ivan-magda/swiftui-interface-orientation","last_synced_at":"2026-01-17T12:56:18.507Z","repository":{"id":282845604,"uuid":"949768083","full_name":"ivan-magda/swiftui-interface-orientation","owner":"ivan-magda","description":"Per-view orientation locking for SwiftUI apps, solving the lack of built-in orientation control.","archived":false,"fork":false,"pushed_at":"2026-01-15T13:40:59.000Z","size":48,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-16T21:35:55.728Z","etag":null,"topics":["interface-orientation","ios","ios-development","orientation","screen-rotation","swift","swift-package-manager","swiftui","uikit","view-modifier"],"latest_commit_sha":null,"homepage":"https://ivan-magda.github.io/swiftui-interface-orientation/","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ivan-magda.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2025-03-17T05:29:59.000Z","updated_at":"2026-01-15T13:41:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"56792fd8-4788-4c16-a3aa-14b686ba19c1","html_url":"https://github.com/ivan-magda/swiftui-interface-orientation","commit_stats":null,"previous_names":["ivan-magda/swiftui-interface-orientation"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/ivan-magda/swiftui-interface-orientation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivan-magda%2Fswiftui-interface-orientation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivan-magda%2Fswiftui-interface-orientation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivan-magda%2Fswiftui-interface-orientation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivan-magda%2Fswiftui-interface-orientation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ivan-magda","download_url":"https://codeload.github.com/ivan-magda/swiftui-interface-orientation/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivan-magda%2Fswiftui-interface-orientation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28492345,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T00:50:05.742Z","status":"online","status_checked_at":"2026-01-17T02:00:07.808Z","response_time":85,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["interface-orientation","ios","ios-development","orientation","screen-rotation","swift","swift-package-manager","swiftui","uikit","view-modifier"],"created_at":"2025-03-23T14:18:30.649Z","updated_at":"2026-01-17T12:56:18.471Z","avatar_url":"https://github.com/ivan-magda.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SwiftUI Interface Orientation\n\n[![Swift 6](https://img.shields.io/badge/Swift-6-orange.svg)](https://swift.org)\n[![iOS 14+](https://img.shields.io/badge/iOS-14+-blue.svg)](https://developer.apple.com/ios/)\n[![SPM Compatible](https://img.shields.io/badge/SPM-compatible-brightgreen.svg)](https://swift.org/package-manager/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)\n\n**Lock screen orientation per-view in SwiftUI. No UIKit subclassing, no hacks.**\n\n```swift\nText(\"This view stays portrait\")\n    .supportedInterfaceOrientations(.portrait)\n```\n\nThat's it. The view locks to portrait. Navigate away, it unlocks. Conflicting constraints across multiple views? Handled automatically.\n\n## The Problem\n\nSwiftUI has no native way to lock orientation for specific views. You either lock the entire app in Info.plist, or dive into UIKit lifecycle callbacks scattered across AppDelegate, SceneDelegate, and view controllers.\n\nThis package gives you a single view modifier that just works.\n\n## Installation\n\n### Swift Package Manager\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/ivan-magda/swiftui-interface-orientation.git\", from: \"1.1.0\")\n]\n```\n\nOr in Xcode: **File → Add Packages** → paste the URL above.\n\n## Quick Start\n\n### 1. Configure the manager (once, at app launch)\n\n```swift\nimport SwiftUIInterfaceOrientation\n\n@main\nstruct MyApp: App {\n    init() {\n        InterfaceOrientationManager.configure()\n    }\n\n    var body: some Scene {\n        WindowGroup {\n            ContentView()\n        }\n    }\n}\n```\n\n### 2. Wire up iOS orientation callbacks\n\n```swift\nclass OrientationDelegate: NSObject, UIApplicationDelegate {\n    func application(\n        _ application: UIApplication,\n        supportedInterfaceOrientationsFor window: UIWindow?\n    ) -\u003e UIInterfaceOrientationMask {\n        InterfaceOrientationManager.shared.supportedInterfaceOrientations\n    }\n}\n\n@main\nstruct MyApp: App {\n    @UIApplicationDelegateAdaptor(OrientationDelegate.self) var delegate\n\n    init() {\n        InterfaceOrientationManager.configure()\n    }\n\n    var body: some Scene {\n        WindowGroup {\n            ContentView()\n        }\n    }\n}\n```\n\n### 3. Lock any view to specific orientations\n\n```swift\nstruct PortraitOnlyView: View {\n    var body: some View {\n        Text(\"Locked to portrait\")\n            .supportedInterfaceOrientations(.portrait)\n    }\n}\n\nstruct LandscapeOnlyView: View {\n    var body: some View {\n        VideoPlayer(player: player)\n            .supportedInterfaceOrientations([.landscapeLeft, .landscapeRight])\n    }\n}\n```\n\n## How It Works\n\nThe package uses a centralized `InterfaceOrientationManager` that tracks orientation constraints from all active views:\n\n1. When a view with `.supportedInterfaceOrientations()` appears, it registers its constraint\n2. When the view disappears, the constraint is removed\n3. The manager computes the intersection of all active constraints\n4. If constraints conflict (intersection is empty), it falls back to your app's defaults from Info.plist\n\nThis means nested views with different constraints \"just work\"—the most restrictive common orientation wins.\n\n## API\n\n### View Modifier\n\n```swift\nfunc supportedInterfaceOrientations(_ orientations: UIInterfaceOrientationMask) -\u003e some View\n```\n\n### Configuration\n\n```swift\n// Use defaults from Info.plist\nInterfaceOrientationManager.configure()\n\n// Or specify custom defaults\nInterfaceOrientationManager.configure(\n    configuration: .init(defaultOrientations: .portrait)\n)\n```\n\n### Orientation Masks\n\n```swift\n.portrait           // Portrait only\n.landscapeLeft      // Landscape, home button on right\n.landscapeRight     // Landscape, home button on left\n.portraitUpsideDown // Upside down (iPad only effectively)\n.landscape          // Both landscape orientations\n.all                // All orientations\n.allButUpsideDown   // All except upside down\n```\n\n## Requirements\n\n- iOS 14.0+\n- Swift 6\n- Xcode 16.0+\n\n## License\n\nMIT License. See [LICENSE](LICENSE) for details.\n\n## Contributing\n\nIssues and PRs welcome.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivan-magda%2Fswiftui-interface-orientation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fivan-magda%2Fswiftui-interface-orientation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivan-magda%2Fswiftui-interface-orientation/lists"}