-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix refreshing a scenario to make HotReloadingScenario working
- Loading branch information
Showing
7 changed files
with
154 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
Sample/Sample/Sources/Internal/Scenarios/HotReloading/HotReloadingSwiftUIScenario.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// Copyright © 2022 An Tran. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Inject | ||
import Scenarios | ||
import SwiftUI | ||
|
||
public final class HotReloadingSwiftUIScenario: Scenario { | ||
public static var name: String = "SwiftUI" | ||
public static var kind: ScenarioKind = .prototype | ||
public static var category: ScenarioCategory? = "Hot Reloading" | ||
|
||
public static var rootViewProvider: RootViewProviding { | ||
BasicAppController( | ||
rootViewController: UIHostingController(rootView: ContentView()) | ||
) | ||
} | ||
} | ||
|
||
private struct ContentView: View { | ||
|
||
@ObserveInjection var inject | ||
|
||
var body: some View { | ||
VStack { | ||
Text("SwiftUI: Hot Reloading is cool") | ||
.foregroundColor(Color.blue) | ||
Text("Find more at https://antran.app") | ||
} | ||
.background(Color.red) | ||
.enableInjection() | ||
.onInjection { _ in | ||
NotificationCenter.default.post(name: .refreshScenario, object: nil) | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
Sample/Sample/Sources/Internal/Scenarios/HotReloading/HotReloadingUIKitScenario.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// Copyright © 2022 An Tran. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Inject | ||
import Scenarios | ||
import SwiftUI | ||
|
||
public final class HotReloadingUIKitScenario: Scenario { | ||
public static var name: String = "UIKit" | ||
public static var kind: ScenarioKind = .prototype | ||
public static var category: ScenarioCategory? = "Hot Reloading" | ||
|
||
public static var rootViewProvider: RootViewProviding { | ||
BasicAppController( | ||
rootViewController: Inject.ViewControllerHost(ViewController()) | ||
) | ||
} | ||
} | ||
|
||
private class ViewController: UIViewController { | ||
init() { | ||
super.init(nibName: nil, bundle: nil) | ||
} | ||
|
||
@available(*, unavailable) | ||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
view.backgroundColor = .systemBackground | ||
|
||
let label = UILabel() | ||
label.text = "UIKit: Hot Reloading" | ||
label.textAlignment = .center | ||
|
||
let stackView = UIStackView(arrangedSubviews: [label]) | ||
stackView.axis = .vertical | ||
|
||
view.addFillingSubview(stackView) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters