Skip to content

Commit 9df17ce

Browse files
committed
Fix sidebar size change
1 parent 2ff68a2 commit 9df17ce

File tree

3 files changed

+67
-54
lines changed

3 files changed

+67
-54
lines changed

CodeEdit/Features/InspectorArea/HistoryInspector/HistoryInspectorItemView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct HistoryInspectorItemView: View {
2525
}
2626

2727
var body: some View {
28-
CommitListItemView(commit: commit)
28+
CommitListItemView(commit: commit, showRef: false)
2929
.popover(isPresented: showPopup, arrowEdge: .leading) {
3030
HistoryPopoverView(commit: commit)
3131
}

CodeEdit/Features/NavigatorArea/SourceControlNavigator/History/Views/CommitListItemView.swift

Lines changed: 60 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import SwiftUI
1010
struct CommitListItemView: View {
1111

1212
var commit: GitCommit
13-
var width: CGFloat?
13+
var showRef: Bool
14+
var width: CGFloat
1415

1516
private var defaultAvatar: some View {
1617
Image(systemName: "person.crop.circle.fill")
@@ -47,70 +48,80 @@ struct CommitListItemView: View {
4748
@Environment(\.openURL)
4849
private var openCommit
4950

50-
init(commit: GitCommit) {
51+
init(commit: GitCommit, showRef: Bool) {
5152
self.commit = commit
52-
//self.width = width
53-
//print("CGFloat", width)
53+
self.showRef = showRef
54+
self.width = 0
55+
}
56+
57+
init(commit: GitCommit, showRef: Bool, width: CGFloat) {
58+
self.commit = commit
59+
self.showRef = showRef
60+
self.width = width
5461
}
5562

5663
var body: some View {
5764
HStack(alignment: .top) {
58-
AsyncImage(url: URL(string: "https://www.gravatar.com/avatar/\(generateAvatarHash())")) { phase in
59-
if let image = phase.image {
60-
image
61-
.resizable()
62-
.clipShape(Circle())
63-
.frame(width: 32, height: 32)
64-
.help(commit.author)
65-
} else if phase.error != nil {
66-
defaultAvatar
67-
.help(commit.author)
68-
} else {
69-
defaultAvatar
70-
.help(commit.author)
65+
if width > 360 {
66+
AsyncImage(url: URL(string: "https://www.gravatar.com/avatar/\(generateAvatarHash())")) { phase in
67+
if let image = phase.image {
68+
image
69+
.resizable()
70+
.clipShape(Circle())
71+
.frame(width: 32, height: 32)
72+
.help(commit.author)
73+
} else if phase.error != nil {
74+
defaultAvatar
75+
.help(commit.author)
76+
} else {
77+
defaultAvatar
78+
.help(commit.author)
79+
}
7180
}
7281
}
7382
VStack(alignment: .leading, spacing: 0) {
7483
HStack {
7584
Text(commit.author)
7685
.fontWeight(.bold)
7786
.font(.system(size: 11))
78-
if !commit.refs.isEmpty {
79-
HStack {
80-
ForEach(commit.refs, id: \.self) { ref in
81-
HStack {
82-
Image.branch
83-
.imageScale(.small)
84-
.foregroundColor(.primary)
85-
Text(ref)
86-
.font(.system(size: 10, design: .monospaced))
87+
if showRef {
88+
if !commit.refs.isEmpty {
89+
HStack {
90+
ForEach(commit.refs, id: \.self) { ref in
91+
HStack {
92+
Image.branch
93+
.imageScale(.small)
94+
.foregroundColor(.primary)
95+
Text(ref)
96+
.font(.system(size: 10, design: .monospaced))
97+
}
98+
.background(
99+
RoundedRectangle(cornerRadius: 3)
100+
.padding(.vertical, -1)
101+
.padding(.horizontal, -2.5)
102+
.foregroundColor(Color(nsColor: .quaternaryLabelColor))
103+
)
104+
.padding(.trailing, 2.5)
87105
}
88-
.background(
89-
RoundedRectangle(cornerRadius: 3)
90-
.padding(.vertical, -1)
91-
.padding(.horizontal, -2.5)
92-
.foregroundColor(Color(nsColor: .quaternaryLabelColor))
93-
)
94-
.padding(.trailing, 2.5)
95106
}
96107
}
97-
}
98-
99-
if !commit.tag.isEmpty {
100-
HStack {
101-
Image.breakpoint
102-
.imageScale(.small)
103-
.foregroundColor(.primary)
104-
Text(commit.tag)
105-
.font(.system(size: 10, design: .monospaced))
108+
109+
if !commit.tag.isEmpty {
110+
HStack {
111+
Image.breakpoint
112+
.imageScale(.small)
113+
.foregroundColor(.primary)
114+
Text(commit.tag)
115+
.font(.system(size: 10, design: .monospaced))
116+
}
117+
.background(
118+
RoundedRectangle(cornerRadius: 3)
119+
.padding(.vertical, -1)
120+
.padding(.horizontal, -2.5)
121+
.foregroundColor(Color(nsColor: .selectedContentBackgroundColor))
122+
)
123+
.padding(.trailing, 2.5)
106124
}
107-
.background(
108-
RoundedRectangle(cornerRadius: 3)
109-
.padding(.vertical, -1)
110-
.padding(.horizontal, -2.5)
111-
.foregroundColor(Color(nsColor: .selectedContentBackgroundColor))
112-
)
113-
.padding(.trailing, 2.5)
114125
}
115126
}
116127

CodeEdit/Features/NavigatorArea/SourceControlNavigator/History/Views/SourceControlNavigatorHistoryView.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct SourceControlNavigatorHistoryView: View {
2121
@State var commitHistory: [GitCommit] = []
2222

2323
@State var selection: GitCommit?
24-
@State var width: CGFloat?
24+
@State private var width: CGFloat = CGFloat.zero
2525

2626
func updateCommitHistory() async {
2727
do {
@@ -60,7 +60,7 @@ struct SourceControlNavigatorHistoryView: View {
6060
ZStack {
6161
List(selection: $selection) {
6262
ForEach(commitHistory) { commit in
63-
CommitListItemView(commit: commit)
63+
CommitListItemView(commit: commit, showRef: true, width: width)
6464
.tag(commit)
6565
.listRowSeparator(.hidden)
6666
}
@@ -70,9 +70,11 @@ struct SourceControlNavigatorHistoryView: View {
7070
CommitDetailsView(commit: $selection)
7171
}
7272
}
73+
.onAppear {
74+
self.width = geometry.size.width
75+
}
7376
.onChange(of: geometry.size.width) { newWidth in
74-
width = newWidth
75-
print(newWidth)
77+
self.width = newWidth
7678
}
7779
}
7880
}

0 commit comments

Comments
 (0)