├── README.md ├── Tests ├── LinuxMain.swift └── SplitViewTests │ ├── XCTestManifests.swift │ └── SplitViewTests.swift ├── Sources └── SplitView │ ├── SplitView.swift │ └── SplitViewController.swift ├── LICENSE ├── Package.swift └── .gitignore /README.md: -------------------------------------------------------------------------------- 1 | # SplitView 2 | 3 | A SwiftUI view that manages a UISplitViewController. 4 | -------------------------------------------------------------------------------- /Tests/LinuxMain.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | 3 | import SplitViewTests 4 | 5 | var tests = [XCTestCaseEntry]() 6 | tests += SplitViewTests.allTests() 7 | XCTMain(tests) 8 | -------------------------------------------------------------------------------- /Tests/SplitViewTests/XCTestManifests.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | 3 | #if !canImport(ObjectiveC) 4 | public func allTests() -> [XCTestCaseEntry] { 5 | return [ 6 | testCase(SplitViewTests.allTests), 7 | ] 8 | } 9 | #endif 10 | -------------------------------------------------------------------------------- /Tests/SplitViewTests/SplitViewTests.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | @testable import SplitView 3 | 4 | final class SplitViewTests: XCTestCase { 5 | func testExample() { 6 | // This is an example of a functional test case. 7 | // Use XCTAssert and related functions to verify your tests produce the correct 8 | // results. 9 | } 10 | 11 | static var allTests = [ 12 | ("testExample", testExample), 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /Sources/SplitView/SplitView.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | public struct SplitView: View { 4 | public var master: Master 5 | public var detail: Detail 6 | @State public var preferredDisplayMode: UISplitViewController.DisplayMode 7 | 8 | public var body: some View { 9 | let controllers = [UIHostingController(rootView: master), UIHostingController(rootView: detail)] 10 | return SplitViewController(controllers: controllers, preferredDisplayMode: $preferredDisplayMode) 11 | } 12 | } 13 | 14 | public extension SplitView { 15 | init(master: Master, detail: Detail) { 16 | self.init(master: master, detail: detail, preferredDisplayMode: .automatic) 17 | } 18 | 19 | func preferredDisplayMode(_ preferredDisplayMode: UISplitViewController.DisplayMode) -> Self { 20 | return SplitView(master: master, detail: detail, preferredDisplayMode: preferredDisplayMode) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/SplitView/SplitViewController.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | public struct SplitViewController: UIViewControllerRepresentable { 4 | public var controllers: [UIViewController] 5 | @Binding public var preferredDisplayMode: UISplitViewController.DisplayMode 6 | 7 | public func makeUIViewController(context: UIViewControllerRepresentableContext) -> UISplitViewController { 8 | let splitViewController = UISplitViewController() 9 | splitViewController.preferredDisplayMode = preferredDisplayMode 10 | splitViewController.viewControllers = controllers 11 | return splitViewController 12 | } 13 | 14 | public func updateUIViewController(_ uiViewController: UISplitViewController, context: UIViewControllerRepresentableContext) { 15 | uiViewController.preferredDisplayMode = preferredDisplayMode 16 | uiViewController.viewControllers = controllers 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Alexsander Akers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.1 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "SplitView", 8 | platforms: [ 9 | .iOS(.v13), 10 | .tvOS(.v13) 11 | ], 12 | products: [ 13 | // Products define the executables and libraries produced by a package, and make them visible to other packages. 14 | .library( 15 | name: "SplitView", 16 | targets: ["SplitView"]), 17 | ], 18 | dependencies: [ 19 | // Dependencies declare other packages that this package depends on. 20 | // .package(url: /* package url */, from: "1.0.0"), 21 | ], 22 | targets: [ 23 | // Targets are the basic building blocks of a package. A target can define a module or a test suite. 24 | // Targets can depend on other targets in this package, and on products in packages which this package depends on. 25 | .target( 26 | name: "SplitView", 27 | dependencies: []), 28 | .testTarget( 29 | name: "SplitViewTests", 30 | dependencies: ["SplitView"]), 31 | ] 32 | ) 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | ## Playgrounds 32 | timeline.xctimeline 33 | playground.xcworkspace 34 | 35 | # Swift Package Manager 36 | # 37 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 38 | # Packages/ 39 | # Package.pins 40 | # Package.resolved 41 | .build/ 42 | 43 | # CocoaPods 44 | # 45 | # We recommend against adding the Pods directory to your .gitignore. However 46 | # you should judge for yourself, the pros and cons are mentioned at: 47 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 48 | # 49 | # Pods/ 50 | 51 | # Carthage 52 | # 53 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 54 | # Carthage/Checkouts 55 | 56 | Carthage/Build 57 | 58 | # fastlane 59 | # 60 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 61 | # screenshots whenever they are needed. 62 | # For more information about the recommended setup visit: 63 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 64 | 65 | fastlane/report.xml 66 | fastlane/Preview.html 67 | fastlane/screenshots/**/*.png 68 | fastlane/test_output 69 | --------------------------------------------------------------------------------