Skip to content

Commit

Permalink
Merge pull request #4 from mtzaquia/zaquia/lift-uihostingcontroller
Browse files Browse the repository at this point in the history
Lift `UIHostingControler` inheritance restriction
  • Loading branch information
mtzaquia authored Mar 25, 2024
2 parents 27c0bfd + 21bdc78 commit b450ac9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ myPresentingView

## License

Copyright (c) 2021 @mtzaquia
Copyright (c) 2024 @mtzaquia

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions Sources/UIKitPresentationModifier/PresentationModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public extension View {
isPresented: Binding<Bool>,
@ViewBuilder content: @escaping () -> Presented,
controllerProvider: @escaping (Presented) -> Controller
) -> some View where Presented: View, Controller: UIHostingController<Presented> {
) -> some View where Presented: View, Controller: RootViewProviding<Presented> {
modifier(
UIKitPresentationModifier(
isPresented: isPresented,
Expand All @@ -76,7 +76,7 @@ final class PresentationState: ObservableObject {
var observation: AnyObject?
}

struct UIKitPresentationModifier<Presented, Controller>: ViewModifier where Presented: View, Controller: UIHostingController<Presented> {
struct UIKitPresentationModifier<Presented, Controller>: ViewModifier where Presented: View, Controller: RootViewProviding<Presented> {
init(
isPresented: Binding<Bool>,
content: @escaping () -> Presented,
Expand Down
34 changes: 34 additions & 0 deletions Sources/UIKitPresentationModifier/RootViewProviding.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Copyright (c) 2024 @mtzaquia
//
// 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.
//

import SwiftUI

/// A controller that provides a root view.
///
/// By conforming a custom controller with this type, you are able to create
/// presentation controllers that do not necessarily inherit from `UIHostingController`.
public protocol RootViewProviding<Root>: UIViewController {
associatedtype Root: View
var rootView: Root { get set }
}

extension UIHostingController: RootViewProviding {}

0 comments on commit b450ac9

Please sign in to comment.