Skip to content

Commit

Permalink
Add notice view
Browse files Browse the repository at this point in the history
  • Loading branch information
aromanov91 committed Sep 11, 2022
1 parent 6a46785 commit 0ffecab
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 11 deletions.
4 changes: 0 additions & 4 deletions Example/Shared/ComponentsList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,6 @@ struct SegmentedControlPreview: View {
Spacer()
}.padding()
}
// .navigationBar("Title", style: .fixed) {
// BarButton(type: .back)
// } trailingBar: {} bottomBar: {}

.scrollWithNavigationBar("App", style: .fixed($offset), background: Color.backgroundSecondary) {
BarButton(type: .back)
} trailingBar: {} bottomBar: {}
Expand Down
2 changes: 1 addition & 1 deletion Sources/OversizeUI/Controls/Button/Button.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public struct OversizeButtonStyle: ButtonStyle {

@ViewBuilder
func background(for role: ButtonRole?) -> some View {
if type != .tertiary {
if type != .quaternary {
switch controlBorderShape {
case .capsule:
Capsule()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import SwiftUI

@available(iOS 14.0, *)
public struct ModalNavigationBar<LeadingBar: View, TrailingBar: View, BottomBar: View, TitleLabel: View>: View {
private let leadingBar: () -> LeadingBar?
private let trailingBar: () -> TrailingBar?
Expand Down
133 changes: 133 additions & 0 deletions Sources/OversizeUI/Controls/Notice/NoticeView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
//
// Copyright © 2022 Alexander Romanov
// NoticeView.swift
//

import SwiftUI

public struct NoticeView<A>: View where A: View {
let image: Image?
let title: String
let subtitle: String?
let actions: Group<A>?
let closeAction: (() -> Void)?

public init(_ title: String,
subtitle: String? = nil,
image: Image? = nil,
@ViewBuilder actions: @escaping () -> A,
closeAction: (() -> Void)? = nil)
{
self.image = image
self.title = title
self.subtitle = subtitle
self.actions = Group { actions() }
self.closeAction = closeAction
}

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

Text(title)
.headline(.bold)
.foregroundOnSurfaceHighEmphasis()
.multilineTextAlignment(.leading)
.padding(.trailing, closeAction != nil ? .medium : .zero)
}

subtitle.map { text in
Text(text)
.body(.medium)
.foregroundOnSurfaceMediumEmphasis()
.multilineTextAlignment(.leading)
}

if actions != nil {
HStack(spacing: .xSmall) {
actions
.buttonStyle(.primary)
.controlSize(.mini)
}
.padding(.top, .xxSmall)
}
}
.frame(maxWidth: .infinity, alignment: .leading)
}
.overlay(alignment: .topTrailing) {
if closeAction != nil {
Button {
closeAction?()
} label: {
Icon(.xMini, color: .onSurfaceHighEmphasis)
}
.buttonStyle(.tertiary(infinityWidth: false))
.controlBorderShape(.capsule)
.padding(.xSmall)
.controlSize(.mini)
}
}
}
}

public extension NoticeView where A == EmptyView {
init(_ title: String,
subtitle: String? = nil,
image: Image? = nil,
closeAction: (() -> Void)? = nil)
{
self.image = image
self.title = title
self.subtitle = subtitle
actions = nil
self.closeAction = closeAction
}
}

struct NoticeView_Previews: PreviewProvider {
static var previews: some View {


VStack(spacing: .small) {

NoticeView("Title")

NoticeView("Title", subtitle: "Subtitle")

NoticeView("Title", subtitle: "Subtitle") {
print("Ok Action")
}

NoticeView("Title") {
Button {
print("Ok")
} label: {
Text("Primay")
}
.accent()
}

NoticeView("Title", subtitle: "Subtitle") {
Button("Primay") {
print("Ok")
}
Button("Primay") {
print("Ok")
}
.buttonStyle(.tertiary)

} closeAction: {
print("Close")
}
}
.padding()
.background { Color.backgroundSecondary.ignoresSafeArea(.all) }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@

import SwiftUI

public struct SegmentedPickerSelector<Element: Equatable, Content, Selection>: View
where
Content: View,
Selection: View
{
public struct SegmentedPickerSelector<Element: Equatable, Content, Selection>: View where Content: View, Selection: View {
@Environment(\.theme) private var theme: ThemeSettings
@Environment(\.segmentedControlStyle) private var style
@Environment(\.controlRadius) var controlRadius: Radius
Expand Down

0 comments on commit 0ffecab

Please sign in to comment.