diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/HUDFeature.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/HUDFeature.xcscheme new file mode 100644 index 0000000000000000000000000000000000000000..525ae0a7d1bc1b2143f7633306249617a46b72ba --- /dev/null +++ b/.swiftpm/xcode/xcshareddata/xcschemes/HUDFeature.xcscheme @@ -0,0 +1,67 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Scheme + LastUpgradeVersion = "1410" + version = "1.3"> + <BuildAction + parallelizeBuildables = "YES" + buildImplicitDependencies = "YES"> + <BuildActionEntries> + <BuildActionEntry + buildForTesting = "YES" + buildForRunning = "YES" + buildForProfiling = "YES" + buildForArchiving = "YES" + buildForAnalyzing = "YES"> + <BuildableReference + BuildableIdentifier = "primary" + BlueprintIdentifier = "HUDFeature" + BuildableName = "HUDFeature" + BlueprintName = "HUDFeature" + ReferencedContainer = "container:"> + </BuildableReference> + </BuildActionEntry> + </BuildActionEntries> + </BuildAction> + <TestAction + buildConfiguration = "Debug" + selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" + selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + shouldUseLaunchSchemeArgsEnv = "YES"> + <Testables> + </Testables> + </TestAction> + <LaunchAction + buildConfiguration = "Debug" + selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" + selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + launchStyle = "0" + useCustomWorkingDirectory = "NO" + ignoresPersistentStateOnLaunch = "NO" + debugDocumentVersioning = "YES" + debugServiceExtension = "internal" + allowLocationSimulation = "YES"> + </LaunchAction> + <ProfileAction + buildConfiguration = "Release" + shouldUseLaunchSchemeArgsEnv = "YES" + savedToolIdentifier = "" + useCustomWorkingDirectory = "NO" + debugDocumentVersioning = "YES"> + <MacroExpansion> + <BuildableReference + BuildableIdentifier = "primary" + BlueprintIdentifier = "HUDFeature" + BuildableName = "HUDFeature" + BlueprintName = "HUDFeature" + ReferencedContainer = "container:"> + </BuildableReference> + </MacroExpansion> + </ProfileAction> + <AnalyzeAction + buildConfiguration = "Debug"> + </AnalyzeAction> + <ArchiveAction + buildConfiguration = "Release" + revealArchiveInOrganizer = "YES"> + </ArchiveAction> +</Scheme> diff --git a/Package.swift b/Package.swift index b1a31d8ceca11af4668be12669978f98874f69e5..85f80eb143901b1b4aacdb6c9a4c21ca34b734e0 100644 --- a/Package.swift +++ b/Package.swift @@ -52,6 +52,7 @@ let package = Package( .library(name: "PermissionsFeature", targets: ["PermissionsFeature"]), .library(name: "ContactListFeature", targets: ["ContactListFeature"]), .library(name: "RequestPermissionFeature", targets: ["RequestPermissionFeature"]), + .library(name: "HUDFeature", targets: ["HUDFeature"]), ], dependencies: [ .package( @@ -659,5 +660,13 @@ let package = Package( ], swiftSettings: swiftSettings ), + .target( + name: "HUDFeature", + dependencies: [ + .target(name: "AppResources"), + .target(name: "Shared"), + ], + swiftSettings: swiftSettings + ), ] ) diff --git a/Sources/HUDFeature/HUDModel.swift b/Sources/HUDFeature/HUDModel.swift new file mode 100644 index 0000000000000000000000000000000000000000..ee7a8925887faf86680a19fdd8d13a0afbb7e57a --- /dev/null +++ b/Sources/HUDFeature/HUDModel.swift @@ -0,0 +1,39 @@ +import AppResources + +public struct HUDModel { + var title: String? + var content: String? + var actionTitle: String? + var hasDotAnimation: Bool + var isAutoDismissable: Bool + var onTapClosure: (() -> Void)? + + public init( + title: String? = nil, + content: String? = nil, + actionTitle: String? = nil, + hasDotAnimation: Bool = false, + isAutoDismissable: Bool = false, + onTapClosure: (() -> Void)? = nil + ) { + self.title = title + self.content = content + self.actionTitle = actionTitle + self.onTapClosure = onTapClosure + self.hasDotAnimation = hasDotAnimation + self.isAutoDismissable = isAutoDismissable + } + + public init( + error: Error, + actionTitle: String? = Localized.Hud.Error.action, + onTapClosure: (() -> Void)? = nil + ) { + self.hasDotAnimation = false + self.actionTitle = actionTitle + self.onTapClosure = onTapClosure + self.title = Localized.Hud.Error.title + self.isAutoDismissable = onTapClosure == nil + self.content = error.localizedDescription + } +} diff --git a/Sources/HUDFeature/HUDView.swift b/Sources/HUDFeature/HUDView.swift new file mode 100644 index 0000000000000000000000000000000000000000..de96309c2eefad9a47d0eb5be5c03051a55c80a7 --- /dev/null +++ b/Sources/HUDFeature/HUDView.swift @@ -0,0 +1,91 @@ +import AppResources +import Shared +import SwiftUI + +struct HUDView: View { + var model: HUDModel + + var body: some View { + ZStack { + Color(Asset.neutralDark.color.withAlphaComponent(0.9)) + .ignoresSafeArea() + + VStack(spacing: 20) { + Spacer() + + if let title = model.title { + Text(title) + .foregroundColor(Color(Asset.neutralWhite.color)) + .font(Font(Fonts.Mulish.bold.font(size: 30.0))) + } + + if let content = model.content { + Text(content) + .foregroundColor(Color(Asset.neutralWhite.color)) + .font(Font(Fonts.Mulish.regular.font(size: 15.0))) + } + + if model.hasDotAnimation { + DotAnimation.SwiftUIView( + color: Asset.neutralWhite.color + ) + .fixedSize() + .frame(height: 20) + } + + Spacer() + + if let actionTitle = model.actionTitle, + let onTapClosure = model.onTapClosure { + CapsuleButton.SwiftUIView( + style: .seeThroughWhite, + title: actionTitle, + action: onTapClosure + ) + .fixedSize(horizontal: false, vertical: true) + } + } + .padding(.horizontal, 15) + .padding(.bottom, 20) + } + } +} + +#if DEBUG +struct HUDView_Previews: PreviewProvider { + struct Preview: View { + var hud: HUDView + + var body: some View { + ZStack { + LinearGradient( + colors: [ + Color(UIColor(red: 122/255, green: 235/255, blue: 239/255, alpha: 1)), + Color(UIColor(red: 56/255, green: 204/255, blue: 232/255, alpha: 1)), + Color(UIColor(red: 63/255, green: 186/255, blue: 253/255, alpha: 1)), + Color(UIColor(red: 98/255, green: 163/255, blue: 255/255, alpha: 1)), + ], + startPoint: .topTrailing, + endPoint: .bottomLeading + ) + .ignoresSafeArea() + + Image(uiImage: Asset.splash.image) + + hud + } + } + } + + static var previews: some View { + Preview(hud: HUDView(model: HUDModel( + title: "Title", + content: "Content", + actionTitle: "Action title", + hasDotAnimation: true, + isAutoDismissable: true, + onTapClosure: {} + ))) + } +} +#endif