Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ra1028 committed May 16, 2024
1 parent 9b6548d commit b276b6a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
30 changes: 16 additions & 14 deletions Sources/PlaybookUI/Internal/Views/CatalogDrawer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@ import SwiftUI

@available(iOS 15.0, *)
internal struct CatalogDrawer: View {
@EnvironmentObject
private var catalogState: CatalogState

var body: some View {
ZStack {
CatalogTop()
Drawer(isCollapsed: $catalogState.isSearchPainCollapsed)
Drawer()
}
}
}

@available(iOS 15.0, *)
private struct Drawer: View {
@Binding
var isCollapsed: Bool
@EnvironmentObject
private var catalogState: CatalogState

var body: some View {
let isCollapsed = catalogState.isSearchPainCollapsed

GeometryReader { geometry in
let drawerWidth =
geometry.safeAreaInsets.leading
Expand All @@ -33,17 +32,20 @@ private struct Drawer: View {
.opacity(isCollapsed ? 0 : 0.3)
.ignoresSafeArea()
.onTapGesture {
isCollapsed = true
catalogState.isSearchPainCollapsed = true
}

HStack(spacing: 0) {
CatalogSearchPane()
.frame(width: drawerWidth)
.background {
Rectangle()
.ignoresSafeArea()
.shadow(radius: 10)
}
CatalogSearchPane { data in
catalogState.selected = data
catalogState.isSearchPainCollapsed = true
}
.frame(width: drawerWidth)
.background {
Rectangle()
.ignoresSafeArea()
.shadow(radius: 10)
}

Spacer.zero
}
Expand Down
5 changes: 3 additions & 2 deletions Sources/PlaybookUI/Internal/Views/CatalogSearchPane.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ internal struct CatalogSearchPane: View {
@FocusState
private var isFocused

let onSelect: (SelectData) -> Void

var body: some View {
HStack(spacing: 0) {
VStack(spacing: 0) {
Expand Down Expand Up @@ -59,8 +61,7 @@ internal struct CatalogSearchPane: View {
data: data,
isSelected: catalogState.selected?.id == select.id
) {
catalogState.selected = select
catalogState.isSearchPainCollapsed = true
onSelect(select)
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions Sources/PlaybookUI/Internal/Views/CatalogSplit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ internal struct CatalogSplit: View {
}
}

CatalogSearchPane()
.frame(width: sidebarWidth)
.offset(x: catalogState.isSearchPainCollapsed ? -sidebarWidth : 0)
CatalogSearchPane { data in
catalogState.selected = data
}
.frame(width: sidebarWidth)
.offset(x: catalogState.isSearchPainCollapsed ? -sidebarWidth : 0)
}
}
.animation(.snappy(duration: 0.3), value: catalogState.isSearchPainCollapsed)
Expand Down
2 changes: 1 addition & 1 deletion Tests/CatalogScenarios.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ enum CatalogScenarios: ScenarioProvider {
catalogState.expandedKinds = ["Kind 1"]
catalogState.isSearchPainCollapsed = false

return CatalogSearchPane()
return CatalogSearchPane { _ in }
.environmentObject(SearchState(playbook: .test))
.environmentObject(catalogState)
}
Expand Down

0 comments on commit b276b6a

Please sign in to comment.