Skip to content

Commit dc4b9f9

Browse files
authored
Redesign Story Row (#239)
This is just simply updating the design of the Story Row to match what it looks like on Android. Also just getting back my SwiftUI chops a bit.
1 parent 8cb6731 commit dc4b9f9

File tree

11 files changed

+236
-26
lines changed

11 files changed

+236
-26
lines changed

Diff for: ios/HackerNews.xcodeproj/project.pbxproj

+8-4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
C3AC6AD42CB6E806006BD22D /* HackerNewsPreviewTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3AC6AD32CB6E7FD006BD22D /* HackerNewsPreviewTest.swift */; };
4343
C3AC6AD62CB6E81B006BD22D /* HackerNewsSnapshotTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3AC6AD52CB6E816006BD22D /* HackerNewsSnapshotTest.swift */; };
4444
C3AC6AD92CB6E8F7006BD22D /* SnapshottingTests in Frameworks */ = {isa = PBXBuildFile; productRef = C3AC6AD82CB6E8F7006BD22D /* SnapshottingTests */; };
45+
EC072CAA2CEF02A500D00B8D /* StoryRowV2.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC072CA92CEF02A500D00B8D /* StoryRowV2.swift */; };
4546
/* End PBXBuildFile section */
4647

4748
/* Begin PBXContainerItemProxy section */
@@ -136,6 +137,7 @@
136137
C3AC6AD32CB6E7FD006BD22D /* HackerNewsPreviewTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HackerNewsPreviewTest.swift; sourceTree = "<group>"; };
137138
C3AC6AD52CB6E816006BD22D /* HackerNewsSnapshotTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HackerNewsSnapshotTest.swift; sourceTree = "<group>"; };
138139
C3AC6AD72CB6E854006BD22D /* HackerNews.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = HackerNews.xctestplan; sourceTree = "<group>"; };
140+
EC072CA92CEF02A500D00B8D /* StoryRowV2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoryRowV2.swift; sourceTree = "<group>"; };
139141
/* End PBXFileReference section */
140142

141143
/* Begin PBXFrameworksBuildPhase section */
@@ -179,6 +181,7 @@
179181
A413E8582A8D868500C0F867 /* ThemedButtonStyle.swift */,
180182
A434C2DF2A8E75960002F488 /* WebView.swift */,
181183
A47309B52AA7D1F600201376 /* CommentRow.swift */,
184+
EC072CA92CEF02A500D00B8D /* StoryRowV2.swift */,
182185
);
183186
path = Components;
184187
sourceTree = "<group>";
@@ -561,6 +564,7 @@
561564
A42705AB2A4296BA0057E439 /* PostListScreen.swift in Sources */,
562565
A40DC1FA2C20D8B60055B920 /* Previews.swift in Sources */,
563566
A427057F2A4293B10057E439 /* ContentView.swift in Sources */,
567+
EC072CAA2CEF02A500D00B8D /* StoryRowV2.swift in Sources */,
564568
1DF162032A436E7B001A3F76 /* DateUtils.swift in Sources */,
565569
A413E8572A8C40E800C0F867 /* Extensions.swift in Sources */,
566570
A42705A92A4294EB0057E439 /* LoginScreen.swift in Sources */,
@@ -740,7 +744,7 @@
740744
CURRENT_PROJECT_VERSION = 1;
741745
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
742746
DEVELOPMENT_ASSET_PATHS = "\"HackerNews/Preview Content\"";
743-
DEVELOPMENT_TEAM = 62J2XHNK9T;
747+
DEVELOPMENT_TEAM = LSPBG7SYXK;
744748
"ENABLE_HARDENED_RUNTIME[sdk=macosx*]" = YES;
745749
ENABLE_PREVIEWS = YES;
746750
ENABLE_USER_SCRIPT_SANDBOXING = NO;
@@ -762,7 +766,7 @@
762766
MARKETING_VERSION = 3.4;
763767
OTHER_LDFLAGS = "-fprofile-instr-generate";
764768
OTHER_SWIFT_FLAGS = "-profile-generate -profile-coverage-mapping";
765-
PRODUCT_BUNDLE_IDENTIFIER = "com.emerge.hn.Hacker-News";
769+
PRODUCT_BUNDLE_IDENTIFIER = com.emergetools.hackernews;
766770
PRODUCT_NAME = "$(TARGET_NAME)";
767771
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
768772
SUPPORTS_MACCATALYST = YES;
@@ -783,7 +787,7 @@
783787
CURRENT_PROJECT_VERSION = 1;
784788
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
785789
DEVELOPMENT_ASSET_PATHS = "\"HackerNews/Preview Content\"";
786-
DEVELOPMENT_TEAM = 62J2XHNK9T;
790+
DEVELOPMENT_TEAM = LSPBG7SYXK;
787791
"ENABLE_HARDENED_RUNTIME[sdk=macosx*]" = YES;
788792
ENABLE_PREVIEWS = YES;
789793
ENABLE_USER_SCRIPT_SANDBOXING = NO;
@@ -803,7 +807,7 @@
803807
);
804808
LIBRARY_SEARCH_PATHS = "\"$(PROJECT_DIR)/Frameworks/Reaper.xcframework\"";
805809
MARKETING_VERSION = 3.4;
806-
PRODUCT_BUNDLE_IDENTIFIER = "com.emerge.hn.Hacker-News";
810+
PRODUCT_BUNDLE_IDENTIFIER = com.emergetools.hackernews;
807811
PRODUCT_NAME = "$(TARGET_NAME)";
808812
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
809813
SUPPORTS_MACCATALYST = YES;

Diff for: ios/HackerNews.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"originHash" : "261ff378e7b15ed930e88adbf89034cf9764a714ee554702b7a367bba1734bed",
2+
"originHash" : "24bebf1b8a7941b76197956b51b5401cff81714df8139818d77c9821c372f77b",
33
"pins" : [
44
{
55
"identity" : "accessibilitysnapshot",
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" : "0xFF",
9+
"green" : "0xFF",
10+
"red" : "0xFE"
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" : "0xFF",
27+
"green" : "0xFF",
28+
"red" : "0xFE"
29+
}
30+
},
31+
"idiom" : "universal"
32+
}
33+
],
34+
"info" : {
35+
"author" : "xcode",
36+
"version" : 1
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"colors" : [
3+
{
4+
"color" : {
5+
"color-space" : "srgb",
6+
"components" : {
7+
"alpha" : "1.000",
8+
"blue" : "0x6F",
9+
"green" : "0x47",
10+
"red" : "0xEF"
11+
}
12+
},
13+
"idiom" : "universal"
14+
}
15+
],
16+
"info" : {
17+
"author" : "xcode",
18+
"version" : 1
19+
}
20+
}

Diff for: ios/HackerNews/Components/StoryRowV2.swift

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//
2+
// StoryRowV2.swift
3+
// HackerNews
4+
//
5+
// Created by Rikin Marfatia on 11/20/24.
6+
//
7+
8+
import SwiftUI
9+
10+
struct StoryRowV2: View {
11+
@ObservedObject var model: AppViewModel
12+
let story: Story
13+
14+
var body: some View {
15+
VStack(alignment: .leading, spacing: 8) {
16+
let author = story.by!
17+
Text("@\(author)")
18+
.foregroundColor(.hnOrange)
19+
.fontWeight(/*@START_MENU_TOKEN@*/.bold/*@END_MENU_TOKEN@*/)
20+
Text(story.title)
21+
.font(.headline)
22+
HStack(spacing: 16) {
23+
HStack(spacing: 4) {
24+
Image(systemName: "arrow.up")
25+
.foregroundColor(.green)
26+
Text("\(story.score)")
27+
}
28+
HStack(spacing: 4) {
29+
Image(systemName: "clock")
30+
.foregroundColor(.purple)
31+
Text(story.displayableDate)
32+
}
33+
Spacer()
34+
// Comment Button
35+
Button(action: {
36+
print("Pressed comment button for: \(story.id)")
37+
model.navigationPath.append(
38+
AppViewModel.AppNavigation.storyComments(story: story)
39+
)
40+
}) {
41+
HStack(spacing: 4) {
42+
Image(systemName: "message.fill")
43+
Text("\(story.commentCount)")
44+
}
45+
}
46+
.buttonStyle(.bordered)
47+
.buttonBorderShape(ButtonBorderShape.capsule)
48+
}
49+
}
50+
}
51+
}
52+
53+
struct StoryRowV2_Preview: PreviewProvider {
54+
static var previews: some View {
55+
let fakeStory = PreviewHelpers.makeFakeStory(index: 0, descendants: 3, kids: [1, 2, 3])
56+
PreviewVariants {
57+
StoryRowV2(model: AppViewModel(), story: fakeStory)
58+
}
59+
}
60+
}

Diff for: ios/HackerNews/Screens/BookmarksScreen.swift

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// BookmarksScreen.swift
3+
// HackerNews
4+
//
5+
// Created by Rikin Marfatia on 11/22/24.
6+
//
7+
8+
import Foundation
9+
import SwiftUI
10+
11+
struct BookmarksScreen: View {
12+
var body: some View {
13+
Text("Hello Bookmarks")
14+
}
15+
}

Diff for: ios/HackerNews/Screens/PostListScreen.swift

+20-18
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,26 @@ struct PostListScreen: View {
2121
.scaleEffect(2)
2222
case .loaded(let stories):
2323
List(stories, id: \.id) { story in
24-
let navigationValue: AppViewModel.AppNavigation = {
25-
if let url = story.makeUrl() {
26-
return AppViewModel.AppNavigation.webLink(url: url, title: story.title)
27-
} else {
28-
return AppViewModel.AppNavigation.storyComments(story: story)
29-
}
30-
}()
31-
NavigationLink(
32-
value: navigationValue,
33-
label: {
34-
StoryRow(
35-
appState: appState,
36-
story: story,
37-
index: stories.firstIndex(where: { $0.id == story.id })!
38-
)
39-
}
40-
)
41-
.listRowBackground(Color.clear)
24+
let navigationValue: AppViewModel.AppNavigation = {
25+
if let url = story.makeUrl() {
26+
return AppViewModel.AppNavigation.webLink(url: url, title: story.title)
27+
} else {
28+
return AppViewModel.AppNavigation.storyComments(story: story)
29+
}
30+
}()
31+
32+
StoryRowV2(
33+
model: appState,
34+
story: story
35+
)
36+
.background(
37+
NavigationLink(
38+
value: navigationValue,
39+
label: {}
40+
)
41+
.opacity(0.0)
42+
)
43+
.listRowBackground(Color.clear)
4244
}
4345
.listStyle(.plain)
4446
}

Diff for: ios/HackerNews/Screens/SettingsScreen.swift

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// SettingsScreen.swift
3+
// HackerNews
4+
//
5+
// Created by Rikin Marfatia on 11/22/24.
6+
//
7+
8+
import Foundation
9+
import SwiftUI
10+
11+
struct SettingsScreen: View {
12+
var body: some View {
13+
Text("Hello Settings")
14+
}
15+
}

Diff for: ios/HackerNews/Screens/StoriesScreen.swift

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// StoriesScreen.swift
3+
// HackerNews
4+
//
5+
// Created by Rikin Marfatia on 11/22/24.
6+
//
7+
8+
import Foundation
9+
import SwiftUI
10+
11+
struct StoriesScreen: View {
12+
@ObservedObject var model: AppViewModel
13+
14+
var body: some View {
15+
switch model.storiesState {
16+
case .notStarted, .loading:
17+
ProgressView()
18+
case .loaded(let stories):
19+
List(stories, id: \.id) { story in
20+
StoryRowV2(model: model, story: story)
21+
.background(
22+
NavigationLink(
23+
value: navigationForStory(story: story),
24+
label: {}
25+
)
26+
.opacity(0.0)
27+
)
28+
.listRowBackground(Color.clear)
29+
}
30+
.listStyle(.plain)
31+
}
32+
}
33+
34+
private func navigationForStory(story: Story) -> AppViewModel.AppNavigation {
35+
if let url = story.makeUrl() {
36+
return AppViewModel.AppNavigation.webLink(url: url, title: story.title)
37+
} else {
38+
return AppViewModel.AppNavigation.storyComments(story: story)
39+
}
40+
}
41+
}
42+
43+
44+
#Preview {
45+
StoriesScreen(model: AppViewModel())
46+
}

Diff for: ios/HackerNews/Screens/StoryRow.swift

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//
2+
// StoryRow.swift
3+
// HackerNews
4+
//
5+
// Created by Rikin Marfatia on 11/20/24.
6+
//
7+
8+
import SwiftUI
9+

Diff for: ios/HackerNews/Utils/Colors.swift

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import Foundation
99
import SwiftUI
1010

1111
struct HNColors {
12-
static let orange = Color("HNOrange")
13-
static let background = Color("Background")
14-
static let commentBackground = Color("CommentBackground")
12+
static let orange = Color("HNOrange")
13+
static let background = Color("Background")
14+
static let commentBackground = Color("CommentBackground")
15+
static let red = Color("HNRed")
1516
}

0 commit comments

Comments
 (0)