Skip to content

Commit

Permalink
Merge pull request #30 from oversizedev/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
aromanov91 authored Jun 28, 2023
2 parents cbe6381 + 0aa3966 commit c7a3053
Show file tree
Hide file tree
Showing 9 changed files with 287 additions and 75 deletions.
2 changes: 1 addition & 1 deletion Sources/OversizeUI/Controls/HUD/HUD.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Copyright © 2023 Alexander Romanov
// File.swift, created on 22.05.2023
// HUD.swift, created on 22.05.2023
//

import SwiftUI
Expand Down
3 changes: 1 addition & 2 deletions Sources/OversizeUI/Controls/PageView/PageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public struct PageView<Content, LeadingBar, TrailingBar, TopToolbar, TitleLabel>
return control
}

public func bottomToolbar(style: PageViewBottomType = .shadow, ignoreSafeArea: Bool = true, @ViewBuilder bottomToolbar: @escaping () -> some View) -> some View {
public func bottomToolbar(style: PageViewBottomType = .shadow, @ViewBuilder bottomToolbar: @escaping () -> some View) -> some View {
VStack(spacing: .zero) {
overlay(
Group {
Expand Down Expand Up @@ -266,7 +266,6 @@ public struct PageView<Content, LeadingBar, TrailingBar, TopToolbar, TitleLabel>
.background(Color.surfacePrimary.shadowElevaton(style == .shadow ? .z2 : .z0))
}
}
.ignoresSafeArea(edges: ignoreSafeArea ? .bottom : .top)
}
}

Expand Down
14 changes: 0 additions & 14 deletions Sources/OversizeUI/Controls/Row/Row.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,6 @@

import SwiftUI

public protocol RowLeadingContentProtocol: View {}

public struct RowLeadingContent<Content: RowLeadingContentProtocol>: View { // where Content: View {
private let content: Content

public init(@ViewBuilder content: () -> Content) {
self.content = content()
}

public var body: some View {
content
}
}

public enum RowClearIconStyle {
case `default`, onSurface
}
Expand Down
18 changes: 9 additions & 9 deletions Sources/OversizeUI/Controls/SectionView/SectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public struct SectionView<Content: View>: View {
}
.padding(.horizontal, surfaceHorizontalPadding)
}
// .padding(.vertical, surfaceVerticalPaddingSize)
.padding(.vertical, surfaceVerticalPaddingSize)
}

private var titleView: some View {
Expand Down Expand Up @@ -190,14 +190,14 @@ public struct SectionView<Content: View>: View {
}
}

// private var surfaceVerticalPaddingSize: CGFloat {
// switch style {
// case .default:
// return Space.small.rawValue
// case .smallIndent, .edgeToEdge:
// return 2
// }
// }
private var surfaceVerticalPaddingSize: CGFloat {
switch style {
case .default:
return Space.small.rawValue
case .smallIndent, .edgeToEdge:
return 2
}
}
}

public extension SectionView {
Expand Down
136 changes: 112 additions & 24 deletions Sources/OversizeUI/Controls/Select/MultiSelect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import SwiftUI

// swiftlint:disable all
public struct MultiSelect<Element: Equatable, Content, Selection>: View
public struct MultiSelect<Element: Equatable, Content, Selection, Actions, ContentUnavailable>: View
where
Content: View,
Selection: View
Selection: View,
Actions: View,
ContentUnavailable: View
{
@Environment(\.theme) private var theme: ThemeSettings
public typealias Data = [Element]
Expand All @@ -18,27 +20,41 @@ public struct MultiSelect<Element: Equatable, Content, Selection>: View
private let data: Data
private let label: String
private let content: (Data.Element, Bool) -> Content
private let contentUnavailable: ContentUnavailable?
private let selectionView: (Data) -> Selection
@State private var showModal = false
@State private var showModal: Bool = false
@Binding private var showModalBinding: Bool?
@State var selectedIndexes: [Int] = []
let actions: Group<Actions>?

public init(_ label: String,
_ data: Data,
selection: Binding<Data>,
@ViewBuilder content: @escaping (Data.Element, Bool) -> Content,
@ViewBuilder selectionView: @escaping (Data) -> Selection)
{
public init(
_ label: String,
_ data: Data,
selection: Binding<Data>,
activeModal: Binding<Bool?> = .constant(nil),
@ViewBuilder content: @escaping (Data.Element, Bool) -> Content,
@ViewBuilder selectionView: @escaping (Data) -> Selection,
@ViewBuilder actions: @escaping () -> Actions,
@ViewBuilder contentUnavailable: () -> ContentUnavailable
) {
self.label = label
self.data = data
self.content = content
self.selectionView = selectionView
self.actions = Group { actions() }
self.contentUnavailable = contentUnavailable()
_showModalBinding = activeModal
_selection = selection
}

public var body: some View {
ZStack {
Button {
showModal.toggle()
if showModalBinding != nil {
showModalBinding?.toggle()
} else {
showModal.toggle()
}
} label: {
if selectedIndexes.isEmpty {
Text(label)
Expand Down Expand Up @@ -77,6 +93,11 @@ public struct MultiSelect<Element: Equatable, Content, Selection>: View
modal
#endif
}
.onChange(of: showModalBinding) { state in
if let state {
showModal = state
}
}
}
.onAppear {
if !selection.isEmpty {
Expand All @@ -92,28 +113,95 @@ public struct MultiSelect<Element: Equatable, Content, Selection>: View

private var modal: some View {
PageView(label) {
LazyVStack(alignment: .leading, spacing: .zero) {
ForEach(data.indices, id: \.self) { index in
let isSelected = selectedIndexes.contains(index)
if data.isEmpty, let contentUnavailable {
contentUnavailable
} else {
LazyVStack(alignment: .leading, spacing: .zero) {
ForEach(data.indices, id: \.self) { index in
let isSelected = selectedIndexes.contains(index)

Checkbox(isOn:
Binding(get: {
isSelected
}, set: { _ in
if isSelected, let elementIndex = selectedIndexes.firstIndex(of: index) {
selectedIndexes.remove(at: elementIndex)
} else {
selectedIndexes.append(index)
Checkbox(isOn: Binding(
get: { isSelected },
set: { _ in
if isSelected, let elementIndex = selectedIndexes.firstIndex(of: index) {
selectedIndexes.remove(at: elementIndex)
} else {
selectedIndexes.append(index)
}
let selectionItems = selectedIndexes.compactMap { data[$0] }
selection = selectionItems
}
let selectionItems = selectedIndexes.compactMap { data[$0] }
selection = selectionItems
}), label: {
), label: {
content(data[index], isSelected)
})
}
}
}
}
.leadingBar { BarButton(.close) }
.trailingBar { actions }
}
}

public extension MultiSelect where ContentUnavailable == Never {
init(
_ label: String,
_ data: Data,
selection: Binding<Data>,
activeModal: Binding<Bool?> = .constant(nil),
@ViewBuilder content: @escaping (Data.Element, Bool) -> Content,
@ViewBuilder selectionView: @escaping (Data) -> Selection,
@ViewBuilder actions: @escaping () -> Actions
) {
self.label = label
self.data = data
self.content = content
self.selectionView = selectionView
self.actions = Group { actions() }
contentUnavailable = nil
_showModalBinding = activeModal
_selection = selection
}
}

public extension MultiSelect where Actions == Never {
init(
_ label: String,
_ data: Data,
selection: Binding<Data>,
activeModal: Binding<Bool?> = .constant(nil),
@ViewBuilder content: @escaping (Data.Element, Bool) -> Content,
@ViewBuilder selectionView: @escaping (Data) -> Selection,
@ViewBuilder contentUnavailable: () -> ContentUnavailable
) {
self.label = label
self.data = data
self.content = content
self.selectionView = selectionView
actions = nil
self.contentUnavailable = contentUnavailable()
_showModalBinding = activeModal
_selection = selection
}
}

public extension MultiSelect where ContentUnavailable == Never, Actions == Never {
init(
_ label: String,
_ data: Data,
selection: Binding<Data>,
activeModal: Binding<Bool?> = .constant(nil),
@ViewBuilder content: @escaping (Data.Element, Bool) -> Content,
@ViewBuilder selectionView: @escaping (Data) -> Selection
) {
self.label = label
self.data = data
self.content = content
self.selectionView = selectionView
actions = nil
contentUnavailable = nil
_showModalBinding = activeModal
_selection = selection
}
}

Expand Down
Loading

0 comments on commit c7a3053

Please sign in to comment.