From 046e45357c9175c7c0a924a1179bb82b0078d46f Mon Sep 17 00:00:00 2001 From: Hasan Sultan <52581466+hasansultan92@users.noreply.github.com> Date: Sun, 15 Sep 2024 02:13:42 -0400 Subject: [PATCH] fix: window container size adjusts for vertical and horizontal --- .../Views/Hover Window/WindowPreview.swift | 2 +- .../WindowPreviewHoverContainer.swift | 65 +++++++++---------- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/DockDoor/Views/Hover Window/WindowPreview.swift b/DockDoor/Views/Hover Window/WindowPreview.swift index 17680ea..f421c31 100644 --- a/DockDoor/Views/Hover Window/WindowPreview.swift +++ b/DockDoor/Views/Hover Window/WindowPreview.swift @@ -60,7 +60,7 @@ struct WindowPreview: View { .overlay(isSelected ? CustomizableFluidGradientView().opacity(0.125) : nil) } } - .frame(maxWidth: calculatedSize.width, maxHeight: calculatedSize.height, alignment: .leading) + .frame(width: calculatedSize.width, height: calculatedSize.height, alignment: .leading) } var body: some View { diff --git a/DockDoor/Views/Hover Window/WindowPreviewHoverContainer.swift b/DockDoor/Views/Hover Window/WindowPreviewHoverContainer.swift index 1ab271f..a72eec5 100644 --- a/DockDoor/Views/Hover Window/WindowPreviewHoverContainer.swift +++ b/DockDoor/Views/Hover Window/WindowPreviewHoverContainer.swift @@ -51,28 +51,7 @@ struct WindowPreviewHoverContainer: View { WindowDismissalContainer(appName: appName, mouseLocation: mouseLocation, bestGuessMonitor: bestGuessMonitor, dockPosition: dockPosition) } - - ScrollViewReader { scrollProxy in - ScrollView(.vertical, showsIndicators: false) { - windowPreviewGrid - .padding(14) - .onAppear { - if !hasAppeared { - hasAppeared.toggle() - runUIUpdates() - } - } - .onChange(of: windowSwitcherCoordinator.currIndex) { newIndex in - withAnimation { - scrollProxy.scrollTo("\(appName)-\(newIndex)", anchor: .center) - } - } - .onChange(of: windows) { _ in - runUIUpdates() - } - } - .opacity(showWindows ? 1 : 0.8) - } + gridContainer() } .padding(.top, (!windowSwitcherCoordinator.windowSwitcherActive && appNameStyle == .default && showAppName) ? 25 : 0) // Provide space above the window preview for the Embedded (default) title style when hovering over the Dock. .dockStyle(cornerRadius: 16) @@ -84,17 +63,36 @@ struct WindowPreviewHoverContainer: View { .frame(maxWidth: bestGuessMonitor.visibleFrame.width - 15, maxHeight: bestGuessMonitor.visibleFrame.height - 15) } - private var windowPreviewGrid: some View { - Group { - if GridLayoutVertical() { - LazyHGrid(rows: calculateGridInfo(), spacing: 25) { - gridContent - } - } else { - LazyVGrid(columns: calculateGridInfo(), spacing: 25) { - gridContent - } + private func gridContainer() -> some View { + ScrollViewReader { scrollProxy in + ScrollView(.vertical, showsIndicators: false) { + Group { + if GridLayoutVertical() { + LazyHGrid(rows: calculateGridInfo(), spacing: 25) { + gridContent + } + } else { + LazyVGrid(columns: calculateGridInfo(), spacing: 25) { + gridContent + } + } + }.padding(14) + .onAppear { + if !hasAppeared { + hasAppeared.toggle() + runUIUpdates() + } + } + .onChange(of: windowSwitcherCoordinator.currIndex) { newIndex in + withAnimation { + scrollProxy.scrollTo("\(appName)-\(newIndex)", anchor: .center) + } + } + .onChange(of: windows) { _ in + runUIUpdates() + } } + .opacity(showWindows ? 1 : 0.8) } } @@ -256,6 +254,7 @@ struct WindowPreviewHoverContainer: View { } else { numberOfColumns = maxNumberOfColumns } - return Array(repeating: GridItem(.flexible(), spacing: 16), count: numberOfColumns) + return mouseLocation == nil ? Array(repeating: GridItem(.fixed(maxColumnWidth), spacing: 16), count: numberOfColumns) : + Array(repeating: GridItem(.flexible(), spacing: 16), count: numberOfColumns) } }