Skip to content

Commit

Permalink
Add async image for notice
Browse files Browse the repository at this point in the history
  • Loading branch information
aromanov91 committed Oct 7, 2022
1 parent eb2a8d2 commit f401157
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions Sources/OversizeUI/Controls/Notice/NoticeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import SwiftUI

public struct NoticeView<A>: View where A: View {
let image: Image?
let imageURL: URL?
let title: String
let subtitle: String?
let actions: Group<A>?
Expand All @@ -15,25 +16,39 @@ public struct NoticeView<A>: View where A: View {
public init(_ title: String,
subtitle: String? = nil,
image: Image? = nil,
imageURL: URL? = nil,
@ViewBuilder actions: @escaping () -> A,
closeAction: (() -> Void)? = nil)
{
self.image = image
self.title = title
self.subtitle = subtitle
self.image = image
self.imageURL = imageURL
self.actions = Group { actions() }
self.closeAction = closeAction
}

public var body: some View {
Surface {
VStack(alignment: .leading, spacing: .xxSmall) {
HStack {
HStack(spacing: .xSmall) {
image.map {
$0
.resizable()
.frame(width: 32, height: 32)
}

imageURL.map { url in
AsyncImage(url: url) {
$0
.resizable()
.frame(width: 32, height: 32)
} placeholder: {
Circle()
.fillBackgroundTertiary()
.frame(width: 32, height: 32)
}
}

Text(title)
.headline(.bold)
Expand Down Expand Up @@ -80,11 +95,13 @@ public extension NoticeView where A == EmptyView {
init(_ title: String,
subtitle: String? = nil,
image: Image? = nil,
imageURL: URL? = nil,
closeAction: (() -> Void)? = nil)
{
self.image = image
self.title = title
self.subtitle = subtitle
self.image = image
self.imageURL = imageURL
actions = nil
self.closeAction = closeAction
}
Expand Down

0 comments on commit f401157

Please sign in to comment.