forked from shadowfacts/Tusker
30 lines
631 B
Swift
30 lines
631 B
Swift
|
//
|
||
|
// ViewController.swift
|
||
|
// ComposeUI
|
||
|
//
|
||
|
// Created by Shadowfacts on 3/4/23.
|
||
|
//
|
||
|
|
||
|
import SwiftUI
|
||
|
import Combine
|
||
|
|
||
|
public protocol ViewController: ObservableObject {
|
||
|
associatedtype ContentView: View
|
||
|
|
||
|
@ViewBuilder
|
||
|
var view: ContentView { get }
|
||
|
}
|
||
|
|
||
|
public struct ControllerView<Controller: ViewController>: View {
|
||
|
@StateObject private var controller: Controller
|
||
|
|
||
|
public init(controller: @escaping () -> Controller) {
|
||
|
self._controller = StateObject(wrappedValue: controller())
|
||
|
}
|
||
|
|
||
|
public var body: some View {
|
||
|
controller.view
|
||
|
.environmentObject(controller)
|
||
|
}
|
||
|
}
|