This commit is contained in:
Ivan Vorobei
2019-06-26 22:12:35 +03:00
parent 2477f5d038
commit 48001a8e9a
1363 changed files with 6 additions and 3 deletions

68
Other Projects/SplitView/.gitignore vendored Executable file
View File

@@ -0,0 +1,68 @@
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
## Build generated
build/
DerivedData/
## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/
## Other
*.moved-aside
*.xccheckout
*.xcscmblueprint
## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM
## Playgrounds
timeline.xctimeline
playground.xcworkspace
# Swift Package Manager
#
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
# Package.pins
# Package.resolved
.build/
# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/
# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts
Carthage/Build
# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots/**/*.png
fastlane/test_output

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2019 Alexsander Akers
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,32 @@
// swift-tools-version:5.1
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "SplitView",
platforms: [
.iOS(.v13),
.tvOS(.v13)
],
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "SplitView",
targets: ["SplitView"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "SplitView",
dependencies: []),
.testTarget(
name: "SplitViewTests",
dependencies: ["SplitView"]),
]
)

View File

@@ -0,0 +1,3 @@
# SplitView
A SwiftUI view that manages a UISplitViewController.

View File

@@ -0,0 +1,22 @@
import SwiftUI
public struct SplitView<Master: View, Detail: View>: View {
public var master: Master
public var detail: Detail
@State public var preferredDisplayMode: UISplitViewController.DisplayMode
public var body: some View {
let controllers = [UIHostingController(rootView: master), UIHostingController(rootView: detail)]
return SplitViewController(controllers: controllers, preferredDisplayMode: $preferredDisplayMode)
}
}
public extension SplitView {
init(master: Master, detail: Detail) {
self.init(master: master, detail: detail, preferredDisplayMode: .automatic)
}
func preferredDisplayMode(_ preferredDisplayMode: UISplitViewController.DisplayMode) -> Self {
return SplitView(master: master, detail: detail, preferredDisplayMode: preferredDisplayMode)
}
}

View File

@@ -0,0 +1,18 @@
import SwiftUI
public struct SplitViewController: UIViewControllerRepresentable {
public var controllers: [UIViewController]
@Binding public var preferredDisplayMode: UISplitViewController.DisplayMode
public func makeUIViewController(context: UIViewControllerRepresentableContext<SplitViewController>) -> UISplitViewController {
let splitViewController = UISplitViewController()
splitViewController.preferredDisplayMode = preferredDisplayMode
splitViewController.viewControllers = controllers
return splitViewController
}
public func updateUIViewController(_ uiViewController: UISplitViewController, context: UIViewControllerRepresentableContext<SplitViewController>) {
uiViewController.preferredDisplayMode = preferredDisplayMode
uiViewController.viewControllers = controllers
}
}

View File

@@ -0,0 +1,7 @@
import XCTest
import SplitViewTests
var tests = [XCTestCaseEntry]()
tests += SplitViewTests.allTests()
XCTMain(tests)

View File

@@ -0,0 +1,14 @@
import XCTest
@testable import SplitView
final class SplitViewTests: XCTestCase {
func testExample() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct
// results.
}
static var allTests = [
("testExample", testExample),
]
}

View File

@@ -0,0 +1,9 @@
import XCTest
#if !canImport(ObjectiveC)
public func allTests() -> [XCTestCaseEntry] {
return [
testCase(SplitViewTests.allTests),
]
}
#endif