Skip to content

Commit

Permalink
Merge pull request #29 from oversizedev/develop
Browse files Browse the repository at this point in the history
Format code
  • Loading branch information
aromanov91 authored Jun 8, 2023
2 parents 2987a96 + cd3b154 commit cbe6381
Show file tree
Hide file tree
Showing 9 changed files with 286 additions and 638 deletions.
78 changes: 38 additions & 40 deletions Sources/OversizeUI/Controls/HUD/HUD.swift
Original file line number Diff line number Diff line change
@@ -1,52 +1,50 @@
//
// Copyright © 2023 Alexander Romanov
// File.swift, created on 22.05.2023
//
//

import SwiftUI

public struct HUD<Title, Icon>: View where Title: View, Icon: View {

@Environment(\.screenSize) var screenSize

private let text: String?

private let title: Title?
private let icon: Icon?

private let isAutoHide: Bool

@Binding private var isPresented: Bool

@State private var bottomOffset: CGFloat = 0
@State private var opacity: CGFloat = 0

// MARK: Initializers

public init(
autoHide: Bool = true,
isPresented: Binding<Bool>,
@ViewBuilder title: () -> Title,
@ViewBuilder icon: () -> Icon
) {
self._isPresented = isPresented
self.text = nil
_isPresented = isPresented
text = nil
self.title = title()
self.icon = icon()
self.isAutoHide = autoHide
isAutoHide = autoHide
}



public var body: some View {
HStack(spacing: .xSmall) {
if icon != nil {
icon
}
if let text {

Text(text)
.body(.medium)
.foregroundColor(.onSurfaceHighEmphasis)

} else if let title {
title
}
Expand All @@ -70,7 +68,7 @@ public struct HUD<Title, Icon>: View where Title: View, Icon: View {
}
})
}

private func presentAnimated() {
withAnimation {
bottomOffset = 0
Expand All @@ -84,7 +82,7 @@ public struct HUD<Title, Icon>: View where Title: View, Icon: View {
}
}
}

private func dismissAnimated() {
withAnimation {
bottomOffset = -200
Expand All @@ -99,11 +97,11 @@ public extension HUD where Title == EmptyView, Icon == EmptyView {
autoHide: Bool = true,
isPresented: Binding<Bool>
) {
self._isPresented = isPresented
_isPresented = isPresented
self.text = text
self.title = nil
self.icon = nil
self.isAutoHide = autoHide
title = nil
icon = nil
isAutoHide = autoHide
}
}

Expand All @@ -114,10 +112,10 @@ public extension HUD where Title == EmptyView {
isPresented: Binding<Bool>,
@ViewBuilder icon: () -> Icon
) {
self._isPresented = isPresented
_isPresented = isPresented
self.text = text
self.title = nil
self.isAutoHide = autoHide
title = nil
isAutoHide = autoHide
self.icon = icon()
}
}
Expand All @@ -128,41 +126,41 @@ public extension HUD where Icon == EmptyView {
isPresented: Binding<Bool>,
@ViewBuilder title: () -> Title
) {
self._isPresented = isPresented
self.text = nil
_isPresented = isPresented
text = nil
self.title = title()
self.icon = nil
self.isAutoHide = autoHide
icon = nil
isAutoHide = autoHide
}
}

public extension View {
func hud(_ text: String, isPresented: Binding<Bool>) -> some View {
self.overlay(alignment: .top) {
overlay(alignment: .top) {
HUD(text, isPresented: isPresented)
}
}
func hud<Icon: View>(_ text: String, isPresented: Binding<Bool>, @ViewBuilder icon: () -> Icon) -> some View {
self.overlay(alignment: .top) {

func hud(_ text: String, isPresented: Binding<Bool>, @ViewBuilder icon: () -> some View) -> some View {
overlay(alignment: .top) {
HUD(text, isPresented: isPresented, icon: icon)
}
}
func hud<Title: View>(isPresented: Binding<Bool>, @ViewBuilder title: () -> Title) -> some View {
self.overlay(alignment: .top) {

func hud(isPresented: Binding<Bool>, @ViewBuilder title: () -> some View) -> some View {
overlay(alignment: .top) {
HUD(isPresented: isPresented, title: title)
}
}
func hud<Title: View, Icon: View>(isPresented: Binding<Bool>, @ViewBuilder title: () -> Title, @ViewBuilder icon: () -> Icon) -> some View {
self.overlay(alignment: .top) {

func hud(isPresented: Binding<Bool>, @ViewBuilder title: () -> some View, @ViewBuilder icon: () -> some View) -> some View {
overlay(alignment: .top) {
HUD(isPresented: isPresented, title: title, icon: icon)
}
}

func hudLoader(_ text: String = "Loading", isPresented: Binding<Bool>) -> some View {
self.overlay(alignment: .top) {
overlay(alignment: .top) {
HUD(text, autoHide: false, isPresented: isPresented) {
ProgressView()
}
Expand Down
73 changes: 35 additions & 38 deletions Sources/OversizeUI/Controls/Loader/LoaderOverlayView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public struct LoaderOverlayView: View {
private let isShowBackground: Bool

@Binding var isLoading: Bool


@State private var jump = false
@State private var rotationImage = false
Expand Down Expand Up @@ -48,28 +47,11 @@ public struct LoaderOverlayView: View {
}

public var body: some View {
VStack {
Spacer()


VStack {
Spacer()

if surface {
Surface {
VStack(spacing: 20) {
containedView()

if showText {
Text(text.isEmpty ? "Loading" : text)
.headline(.semibold)
.onSurfaceDisabledForegroundColor()
.offset(y: 8)
}
}
.padding()
}
.surfaceStyle(.primary)
.elevation(.z4)
} else {
if surface {
Surface {
VStack(spacing: 20) {
containedView()

Expand All @@ -81,24 +63,39 @@ public struct LoaderOverlayView: View {
}
}
.padding()
.background {
Capsule()
.fillSurfaceSecondary()
}
.surfaceStyle(.primary)
.elevation(.z4)
} else {
VStack(spacing: 20) {
containedView()

if showText {
Text(text.isEmpty ? "Loading" : text)
.headline(.semibold)
.onSurfaceDisabledForegroundColor()
.offset(y: 8)
}
}

Spacer()
.padding()
.background {
Capsule()
.fillSurfaceSecondary()
}
}
.frame(
maxWidth: .infinity,
maxHeight: .infinity,
alignment: .center
)
.background(
.ultraThinMaterial.opacity(isShowBackground ? 1 : 0),
ignoresSafeAreaEdges: .all
)
.opacity(isLoading ? 1 : 0)

Spacer()
}
.frame(
maxWidth: .infinity,
maxHeight: .infinity,
alignment: .center
)
.background(
.ultraThinMaterial.opacity(isShowBackground ? 1 : 0),
ignoresSafeAreaEdges: .all
)
.opacity(isLoading ? 1 : 0)
}

@ViewBuilder
Expand Down Expand Up @@ -134,7 +131,7 @@ public struct LoaderOverlayView: View {

public extension View {
func loader(_ text: String? = nil, isPresented: Binding<Bool>) -> some View {
self.overlay {
overlay {
LoaderOverlayView(text: text ?? "", isLoading: isPresented)
}
}
Expand Down
Loading

0 comments on commit cbe6381

Please sign in to comment.