Skip to content

Commit 0ac2bae

Browse files
committed
Disabled animation for utility area when hiding interface
- Added command "open.drawer.no.animation" to command manager. This will toggle the utility area, without an animation. - Added option possibility of no animation to SplitViewItem.Update - Added struct SplitViewItemCanAnimateViewTraitKey and function splitViewCanAnimate to SplitViewModifiers. These optionally allow disabling animations for SplitViews. - Updated "Hide Interface", WorkspaceView and UtilityAreaViewModel to accommodate these changes
1 parent 25f1681 commit 0ac2bae

6 files changed

Lines changed: 34 additions & 3 deletions

File tree

CodeEdit/Features/Documents/Controllers/CodeEditWindowController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ final class CodeEditWindowController: NSWindowController, NSToolbarDelegate, Obs
276276
toggleLastPanel(shouldAnimate: false)
277277
}
278278
if workspace?.utilityAreaModel?.isCollapsed != utilityAreaTargetState {
279-
CommandManager.shared.executeCommand("open.drawer")
279+
CommandManager.shared.executeCommand("open.drawer.no.animation")
280280
}
281281
if toolbarCollapsed != toolbarTargetState {
282282
toggleToolbar()

CodeEdit/Features/SplitView/Model/SplitViewItem.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,15 @@ class SplitViewItem: ObservableObject {
4545
/// - Parameter child: the view corresponding to the SplitViewItem.
4646
func update(child: _VariadicView.Children.Element) {
4747
self.item.canCollapse = child[SplitViewItemCanCollapseViewTraitKey.self]
48+
let canAnimate = child[SplitViewItemCanAnimateViewTraitKey.self]
4849
DispatchQueue.main.async {
4950
self.observers = []
50-
self.item.animator().isCollapsed = child[SplitViewItemCollapsedViewTraitKey.self].wrappedValue
51+
let collapsed = child[SplitViewItemCollapsedViewTraitKey.self].wrappedValue
52+
if canAnimate {
53+
self.item.animator().isCollapsed = collapsed
54+
} else {
55+
self.item.isCollapsed = collapsed
56+
}
5157
self.item.holdingPriority = child[SplitViewHoldingPriorityTraitKey.self]
5258
self.observers = self.createObservers()
5359
}

CodeEdit/Features/SplitView/Views/SplitViewModifiers.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ struct SplitViewHoldingPriorityTraitKey: _ViewTraitKey {
2323
static var defaultValue: NSLayoutConstraint.Priority = .defaultLow
2424
}
2525

26+
struct SplitViewItemCanAnimateViewTraitKey: _ViewTraitKey {
27+
static var defaultValue: Bool { true }
28+
}
29+
2630
extension View {
2731
func collapsed(_ value: Binding<Bool>) -> some View {
2832
self
@@ -43,4 +47,8 @@ extension View {
4347
self
4448
._trait(SplitViewHoldingPriorityTraitKey.self, priority)
4549
}
50+
51+
func splitViewCanAnimate(_ enabled: Binding<Bool>) -> some View {
52+
self._trait(SplitViewItemCanAnimateViewTraitKey.self, enabled.wrappedValue)
53+
}
4654
}

CodeEdit/Features/StatusBar/Views/StatusBarItems/StatusBarToggleUtilityAreaButton.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ internal struct StatusBarToggleUtilityAreaButton: View {
3131
id: "open.drawer",
3232
command: { [weak utilityAreaViewModel] in utilityAreaViewModel?.togglePanel() }
3333
)
34+
CommandManager.shared.addCommand(
35+
name: "Toggle Utility Area Without Animation",
36+
title: "Toggle Utility Area Without Animation",
37+
id: "open.drawer.no.animation",
38+
command: { [weak utilityAreaViewModel] in utilityAreaViewModel?.togglePanel(animation: false) }
39+
)
3440
}
3541
}
3642
.onAppear {
@@ -40,6 +46,12 @@ internal struct StatusBarToggleUtilityAreaButton: View {
4046
id: "open.drawer",
4147
command: { [weak utilityAreaViewModel] in utilityAreaViewModel?.togglePanel() }
4248
)
49+
CommandManager.shared.addCommand(
50+
name: "Toggle Utility Area Without Animation",
51+
title: "Toggle Utility Area Without Animation",
52+
id: "open.drawer.no.animation",
53+
command: { [weak utilityAreaViewModel] in utilityAreaViewModel?.togglePanel(animation: false) }
54+
)
4355
}
4456
}
4557
}

CodeEdit/Features/UtilityArea/ViewModels/UtilityAreaViewModel.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class UtilityAreaViewModel: ObservableObject {
2121
/// Indicates whether debugger is collapse or not
2222
@Published var isCollapsed: Bool = false
2323

24+
/// Indicates whether collapse animation should be enabled when utility area is toggled
25+
@Published var animateCollapse: Bool = true
26+
2427
/// Returns true when the drawer is visible
2528
@Published var isMaximized: Bool = false
2629

@@ -47,7 +50,8 @@ class UtilityAreaViewModel: ObservableObject {
4750
workspace.addToWorkspaceState(key: .utilityAreaMaximized, value: isMaximized)
4851
}
4952

50-
func togglePanel() {
53+
func togglePanel(animation: Bool = true) {
54+
self.animateCollapse = animation
5155
self.isMaximized = false
5256
self.isCollapsed.toggle()
5357
}

CodeEdit/WorkspaceView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ struct WorkspaceView: View {
6868
Rectangle()
6969
.collapsable()
7070
.collapsed($utilityAreaViewModel.isCollapsed)
71+
.splitViewCanAnimate($utilityAreaViewModel.animateCollapse)
7172
.opacity(0)
7273
.frame(idealHeight: 260)
7374
.frame(minHeight: 100)

0 commit comments

Comments
 (0)