From a88a85fe750976b2ee0252943ffccb974b05cc27 Mon Sep 17 00:00:00 2001 From: Nikita Semenov Date: Tue, 26 Jul 2022 15:09:42 +0300 Subject: [PATCH] fix: move alerts into TIUIKitCore --- TIUIElements/README.md | 62 ------------- TIUIKitCore/README.md | 88 +++++++++++++++++-- .../Alerts/Factories/AlertFactory.swift | 0 .../Sources/Alerts/Models/AlertAction.swift | 0 .../Alerts/Models/AlertDescriptor.swift | 0 .../Alerts/Protocols/AlertPresentable.swift | 0 .../Protocols/AlertPresentationContext.swift | 0 .../Alerts/Protocols/UIKitAlertContext.swift | 0 .../Alerts}/AlertDescriptor+Helpers.swift | 0 .../UIAlertController+AlertPresentable.swift | 0 .../AlertLocalizationProvider.swift | 0 .../DefaultAlertLocalizationProvider.swift | 0 TIUIKitCore/TIUIKitCore.podspec | 2 + 13 files changed, 84 insertions(+), 68 deletions(-) rename {TIUIElements => TIUIKitCore}/Sources/Alerts/Factories/AlertFactory.swift (100%) rename {TIUIElements => TIUIKitCore}/Sources/Alerts/Models/AlertAction.swift (100%) rename {TIUIElements => TIUIKitCore}/Sources/Alerts/Models/AlertDescriptor.swift (100%) rename {TIUIElements => TIUIKitCore}/Sources/Alerts/Protocols/AlertPresentable.swift (100%) rename {TIUIElements => TIUIKitCore}/Sources/Alerts/Protocols/AlertPresentationContext.swift (100%) rename {TIUIElements => TIUIKitCore}/Sources/Alerts/Protocols/UIKitAlertContext.swift (100%) rename {TIUIElements/Sources/Alerts/Helpers => TIUIKitCore/Sources/Extensions/Alerts}/AlertDescriptor+Helpers.swift (100%) rename {TIUIElements/Sources/Alerts/Helpers => TIUIKitCore/Sources/Extensions/Alerts}/UIAlertController+AlertPresentable.swift (100%) rename {TIUIElements/Sources/Alerts/Protocols => TIUIKitCore/Sources/Localization/AlertsLocalization}/AlertLocalizationProvider.swift (100%) rename {TIUIElements/Sources/Alerts/Models => TIUIKitCore/Sources/Localization/AlertsLocalization}/DefaultAlertLocalizationProvider.swift (100%) diff --git a/TIUIElements/README.md b/TIUIElements/README.md index 923d26f4..1814f815 100644 --- a/TIUIElements/README.md +++ b/TIUIElements/README.md @@ -127,68 +127,6 @@ class ViewController: UITableViewController, CollapsibleViewsContainer {

-# AlertsFactory -Use to present alerts in a few lines of code. Can be used for UIKit and SwiftUI -> You can initialize `AlertsFactory` with your own *LocalizationProvider* or use `DefaultAlertLocalizationProvider` - -## Your view or view controller must implement PresentationContext protocol -There are `UIKitAlertContext` protocol that are designed to make it easier to work with `AlertPresentationContext` protocol. By default, no changes need to be made for UIKit view controllers to make them conform to `UIKitAlertContext`. - -## Custom alerts -```swift -// Presents alert -func presentAlert() { - factory - .alert(title: "Alert's title", - message: "Alert's message", - tint: .systemBlue, - actions: [ - AlertAction(title: "Ok", style: .default, action: nil), - AlertAction(title: "Cancel", style: .cancel, action: nil) - ]) - .present(on: self) -} - -// Presents sheet alert -func presentSheetAlert() { - factory - .sheetAlert(title: "Alert's title", - message: "Alert's message", - tint: .systemBlue, - actions: [ - AlertAction(title: "Ok", style: .default, action: nil), - AlertAction(title: "Cancel", style: .cancel, action: nil) - ]) - .present(on: self) -} -``` - -## Default alerts -```swift -// Ok alert -func presentOkAlert() { - factory - .okAlert(title: "Title", message: "Message") - .present(on: self) -} - -// Retry alert -func presentRetryAlert() { - factory - .retryAlert(title: "Title", message: "Message") { [weak self] in - self?.presentOkAlert() - } - .present(on: self) -} - -// Dialogue alert -func presentDialogueAlert() { - factory - .dialogueAlert(title: "Title", message: "Message") - .present(on: self) -} -``` - # Installation via SPM You can install this framework as a target of LeadKit. diff --git a/TIUIKitCore/README.md b/TIUIKitCore/README.md index 96d028a7..bbd3408d 100644 --- a/TIUIKitCore/README.md +++ b/TIUIKitCore/README.md @@ -4,11 +4,87 @@ Core UI elements: protocols, views and helpers. # Protocols -- [InitializableView](InitializableView/InitializableView.swift) - protocol with methods that should be called in constructor methods of view. -- [Animatable](Animatable/Animatable.swift) - protocol that ensures that specific type support basic animation actions. -- [ActivityIndicator](ActivityIndicator/ActivityIndicator.swift) - basic activity indicator. -- [ActivityIndicatorHolder](ActivityIndicator/ActivityIndicatorHolder.swift) - placeholder view, containing activity indicator. +- [InitializableView](Sources/InitializableView/InitializableViewProtocol.swift) - protocol with methods that should be called in constructor methods of view. +- [Animatable](Sources/ActivityIndicator/Animatable.swift) - protocol that ensures that specific type support basic animation actions. +- [ActivityIndicator](Sources/ActivityIndicator/ActivityIndicator.swift) - basic activity indicator. +- [ActivityIndicatorHolder](Sources/ActivityIndicator/ActivityIndicatorHolder.swift) - placeholder view, containing activity indicator. +- [AlertLocalizationProvider](Sources/Localization/AlertsLocalization/AlertLocalizationProvider.swift) - protocol that ensures that localization for alerts will be provided. +- [AlertPresentable](Sources/Alerts/Protocols/AlertPresentable.swift) - protocol indicates that certain object can present alerts. +- [AlertPresentationContext](Sources/Alerts/Protocols/AlertPresentationContext.swift) - protocol indicates that certain object can present alert on top of itself. +- [UIKitAlertContext](Sources/Alerts/Protocols/UIKitAlertContext.swift) - helper to provide easy conformance of `UIViewController` to `AlertPresentationContext`. -# Views +# Models -- [BaseInitializableView](BaseInitializableView/BaseInitializableView.swift) - UIView conformance to InitializableView. +- [DefaultAlertLocalizationProvider](Sources/Localization/AlertsLocalization/DefaultAlertLocalizationProvider.swift) - default localization provider for alerts. +- [AlertAction](Sources/Alerts/Models/AlertAction.swift) - representation of alert action +- [AlertDescriptor](Sources/Alerts/Models/AlertDescriptor.swift) - struct that holds all needed information to present alert + +# Factories + +- [AlertsFactory](Sources/Alerts/Factories/AlertFactory.swift) - factory to present alerts. + +## AlertsFactory +Use to present alerts in a few lines of code. Can be used for UIKit and SwiftUI +> You can initialize `AlertsFactory` with your own *LocalizationProvider* or use `DefaultAlertLocalizationProvider` + +### Your view or view controller must implement PresentationContext protocol +There are `UIKitAlertContext` protocol that are designed to make it easier to work with `AlertPresentationContext` protocol. By default, no changes need to be made for UIKit view controllers to make them conform to `UIKitAlertContext`. + +## Custom alerts +```swift +// Presents alert +func presentAlert() { + factory + .alert(title: "Alert's title", + message: "Alert's message", + tint: .systemBlue, + actions: [ + AlertAction(title: "Ok", style: .default, action: nil), + AlertAction(title: "Cancel", style: .cancel, action: nil) + ]) + .present(on: self) +} + +// Presents sheet alert +func presentSheetAlert() { + factory + .sheetAlert(title: "Alert's title", + message: "Alert's message", + tint: .systemBlue, + actions: [ + AlertAction(title: "Ok", style: .default, action: nil), + AlertAction(title: "Cancel", style: .cancel, action: nil) + ]) + .present(on: self) +} +``` + +## Default alerts +```swift +// Ok alert +func presentOkAlert() { + factory + .okAlert(title: "Title", message: "Message") + .present(on: self) +} + +// Retry alert +func presentRetryAlert() { + factory + .retryAlert(title: "Title", message: "Message") { [weak self] in + self?.presentOkAlert() + } + .present(on: self) +} + +// Dialogue alert +func presentDialogueAlert() { + factory + .dialogueAlert(title: "Title", message: "Message") + .present(on: self) +} +``` + +# Installation via SPM + +You can install this framework as a target of LeadKit. diff --git a/TIUIElements/Sources/Alerts/Factories/AlertFactory.swift b/TIUIKitCore/Sources/Alerts/Factories/AlertFactory.swift similarity index 100% rename from TIUIElements/Sources/Alerts/Factories/AlertFactory.swift rename to TIUIKitCore/Sources/Alerts/Factories/AlertFactory.swift diff --git a/TIUIElements/Sources/Alerts/Models/AlertAction.swift b/TIUIKitCore/Sources/Alerts/Models/AlertAction.swift similarity index 100% rename from TIUIElements/Sources/Alerts/Models/AlertAction.swift rename to TIUIKitCore/Sources/Alerts/Models/AlertAction.swift diff --git a/TIUIElements/Sources/Alerts/Models/AlertDescriptor.swift b/TIUIKitCore/Sources/Alerts/Models/AlertDescriptor.swift similarity index 100% rename from TIUIElements/Sources/Alerts/Models/AlertDescriptor.swift rename to TIUIKitCore/Sources/Alerts/Models/AlertDescriptor.swift diff --git a/TIUIElements/Sources/Alerts/Protocols/AlertPresentable.swift b/TIUIKitCore/Sources/Alerts/Protocols/AlertPresentable.swift similarity index 100% rename from TIUIElements/Sources/Alerts/Protocols/AlertPresentable.swift rename to TIUIKitCore/Sources/Alerts/Protocols/AlertPresentable.swift diff --git a/TIUIElements/Sources/Alerts/Protocols/AlertPresentationContext.swift b/TIUIKitCore/Sources/Alerts/Protocols/AlertPresentationContext.swift similarity index 100% rename from TIUIElements/Sources/Alerts/Protocols/AlertPresentationContext.swift rename to TIUIKitCore/Sources/Alerts/Protocols/AlertPresentationContext.swift diff --git a/TIUIElements/Sources/Alerts/Protocols/UIKitAlertContext.swift b/TIUIKitCore/Sources/Alerts/Protocols/UIKitAlertContext.swift similarity index 100% rename from TIUIElements/Sources/Alerts/Protocols/UIKitAlertContext.swift rename to TIUIKitCore/Sources/Alerts/Protocols/UIKitAlertContext.swift diff --git a/TIUIElements/Sources/Alerts/Helpers/AlertDescriptor+Helpers.swift b/TIUIKitCore/Sources/Extensions/Alerts/AlertDescriptor+Helpers.swift similarity index 100% rename from TIUIElements/Sources/Alerts/Helpers/AlertDescriptor+Helpers.swift rename to TIUIKitCore/Sources/Extensions/Alerts/AlertDescriptor+Helpers.swift diff --git a/TIUIElements/Sources/Alerts/Helpers/UIAlertController+AlertPresentable.swift b/TIUIKitCore/Sources/Extensions/Alerts/UIAlertController+AlertPresentable.swift similarity index 100% rename from TIUIElements/Sources/Alerts/Helpers/UIAlertController+AlertPresentable.swift rename to TIUIKitCore/Sources/Extensions/Alerts/UIAlertController+AlertPresentable.swift diff --git a/TIUIElements/Sources/Alerts/Protocols/AlertLocalizationProvider.swift b/TIUIKitCore/Sources/Localization/AlertsLocalization/AlertLocalizationProvider.swift similarity index 100% rename from TIUIElements/Sources/Alerts/Protocols/AlertLocalizationProvider.swift rename to TIUIKitCore/Sources/Localization/AlertsLocalization/AlertLocalizationProvider.swift diff --git a/TIUIElements/Sources/Alerts/Models/DefaultAlertLocalizationProvider.swift b/TIUIKitCore/Sources/Localization/AlertsLocalization/DefaultAlertLocalizationProvider.swift similarity index 100% rename from TIUIElements/Sources/Alerts/Models/DefaultAlertLocalizationProvider.swift rename to TIUIKitCore/Sources/Localization/AlertsLocalization/DefaultAlertLocalizationProvider.swift diff --git a/TIUIKitCore/TIUIKitCore.podspec b/TIUIKitCore/TIUIKitCore.podspec index 93baeac2..2da9cae0 100644 --- a/TIUIKitCore/TIUIKitCore.podspec +++ b/TIUIKitCore/TIUIKitCore.podspec @@ -12,4 +12,6 @@ Pod::Spec.new do |s| s.source_files = s.name + '/Sources/**/*' s.framework = 'UIKit' + + s.dependency 'TISwiftUtils', s.version.to_s end