From 28ffd6b01bb5dea96e85aa9313c5e62c44da5b4c Mon Sep 17 00:00:00 2001 From: Mikhail Date: Thu, 26 Dec 2024 16:00:47 +0100 Subject: [PATCH 1/2] remove demos --- Examples/DemosApp/DemosApp/Core/App.swift | 90 +++---- .../DemosApp/Demos/Login/SwiftUILogin.swift | 163 ------------ .../DemosApp/Demos/Login/UIKitLogin.swift | 234 ------------------ .../UIViewControllerRepresenting.swift | 18 -- 4 files changed, 37 insertions(+), 468 deletions(-) delete mode 100644 Examples/DemosApp/DemosApp/Demos/Login/SwiftUILogin.swift delete mode 100644 Examples/DemosApp/DemosApp/Demos/Login/UIKitLogin.swift delete mode 100644 Examples/DemosApp/DemosApp/Helpers/UIViewControllerRepresenting.swift diff --git a/Examples/DemosApp/DemosApp/Core/App.swift b/Examples/DemosApp/DemosApp/Core/App.swift index d8a335bd..9d9fa46a 100644 --- a/Examples/DemosApp/DemosApp/Core/App.swift +++ b/Examples/DemosApp/DemosApp/Core/App.swift @@ -5,63 +5,47 @@ struct App: View { var body: some View { NavigationView { List { - Section("Components") { - NavigationLinkWithTitle("Button") { - ButtonPreview() - } - NavigationLinkWithTitle("Card") { - CardPreview() - } - NavigationLinkWithTitle("Checkbox") { - CheckboxPreview() - } - NavigationLinkWithTitle("Countdown") { - CountdownPreview() - } - NavigationLinkWithTitle("Divider") { - DividerPreview() - } - NavigationLinkWithTitle("Input Field") { - InputFieldPreview() - } - NavigationLinkWithTitle("Loading") { - LoadingPreview() - } - NavigationLinkWithTitle("Radio Group") { - RadioGroupPreview() - } - NavigationLinkWithTitle("Segmented Control") { - SegmentedControlPreview() - } - NavigationLinkWithTitle("Text Field") { - TextInputPreviewPreview() - } + NavigationLinkWithTitle("Alert") { + AlertPreview() } - - Section("Modals") { - NavigationLinkWithTitle("Alert") { - AlertPreview() - } - NavigationLinkWithTitle("Bottom Modal") { - BottomModalPreview() - } - NavigationLinkWithTitle("Center Modal") { - CenterModalPreview() - } + NavigationLinkWithTitle("Button") { + ButtonPreview() } - - Section("Login Demo") { - NavigationLinkWithTitle("SwiftUI") { - SwiftUILogin() - } - NavigationLinkWithTitle("UIKit") { - UIViewControllerRepresenting { - UIKitLogin() - } - } + NavigationLinkWithTitle("Card") { + CardPreview() + } + NavigationLinkWithTitle("Checkbox") { + CheckboxPreview() + } + NavigationLinkWithTitle("Countdown") { + CountdownPreview() + } + NavigationLinkWithTitle("Divider") { + DividerPreview() + } + NavigationLinkWithTitle("Input Field") { + InputFieldPreview() + } + NavigationLinkWithTitle("Loading") { + LoadingPreview() + } + NavigationLinkWithTitle("Modal (Bottom)") { + BottomModalPreview() + } + NavigationLinkWithTitle("Modal (Center)") { + CenterModalPreview() + } + NavigationLinkWithTitle("Radio Group") { + RadioGroupPreview() + } + NavigationLinkWithTitle("Segmented Control") { + SegmentedControlPreview() + } + NavigationLinkWithTitle("Text Field") { + TextInputPreviewPreview() } } - .navigationTitle("Examples") + .navigationTitle("Components") .navigationBarTitleDisplayMode(.inline) } } diff --git a/Examples/DemosApp/DemosApp/Demos/Login/SwiftUILogin.swift b/Examples/DemosApp/DemosApp/Demos/Login/SwiftUILogin.swift deleted file mode 100644 index 62d69dc7..00000000 --- a/Examples/DemosApp/DemosApp/Demos/Login/SwiftUILogin.swift +++ /dev/null @@ -1,163 +0,0 @@ -import ComponentsKit -import SwiftUI - -struct SwiftUILogin: View { - enum Pages { - case signIn - case signUp - } - enum Input { - case name - case email - case password - case bio - } - - @State private var selectedPage = Pages.signIn - - @State private var name = "" - @State private var email = "" - @State private var password = "" - @State private var bio = "" - - @FocusState private var focusedInput: Input? - @State private var isConsented: Bool = false - @State private var isLoading = false - - private var isButtonEnabled: Bool { - return !self.email.isEmpty - && !self.password.isEmpty - && self.isConsented - && ( - self.selectedPage == .signUp && !self.name.isEmpty - || self.selectedPage == .signIn - ) - } - - var body: some View { - ZStack { - UniversalColor.background.color - - ScrollView { - VStack(spacing: 20) { - SUSegmentedControl( - selectedId: self.$selectedPage, - model: .init { - $0.items = [ - .init(id: .signIn) { - $0.title = "Sign In" - }, - .init(id: .signUp) { - $0.title = "Sign Up" - } - ] - $0.isEnabled = !self.isLoading - } - ) - - Text( - self.selectedPage == .signIn - ? "Welcome back" - : "Create an account" - ) - .font(UniversalFont.lgHeadline.font) - .padding(.vertical, 30) - - if self.selectedPage == .signUp { - SUInputField( - text: self.$name, - globalFocus: self.$focusedInput, - localFocus: .name, - model: .init { - $0.title = "Name" - $0.isRequired = true - $0.isEnabled = !self.isLoading - } - ) - } - SUInputField( - text: self.$email, - globalFocus: self.$focusedInput, - localFocus: .email, - model: .init { - $0.title = "Email" - $0.isRequired = true - $0.isEnabled = !self.isLoading - } - ) - SUInputField( - text: self.$password, - globalFocus: self.$focusedInput, - localFocus: .password, - model: .init { - $0.title = "Password" - $0.isRequired = true - $0.isSecureInput = true - $0.isEnabled = !self.isLoading - } - ) - - if self.selectedPage == .signUp { - SUTextInput( - text: self.$bio, - globalFocus: self.$focusedInput, - localFocus: .bio, - model: .init { - $0.placeholder = "Tell about yourself" - $0.minRows = 3 - $0.maxRows = 5 - $0.isEnabled = !self.isLoading - } - ) - } - - SUCheckbox( - isSelected: self.$isConsented, - model: .init { - $0.title = "By continuing, you accept our Terms of Service and Privacy Policy" - $0.isEnabled = !self.isLoading - } - ) - - Group { - if self.isLoading { - SULoading() - } else { - SUButton( - model: .init { - $0.title = "Continue" - $0.isFullWidth = true - $0.color = .primary - $0.isEnabled = self.isButtonEnabled - }, - action: { - self.isLoading = true - DispatchQueue.main.asyncAfter(deadline: .now() + 2) { - self.isLoading = false - UINotificationFeedbackGenerator().notificationOccurred(.success) - } - } - ) - } - } - .padding(.top, 10) - } - .padding() - } - } - .frame(maxWidth: 500) - .onChange(of: self.selectedPage) { newValue in - if newValue == .signIn, - self.focusedInput == .name || self.focusedInput == .bio { - self.focusedInput = .email - } - } - .onTapGesture { - self.focusedInput = nil - } - } -} - -#Preview { - SwiftUILogin() -} diff --git a/Examples/DemosApp/DemosApp/Demos/Login/UIKitLogin.swift b/Examples/DemosApp/DemosApp/Demos/Login/UIKitLogin.swift deleted file mode 100644 index 8b4d604c..00000000 --- a/Examples/DemosApp/DemosApp/Demos/Login/UIKitLogin.swift +++ /dev/null @@ -1,234 +0,0 @@ -import ComponentsKit -import SwiftUI -import UIKit - -final class UIKitLogin: UIViewController { - enum Pages { - case signIn - case signUp - } - - private let scrollView: UIScrollView = { - let scrollView = UIScrollView() - scrollView.delaysContentTouches = false - return scrollView - }() - private lazy var stackView: UIStackView = { - let stackView = UIStackView() - stackView.axis = .vertical - stackView.spacing = 20 - stackView.alignment = .center - return stackView - }() - - private let pageControl = UKSegmentedControl( - selectedId: .signIn, - model: .init { - $0.items = [ - .init(id: .signIn) { - $0.title = "Sign In" - }, - .init(id: .signUp) { - $0.title = "Sign Up" - } - ] - } - ) - private let titleLabel: UILabel = { - let label = UILabel() - label.font = UniversalFont.lgHeadline.uiFont - return label - }() - private let nameInput = UKInputField( - model: .init { - $0.title = "Name" - $0.isRequired = true - } - ) - private let emailInput = UKInputField( - model: .init { - $0.title = "Email" - $0.isRequired = true - } - ) - private let passwordInput = UKInputField( - model: .init { - $0.title = "Password" - $0.isRequired = true - $0.isSecureInput = true - } - ) - private let bioInput = UKTextInput( - model: .init { - $0.placeholder = "Tell about yourself" - $0.minRows = 3 - $0.maxRows = 5 - } - ) - private let consentCheckbox = UKCheckbox( - model: .init { - $0.title = "By continuing, you accept our Terms of Service and Privacy Policy" - } - ) - private let continueButton = UKButton( - model: .init { - $0.title = "Continue" - $0.isFullWidth = true - $0.color = .primary - } - ) - private let loader = UKLoading() - - private var isLoading = false { - didSet { self.update() } - } - - private var isButtonEnabled: Bool { - return !self.emailInput.text.isEmpty - && !self.passwordInput.text.isEmpty - && self.consentCheckbox.isSelected - && ( - self.pageControl.selectedId == .signUp && !self.nameInput.text.isEmpty - || self.pageControl.selectedId == .signIn - ) - } - - override func viewDidLoad() { - super.viewDidLoad() - - self.setup() - self.style() - self.layout() - self.update() - } - - private func setup() { - self.view.addSubview(self.scrollView) - self.scrollView.addSubview(self.stackView) - self.scrollView.addSubview(self.loader) - - self.stackView.addArrangedSubview(self.pageControl) - self.stackView.addArrangedSubview(self.titleLabel) - self.stackView.addArrangedSubview(self.nameInput) - self.stackView.addArrangedSubview(self.emailInput) - self.stackView.addArrangedSubview(self.passwordInput) - self.stackView.addArrangedSubview(self.bioInput) - self.stackView.addArrangedSubview(self.consentCheckbox) - self.stackView.addArrangedSubview(self.continueButton) - - self.pageControl.onSelectionChange = { [weak self] _ in - guard let self else { return } - - self.dismissKeyboard() - self.update() - } - self.nameInput.onValueChange = { [weak self] _ in - self?.update() - } - self.emailInput.onValueChange = { [weak self] _ in - self?.update() - } - self.passwordInput.onValueChange = { [weak self] _ in - self?.update() - } - self.consentCheckbox.onValueChange = { [weak self] _ in - self?.update() - } - self.continueButton.action = { - self.isLoading = true - DispatchQueue.main.asyncAfter(deadline: .now() + 2) { - self.isLoading = false - UINotificationFeedbackGenerator().notificationOccurred(.success) - } - } - - self.scrollView.addGestureRecognizer( - UITapGestureRecognizer( - target: self, - action: #selector(self.dismissKeyboard) - ) - ) - } - - @objc private func dismissKeyboard() { - self.nameInput.resignFirstResponder() - self.emailInput.resignFirstResponder() - self.passwordInput.resignFirstResponder() - self.bioInput.resignFirstResponder() - } - - private func style() { - self.scrollView.backgroundColor = UniversalColor.background.uiColor - - self.stackView.setCustomSpacing(50, after: self.pageControl) - self.stackView.setCustomSpacing(50, after: self.titleLabel) - self.stackView.setCustomSpacing(50, after: self.consentCheckbox) - } - - private func layout() { - self.scrollView.allEdges() - - self.stackView.top(20) - self.stackView.bottom(20) - - self.stackView.leadingAnchor.constraint( - greaterThanOrEqualTo: self.view.leadingAnchor, - constant: 20 - ).isActive = true - self.stackView.trailingAnchor.constraint( - lessThanOrEqualTo: self.view.trailingAnchor, - constant: -20 - ).isActive = true - self.stackView.widthAnchor.constraint( - lessThanOrEqualToConstant: 500 - ).isActive = true - self.stackView.centerHorizontally() - - self.loader.below(self.stackView, padding: 50) - self.loader.centerHorizontally() - } - - private func update() { - switch self.pageControl.selectedId { - case .signIn: - self.nameInput.isHidden = true - self.bioInput.isHidden = true - self.titleLabel.text = "Welcome back" - case .signUp: - self.nameInput.isHidden = false - self.bioInput.isHidden = false - self.titleLabel.text = "Create an account" - } - - self.pageControl.model.update { - $0.isEnabled = !self.isLoading - } - self.nameInput.model.update { - $0.isEnabled = !self.isLoading - } - self.emailInput.model.update { - $0.isEnabled = !self.isLoading - } - self.passwordInput.model.update { - $0.isEnabled = !self.isLoading - } - self.consentCheckbox.model.update { - $0.isEnabled = !self.isLoading - } - self.bioInput.model.update { - $0.isEnabled = !self.isLoading - } - self.continueButton.model.update { [weak self] in - guard let self else { return } - $0.isEnabled = self.isButtonEnabled - } - self.loader.isHidden = !self.isLoading - self.continueButton.isHidden = self.isLoading - } -} - -#Preview { - UIViewControllerRepresenting { - UIKitLogin() - } -} diff --git a/Examples/DemosApp/DemosApp/Helpers/UIViewControllerRepresenting.swift b/Examples/DemosApp/DemosApp/Helpers/UIViewControllerRepresenting.swift deleted file mode 100644 index 6533405a..00000000 --- a/Examples/DemosApp/DemosApp/Helpers/UIViewControllerRepresenting.swift +++ /dev/null @@ -1,18 +0,0 @@ -import SwiftUI -import UIKit - -struct UIViewControllerRepresenting: UIViewControllerRepresentable { - private let controller: ViewController - - init(_ controller: () -> ViewController) { - self.controller = controller() - } - - func makeUIViewController(context: Context) -> some UIViewController { - return self.controller - } - func updateUIViewController( - _ uiViewController: UIViewControllerType, - context: Context - ) {} -} From 7ac0d105ebd816e560ca98e1dcc1bace0a9cc002 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Thu, 26 Dec 2024 16:03:31 +0100 Subject: [PATCH 2/2] change number of min and max rows in the `textInput` preview --- .../ComponentsPreview/PreviewPages/TextInputPreview.swift | 5 +++-- Examples/DemosApp/DemosApp/Core/App.swift | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Examples/DemosApp/DemosApp/ComponentsPreview/PreviewPages/TextInputPreview.swift b/Examples/DemosApp/DemosApp/ComponentsPreview/PreviewPages/TextInputPreview.swift index 0c3673b6..978ee110 100644 --- a/Examples/DemosApp/DemosApp/ComponentsPreview/PreviewPages/TextInputPreview.swift +++ b/Examples/DemosApp/DemosApp/ComponentsPreview/PreviewPages/TextInputPreview.swift @@ -42,13 +42,14 @@ struct TextInputPreviewPreview: View { BodyFontPicker(selection: self.$model.font) KeyboardTypePicker(selection: self.$model.keyboardType) Picker("Max Rows", selection: self.$model.maxRows) { - Text("2 Rows").tag(2) Text("3 Rows").tag(3) + Text("4 Rows").tag(4) Text("No Limit").tag(Optional.none) } Picker("Min Rows", selection: self.$model.minRows) { Text("1 Row").tag(1) Text("2 Rows").tag(2) + Text("3 Rows").tag(3) } Toggle("Placeholder", isOn: .init( get: { @@ -81,7 +82,7 @@ struct TextInputPreviewPreview: View { private static var initialModel: TextInputVM { return .init { $0.placeholder = "Placeholder" - $0.minRows = 1 + $0.minRows = 2 $0.maxRows = nil } } diff --git a/Examples/DemosApp/DemosApp/Core/App.swift b/Examples/DemosApp/DemosApp/Core/App.swift index 9d9fa46a..1ffaa23f 100644 --- a/Examples/DemosApp/DemosApp/Core/App.swift +++ b/Examples/DemosApp/DemosApp/Core/App.swift @@ -41,7 +41,7 @@ struct App: View { NavigationLinkWithTitle("Segmented Control") { SegmentedControlPreview() } - NavigationLinkWithTitle("Text Field") { + NavigationLinkWithTitle("Text Input") { TextInputPreviewPreview() } }