Skip to content

Commit

Permalink
Add IBFreeFormViewControllerRepresentable
Browse files Browse the repository at this point in the history
  • Loading branch information
Adobels committed Nov 13, 2023
1 parent b2a902f commit d871666
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public struct IBFreeFormViewControllerRepresentable<ViewController: UIViewContro
}

public func updateUIViewController(_ uiViewController: UIViewController, context: Context) { }

}

private class ContainerViewController: UIViewController {
Expand Down Expand Up @@ -63,7 +62,6 @@ private class ContainerViewController: UIViewController {
}
gesture.setTranslation(.zero, in: view)
}

}

#endif
Original file line number Diff line number Diff line change
@@ -1,34 +1,16 @@
//
// UIViewPreviews.swift
// IBRepresentableForView.swift
// UIViewKit
//
// Created by Blazej SLEBODA on 20/09/2023.
// Created by Blazej SLEBODA on 13/11/2023.
//

import SwiftUI
@available(iOS 13.0, *)
struct IBRepresentableForViewController<ViewController: UIViewController>: UIViewControllerRepresentable {

public var viewController: ViewController

public init(_ viewController: @escaping @autoclosure () -> ViewController) {
self.viewController = viewController()
}

public init(_ viewController: @escaping () -> ViewController) {
self.viewController = viewController()
}
#if DEBUG

public func makeUIViewController(context: Context) -> UIViewController {
viewController
}

public func updateUIViewController(_ uiViewController: UIViewController, context: Context) { }

}
import SwiftUI

@available(iOS 13.0, *)
struct IBRepresentableForView<View: UIView>: UIViewRepresentable {
public struct IBRepresentableForView<View: UIView>: UIViewRepresentable {

public var view: UIView

Expand Down Expand Up @@ -58,3 +40,5 @@ struct IBRepresentableForView<View: UIView>: UIViewRepresentable {

public func updateUIView(_ uiView: UIView, context: Context) { }
}

#endif
33 changes: 33 additions & 0 deletions Sources/UIViewKit/Previews/IBRepresentableForViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// IBRepresentableForViewController.swift
// UIViewKit
//
// Created by Blazej SLEBODA on 20/09/2023.
//

#if DEBUG

import SwiftUI

@available(iOS 13.0, *)
public struct IBRepresentableForViewController<ViewController: UIViewController>: UIViewControllerRepresentable {

public var viewController: ViewController

public init(_ viewController: @escaping @autoclosure () -> ViewController) {
self.viewController = viewController()
}

public init(_ viewController: @escaping () -> ViewController) {
self.viewController = viewController()
}

public func makeUIViewController(context: Context) -> UIViewController {
viewController
}

public func updateUIViewController(_ uiViewController: UIViewController, context: Context) { }

}

#endif

0 comments on commit d871666

Please sign in to comment.