This file contains hidden or 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
let appFlowCoordinator = AppFlowCoordinator() | |
let rootView = RootView().environmentObject(appFlowCoordinator) | |
window.rootViewController = UIHostingController(rootView: rootView) |
This file contains hidden or 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
struct LoginView: View { | |
@EnvironmentObject var appFlowCoordinator: AppFlowCoordinator | |
var body: some View { | |
ZStack { | |
Button(action: appFlowCoordinator.showMainView) { | |
Text("Login") | |
} | |
} | |
} |
This file contains hidden or 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
struct RootView: View { | |
@EnvironmentObject var appFlowCoordinator: AppFlowCoordinator | |
@ViewBuilder | |
var body: some View { | |
ZStack { | |
Color.black.edgesIgnoringSafeArea(.all) | |
if appFlowCoordinator.activeFlow == .main { | |
ContentView().transition(.asymmetric(insertion: .scale, removal: .opacity)) | |
} |
This file contains hidden or 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
import SwiftUI | |
final class AppFlowCoordinator: ObservableObject { | |
@Published var activeFlow: Flow = .login | |
func showLoginView() { | |
withAnimation { | |
activeFlow = .login | |
} | |
} |
This file contains hidden or 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
import SwiftUI | |
struct ContentView: View { | |
@Environment(\.dependencyManager) var dependencyManager: DependencyManager | |
var body: some View { | |
Text(dependencyManager.identifier) | |
} | |
} |
This file contains hidden or 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
// Setting non-default instance of DependencyManager, otherwise default instance is used created in DependencyManagerKey | |
let dependencyManager = DependencyManager(identifier: "Scene delegate created") | |
let contentView = ContentView().environment(\.dependencyManager, dependencyManager) |
This file contains hidden or 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
import Foundation | |
import SwiftUI | |
struct DependencyManager { | |
let identifier: String | |
let urlSession = URLSession.shared | |
} | |
struct DependencyManagerKey: EnvironmentKey { | |
typealias Value = DependencyManager |
This file contains hidden or 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
let textView = TokenTextView(frame: .zero) | |
textView.translatesAutoresizingMaskIntoConstraints = false | |
view.addSubview(textView) | |
NSLayoutConstraint.activate([ | |
textView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 16), | |
textView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -16), | |
textView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 16), | |
textView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -16) | |
]) | |
This file contains hidden or 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
final class TokenTextView: UITextView { | |
init(frame: CGRect) { | |
let layoutManager = TokenLayoutManager() | |
let textStorage = NSTextStorage() | |
textStorage.addLayoutManager(layoutManager) | |
let textContainer = NSTextContainer() | |
textContainer.heightTracksTextView = true | |
textContainer.widthTracksTextView = true | |
layoutManager.addTextContainer(textContainer) | |
super.init(frame: frame, textContainer: textContainer) |
This file contains hidden or 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
extension NSAttributedString.Key { | |
static let token = NSAttributedString.Key("Token") | |
} | |
final class TokenLayoutManager: NSLayoutManager { | |
var textContainerOriginOffset: CGSize = .zero | |
override func drawGlyphs(forGlyphRange glyphsToShow: NSRange, at origin: CGPoint) { | |
let characterRange = self.characterRange(forGlyphRange: glyphsToShow, actualGlyphRange: nil) | |
textStorage?.enumerateAttribute(.token, in: characterRange, options: .longestEffectiveRangeNotRequired, using: { (value, subrange, _) in |