Skip to content

Commit 948c84e

Browse files
committed
优化用户名 hover/click 效果
1 parent 662910b commit 948c84e

File tree

6 files changed

+59
-35
lines changed

6 files changed

+59
-35
lines changed

V2exOS.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
0D033B40288D140C00129C9B /* TopicListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D033B3F288D140C00129C9B /* TopicListView.swift */; };
1515
0D033B42288D15CF00129C9B /* TopicDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D033B41288D15CF00129C9B /* TopicDetailView.swift */; };
1616
0D12614A28A94AA3009DBCE2 /* V2exAPI in Frameworks */ = {isa = PBXBuildFile; productRef = 0D12614928A94AA3009DBCE2 /* V2exAPI */; };
17+
0D139DE228E7E06C00E4CF88 /* UserName.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D139DE128E7E06C00E4CF88 /* UserName.swift */; };
1718
0D40378C28E6E4EA00B1A341 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D40378B28E6E4EA00B1A341 /* SettingsView.swift */; };
1819
0D40378E28E6E4F500B1A341 /* ProxyHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D40378D28E6E4F500B1A341 /* ProxyHelper.swift */; };
1920
0D8A2E6F2896AB49001B2769 /* CommentListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D8A2E6E2896AB49001B2769 /* CommentListView.swift */; };
@@ -38,6 +39,7 @@
3839
0D033B3D288D0FF700129C9B /* SidebarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarView.swift; sourceTree = "<group>"; };
3940
0D033B3F288D140C00129C9B /* TopicListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopicListView.swift; sourceTree = "<group>"; };
4041
0D033B41288D15CF00129C9B /* TopicDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopicDetailView.swift; sourceTree = "<group>"; };
42+
0D139DE128E7E06C00E4CF88 /* UserName.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserName.swift; sourceTree = "<group>"; };
4143
0D40378B28E6E4EA00B1A341 /* SettingsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
4244
0D40378D28E6E4F500B1A341 /* ProxyHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProxyHelper.swift; sourceTree = "<group>"; };
4345
0D8A2E6E2896AB49001B2769 /* CommentListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentListView.swift; sourceTree = "<group>"; };
@@ -115,6 +117,7 @@
115117
0D40378B28E6E4EA00B1A341 /* SettingsView.swift */,
116118
0DF9130528E49D2F00A2CDEC /* TopicList */,
117119
0DF9130428E49D2000A2CDEC /* TopicDetail */,
120+
0D139DE328E7E0BD00E4CF88 /* Components */,
118121
);
119122
path = Views;
120123
sourceTree = "<group>";
@@ -126,6 +129,14 @@
126129
name = Frameworks;
127130
sourceTree = "<group>";
128131
};
132+
0D139DE328E7E0BD00E4CF88 /* Components */ = {
133+
isa = PBXGroup;
134+
children = (
135+
0D139DE128E7E06C00E4CF88 /* UserName.swift */,
136+
);
137+
path = Components;
138+
sourceTree = "<group>";
139+
};
129140
0D8F3357288D35B200C27AF1 /* Utils */ = {
130141
isa = PBXGroup;
131142
children = (
@@ -253,6 +264,7 @@
253264
0D033B42288D15CF00129C9B /* TopicDetailView.swift in Sources */,
254265
0D033B40288D140C00129C9B /* TopicListView.swift in Sources */,
255266
0D033B26288CD64500129C9B /* V2exOSApp.swift in Sources */,
267+
0D139DE228E7E06C00E4CF88 /* UserName.swift in Sources */,
256268
0D033B3E288D0FF700129C9B /* SidebarView.swift in Sources */,
257269
0DF3300E28A55DEA00AEF312 /* InboxListView.swift in Sources */,
258270
0D40378E28E6E4F500B1A341 /* ProxyHelper.swift in Sources */,

V2exOS/Modifier/UserName.swift

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//
2+
// UserName.swift
3+
// V2exOS
4+
//
5+
// Created by m on 2022/9/30.
6+
//
7+
8+
import Foundation
9+
import SwiftUI
10+
11+
struct UserName: View {
12+
13+
var username: String
14+
15+
init(_ username: String) {
16+
self.username = username
17+
}
18+
19+
var body: some View {
20+
Button {
21+
if let url = URL(string: "https://www.v2ex.com/member/\(username)") {
22+
NSWorkspace.shared.open(url)
23+
}
24+
} label: {
25+
Text(username)
26+
.foregroundColor(.secondary)
27+
.fontWeight(.bold)
28+
.onHover { inside in
29+
if inside {
30+
NSCursor.pointingHand.push()
31+
} else {
32+
NSCursor.pop()
33+
}
34+
}
35+
}
36+
.buttonStyle(PlainButtonStyle())
37+
}
38+
}
39+
40+
struct UserName_Previews: PreviewProvider {
41+
static var previews: some View {
42+
UserName("isaced")
43+
}
44+
}

V2exOS/Views/TopicDetail/CommentListView.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ struct CommentListView: View {
4646
VStack(alignment: .leading, spacing: 6) {
4747
HStack {
4848
if let username = comment.member.username {
49-
Text("")
50-
.linkName(username)
49+
UserName(username)
5150
}
5251

5352
if let created = comment.created {

V2exOS/Views/TopicDetail/TopicDetailView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct TopicDetailView: View {
3636
if let authorName = topic.member?.username {
3737
HStack(alignment: .bottom, spacing: 5) {
3838
Image(systemName: "person.circle")
39-
Text(authorName)
39+
UserName(authorName)
4040
}
4141
}
4242

V2exOS/Views/TopicList/TopicListCellView.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ struct TopicListCellView: View {
3636

3737
HStack() {
3838
if let username = topic.member?.username {
39-
Text("")
40-
.linkName(username)
39+
UserName(username)
4140

4241
Text("")
4342
}

0 commit comments

Comments
 (0)