Skip to content

Commit 25a5234

Browse files
authored
Comment Screen Design Pass (#283)
Redesigning the Comments Screen + Adding some Functionality with Upvotes and Commenting
1 parent cafe655 commit 25a5234

File tree

19 files changed

+671
-294
lines changed

19 files changed

+671
-294
lines changed

ios/HackerNews.xcodeproj/project.pbxproj

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
A495A6662CED57BB009A2A6B /* SnapshotTesting in Frameworks */ = {isa = PBXBuildFile; productRef = A495A6652CED57BB009A2A6B /* SnapshotTesting */; };
3232
A495A6682CED5800009A2A6B /* SwiftSnapshotTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = A495A6672CED57FA009A2A6B /* SwiftSnapshotTest.swift */; };
3333
A495B2952BFEA11B00A8A8A9 /* Reaper in Frameworks */ = {isa = PBXBuildFile; productRef = A495B2942BFEA11B00A8A8A9 /* Reaper */; };
34-
A49933942AA28B5900DED8B1 /* StoryViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A48C0DE92A9819E00034CC0A /* StoryViewModel.swift */; };
35-
A49933952AA28B6500DED8B1 /* StoryScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = A48C0DE62A9818A50034CC0A /* StoryScreen.swift */; };
34+
A49933942AA28B5900DED8B1 /* CommentsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A48C0DE92A9819E00034CC0A /* CommentsViewModel.swift */; };
35+
A49933952AA28B6500DED8B1 /* CommentsScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = A48C0DE62A9818A50034CC0A /* CommentsScreen.swift */; };
3636
A4BED5C32AD5E083001642B3 /* (null) in Frameworks */ = {isa = PBXBuildFile; };
3737
A4BED5C42AD5E083001642B3 /* (null) in Frameworks */ = {isa = PBXBuildFile; };
3838
A4D28AEE2C237E2A007F20D0 /* SnapshotPreferences in Frameworks */ = {isa = PBXBuildFile; productRef = A4D28AED2C237E2A007F20D0 /* SnapshotPreferences */; };
@@ -47,6 +47,7 @@
4747
EC29FDA92CFFD0B5007B1AE9 /* SettingsScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC29FDA82CFFD0B5007B1AE9 /* SettingsScreen.swift */; };
4848
EC70E1612D1DD82B00582023 /* HNWebClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC70E1602D1DD82B00582023 /* HNWebClient.swift */; };
4949
EC882BB22D23A8A70065FEC0 /* LoginScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC882BB12D23A8A70065FEC0 /* LoginScreen.swift */; };
50+
ECC0BC8C2D39CDCB00ABB263 /* CommentComposer.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECC0BC8B2D39CDCB00ABB263 /* CommentComposer.swift */; };
5051
ECCE8F262D03815300349733 /* Pager.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECCE8F252D03815300349733 /* Pager.swift */; };
5152
ECE608562D338B3E008B1618 /* ibm_plex_sans_medium.ttf in Resources */ = {isa = PBXBuildFile; fileRef = ECE608532D338B3E008B1618 /* ibm_plex_sans_medium.ttf */; };
5253
ECE608572D338B3E008B1618 /* ibm_plex_sans_bold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = ECE608522D338B3E008B1618 /* ibm_plex_sans_bold.ttf */; };
@@ -139,8 +140,8 @@
139140
A45C2C9C2A5DDE25009BC030 /* primary_category.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = primary_category.txt; sourceTree = "<group>"; };
140141
A45C2CBB2A5F0A41009BC030 /* Hacker-News-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = "Hacker-News-Info.plist"; sourceTree = SOURCE_ROOT; };
141142
A47309B52AA7D1F600201376 /* CommentRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentRow.swift; sourceTree = "<group>"; };
142-
A48C0DE62A9818A50034CC0A /* StoryScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoryScreen.swift; sourceTree = "<group>"; };
143-
A48C0DE92A9819E00034CC0A /* StoryViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoryViewModel.swift; sourceTree = "<group>"; };
143+
A48C0DE62A9818A50034CC0A /* CommentsScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentsScreen.swift; sourceTree = "<group>"; };
144+
A48C0DE92A9819E00034CC0A /* CommentsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentsViewModel.swift; sourceTree = "<group>"; };
144145
A495A6672CED57FA009A2A6B /* SwiftSnapshotTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftSnapshotTest.swift; sourceTree = "<group>"; };
145146
C3AC6AD32CB6E7FD006BD22D /* HackerNewsPreviewTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HackerNewsPreviewTest.swift; sourceTree = "<group>"; };
146147
C3AC6AD52CB6E816006BD22D /* HackerNewsSnapshotTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HackerNewsSnapshotTest.swift; sourceTree = "<group>"; };
@@ -151,6 +152,7 @@
151152
EC29FDA82CFFD0B5007B1AE9 /* SettingsScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsScreen.swift; sourceTree = "<group>"; };
152153
EC70E1602D1DD82B00582023 /* HNWebClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HNWebClient.swift; sourceTree = "<group>"; };
153154
EC882BB12D23A8A70065FEC0 /* LoginScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginScreen.swift; sourceTree = "<group>"; };
155+
ECC0BC8B2D39CDCB00ABB263 /* CommentComposer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentComposer.swift; sourceTree = "<group>"; };
154156
ECCE8F252D03815300349733 /* Pager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Pager.swift; sourceTree = "<group>"; };
155157
ECE608522D338B3E008B1618 /* ibm_plex_sans_bold.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = ibm_plex_sans_bold.ttf; sourceTree = "<group>"; };
156158
ECE608532D338B3E008B1618 /* ibm_plex_sans_medium.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = ibm_plex_sans_medium.ttf; sourceTree = "<group>"; };
@@ -201,6 +203,7 @@
201203
A47309B52AA7D1F600201376 /* CommentRow.swift */,
202204
EC072CA92CEF02A500D00B8D /* StoryRowV2.swift */,
203205
EC0B1C742D1A34110000C3AC /* CommentsHeader.swift */,
206+
ECC0BC8B2D39CDCB00ABB263 /* CommentComposer.swift */,
204207
);
205208
path = Components;
206209
sourceTree = "<group>";
@@ -232,7 +235,7 @@
232235
isa = PBXGroup;
233236
children = (
234237
A42705AA2A4296BA0057E439 /* FeedScreen.swift */,
235-
A48C0DE62A9818A50034CC0A /* StoryScreen.swift */,
238+
A48C0DE62A9818A50034CC0A /* CommentsScreen.swift */,
236239
EC29FDA62CFFD074007B1AE9 /* BookmarksScreen.swift */,
237240
EC29FDA82CFFD0B5007B1AE9 /* SettingsScreen.swift */,
238241
EC882BB12D23A8A70065FEC0 /* LoginScreen.swift */,
@@ -382,7 +385,7 @@
382385
isa = PBXGroup;
383386
children = (
384387
A42705A62A42949D0057E439 /* AppViewModel.swift */,
385-
A48C0DE92A9819E00034CC0A /* StoryViewModel.swift */,
388+
A48C0DE92A9819E00034CC0A /* CommentsViewModel.swift */,
386389
);
387390
path = Models;
388391
sourceTree = "<group>";
@@ -614,11 +617,12 @@
614617
A427057D2A4293B10057E439 /* HNApp.swift in Sources */,
615618
EC70E1612D1DD82B00582023 /* HNWebClient.swift in Sources */,
616619
A434C2E02A8E75960002F488 /* WebView.swift in Sources */,
617-
A49933942AA28B5900DED8B1 /* StoryViewModel.swift in Sources */,
620+
A49933942AA28B5900DED8B1 /* CommentsViewModel.swift in Sources */,
618621
A47309B62AA7D1F600201376 /* CommentRow.swift in Sources */,
619-
A49933952AA28B6500DED8B1 /* StoryScreen.swift in Sources */,
622+
A49933952AA28B6500DED8B1 /* CommentsScreen.swift in Sources */,
620623
A42705A72A42949D0057E439 /* AppViewModel.swift in Sources */,
621624
A42705AD2A429D2E0057E439 /* HNApi.swift in Sources */,
625+
ECC0BC8C2D39CDCB00ABB263 /* CommentComposer.swift in Sources */,
622626
A423B0682BAE05FB00267DDB /* NetworkDebugger.swift in Sources */,
623627
ECCE8F262D03815300349733 /* Pager.swift in Sources */,
624628
);

ios/HackerNews/Assets.xcassets/Color.colorset/Contents.json renamed to ios/HackerNews/Assets.xcassets/Colors/Background.colorset/Contents.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"components" : {
77
"alpha" : "1.000",
88
"blue" : "0xFF",
9-
"green" : "0xFF",
10-
"red" : "0xFE"
9+
"green" : "0xF9",
10+
"red" : "0xF9"
1111
}
1212
},
1313
"idiom" : "universal"
@@ -23,9 +23,9 @@
2323
"color-space" : "srgb",
2424
"components" : {
2525
"alpha" : "1.000",
26-
"blue" : "0xFF",
27-
"green" : "0xFF",
28-
"red" : "0xFE"
26+
"blue" : "0x17",
27+
"green" : "0x13",
28+
"red" : "0x12"
2929
}
3030
},
3131
"idiom" : "universal"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"author" : "xcode",
4+
"version" : 1
5+
}
6+
}

ios/HackerNews/Assets.xcassets/HNOrange.colorset/Contents.json renamed to ios/HackerNews/Assets.xcassets/Colors/HNOrange.colorset/Contents.json

File renamed without changes.

ios/HackerNews/Assets.xcassets/HNRed.colorset/Contents.json renamed to ios/HackerNews/Assets.xcassets/Colors/HNRed.colorset/Contents.json

File renamed without changes.

ios/HackerNews/Assets.xcassets/Background.colorset/Contents.json renamed to ios/HackerNews/Assets.xcassets/Colors/OnBackground.colorset/Contents.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"color-space" : "srgb",
66
"components" : {
77
"alpha" : "1.000",
8-
"blue" : "0.940",
9-
"green" : "0.960",
10-
"red" : "0.960"
8+
"blue" : "0x20",
9+
"green" : "0x1C",
10+
"red" : "0x1A"
1111
}
1212
},
1313
"idiom" : "universal"
@@ -23,9 +23,9 @@
2323
"color-space" : "srgb",
2424
"components" : {
2525
"alpha" : "1.000",
26-
"blue" : "0.130",
27-
"green" : "0.120",
28-
"red" : "0.110"
26+
"blue" : "0xE8",
27+
"green" : "0xE2",
28+
"red" : "0xE2"
2929
}
3030
},
3131
"idiom" : "universal"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"colors" : [
3+
{
4+
"color" : {
5+
"color-space" : "srgb",
6+
"components" : {
7+
"alpha" : "1.000",
8+
"blue" : "0xF3",
9+
"green" : "0xED",
10+
"red" : "0xEE"
11+
}
12+
},
13+
"idiom" : "universal"
14+
},
15+
{
16+
"appearances" : [
17+
{
18+
"appearance" : "luminosity",
19+
"value" : "dark"
20+
}
21+
],
22+
"color" : {
23+
"color-space" : "srgb",
24+
"components" : {
25+
"alpha" : "1.000",
26+
"blue" : "0x24",
27+
"green" : "0x20",
28+
"red" : "0x1E"
29+
}
30+
},
31+
"idiom" : "universal"
32+
}
33+
],
34+
"info" : {
35+
"author" : "xcode",
36+
"version" : 1
37+
}
38+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//
2+
// CommentComposer.swift
3+
// HackerNews
4+
//
5+
// Created by Rikin Marfatia on 1/16/25.
6+
//
7+
import SwiftUI
8+
9+
struct CommentComposer: View {
10+
@Binding var state: CommentComposerState
11+
let goToLogin: () -> Void
12+
let sendComment: () -> Void
13+
14+
var body: some View {
15+
VStack {
16+
HStack(alignment: .center) {
17+
Image(systemName: "message.fill")
18+
.font(.system(size: 12))
19+
Text("Add a comment")
20+
.font(.custom("IBMPlexSans-Medium", size: 12))
21+
}
22+
TextField(
23+
"Words of wisdom",
24+
text: $state.text
25+
)
26+
.textFieldStyle(.roundedBorder)
27+
.disabled(AuthState.loggedOut == state.loggedIn)
28+
.submitLabel(.send)
29+
.onSubmit {
30+
sendComment()
31+
}
32+
}
33+
.padding(16)
34+
.background {
35+
Color
36+
.clear
37+
.background(.ultraThinMaterial)
38+
.containerShape(
39+
.rect(
40+
cornerRadii: RectangleCornerRadii(
41+
topLeading: 24,
42+
bottomLeading: 0,
43+
bottomTrailing: 0,
44+
topTrailing: 24
45+
),
46+
style: .continuous
47+
)
48+
)
49+
}
50+
.onTapGesture {
51+
if (AuthState.loggedOut == state.loggedIn) {
52+
goToLogin()
53+
}
54+
}
55+
}
56+
}
57+
58+
#Preview {
59+
CommentComposer(
60+
state: .constant(
61+
CommentComposerState(
62+
parentId: "",
63+
goToUrl: "",
64+
hmac: "",
65+
loggedIn: .loggedIn,
66+
text: ""
67+
)
68+
),
69+
goToLogin: {},
70+
sendComment: {}
71+
)
72+
}

ios/HackerNews/Components/CommentRow.swift

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,55 +11,56 @@ import SwiftUI
1111
private let maxIndentationLevel: Int = 5
1212

1313
struct CommentRow: View {
14-
let state: CommentInfo
15-
let likeComment: (CommentInfo) -> Void
14+
let state: CommentState
15+
let likeComment: (CommentState) -> Void
16+
let toggleComment: () -> Void
1617

1718
var body: some View {
1819
VStack(alignment: .leading) {
1920
// first row
2021
HStack {
2122
// author
2223
Text("@\(state.user)")
23-
.font(.caption)
24-
.fontWeight(.bold)
24+
.font(.custom("IBMPlexMono-Bold", size: 12))
2525
// time
2626
HStack(alignment: .center, spacing: 4.0) {
2727
Image(systemName: "clock")
28+
.font(.system(size: 12))
2829
Text(state.age)
30+
.font(.custom("IBMPlexSans-Medium", size: 12))
2931
}
3032
.font(.caption)
3133
// collapse/expand
3234
Image(systemName: "chevron.up.chevron.down")
33-
.font(.caption)
35+
.font(.system(size: 12))
3436
// space between
3537
Spacer()
3638
// upvote
3739
Button(action: {
3840
likeComment(state)
3941
}) {
4042
Image(systemName: "arrow.up")
41-
.font(.caption2)
43+
.font(.system(size: 12))
44+
.padding(.horizontal, 8)
45+
.padding(.vertical, 4)
4246
}
43-
.padding(
44-
EdgeInsets(
45-
top: 4.0,
46-
leading: 8.0,
47-
bottom: 4.0,
48-
trailing: 8.0
49-
)
50-
)
51-
.background(HNColors.background)
52-
.foregroundStyle(.black)
47+
.background(state.upvoted ? .green.opacity(0.2) : .white.opacity(0.2))
48+
.foregroundStyle(state.upvoted ? .green : .onBackground)
5349
.clipShape(Capsule())
5450
}
55-
51+
5652
// Comment Body
57-
Text(state.text.strippingHTML())
58-
.font(.caption)
53+
if (!state.hidden) {
54+
Text(state.text.strippingHTML())
55+
.font(.custom("IBMPlexMono-Regular", size: 12))
56+
}
5957
}
6058
.padding(8.0)
61-
.background(HNColors.commentBackground)
59+
.background(.surface)
6260
.clipShape(RoundedRectangle(cornerRadius: 16.0))
61+
.onTapGesture {
62+
toggleComment()
63+
}
6364
.padding(
6465
EdgeInsets(
6566
top: 0,
@@ -75,7 +76,8 @@ struct CommentView_Preview: PreviewProvider {
7576
PreviewVariants {
7677
CommentRow(
7778
state: PreviewHelpers.makeFakeComment(),
78-
likeComment: {_ in}
79+
likeComment: {_ in},
80+
toggleComment: {}
7981
)
8082
}
8183
}
@@ -87,7 +89,8 @@ struct CommentViewIndentation_Preview: PreviewProvider {
8789
ForEach(0..<6) { index in
8890
CommentRow(
8991
state: PreviewHelpers.makeFakeComment(level: index),
90-
likeComment: {_ in}
92+
likeComment: {_ in},
93+
toggleComment: {}
9194
)
9295
.previewLayout(.sizeThatFits)
9396
.previewDisplayName("Indentation \(index)")

0 commit comments

Comments
 (0)