Skip to content

Commit

Permalink
优化列表图文
Browse files Browse the repository at this point in the history
  • Loading branch information
ming1016 committed Apr 12, 2024
1 parent 0f5a7df commit 84ca76d
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 43 deletions.
57 changes: 46 additions & 11 deletions SwiftPamphletApp/HomeUI/DataLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct DataLink: Identifiable {
if let info = selectInfoBindable {
EditInfoView(info: info)
} else {
EmptyView()
IntroView()
}
}
case "开发/仓库":
Expand All @@ -50,25 +50,60 @@ struct DataLink: Identifiable {
Text("请在设置里写上 Github 的 access token")
}
} else {
EmptyView()
IntroView()
}
}
case "语法速查":
IssuesListFromCustomView(vm: IssueVM(guideName: "guide-syntax"))
switch type {
case .content:
IssuesListFromCustomView(vm: IssueVM(guideName: "guide-syntax"))
case .detail:
IntroView()
}
case "特性":
IssuesListFromCustomView(vm: IssueVM(guideName:"guide-features"))
switch type {
case .content:
IssuesListFromCustomView(vm: IssueVM(guideName:"guide-features"))
case .detail:
IntroView()
}
case "专题":
IssuesListFromCustomView(vm: IssueVM(guideName:"guide-subject"))
switch type {
case .content:
IssuesListFromCustomView(vm: IssueVM(guideName:"guide-subject"))
case .detail:
IntroView()
}
case "SwiftUI":
IssuesListFromCustomView(vm: IssueVM(guideName:"lib-SwiftUI"))
switch type {
case .content:
IssuesListFromCustomView(vm: IssueVM(guideName:"lib-SwiftUI"))
case .detail:
IntroView()
}
case "Combine":
IssuesListFromCustomView(vm: IssueVM(guideName:"lib-Combine"))
switch type {
case .content:
IssuesListFromCustomView(vm: IssueVM(guideName:"lib-Combine"))
case .detail:
IntroView()
}
case "Concurrency":
IssuesListFromCustomView(vm: IssueVM(guideName:"lib-Concurrency"))
switch type {
case .content:
IssuesListFromCustomView(vm: IssueVM(guideName:"lib-Concurrency"))
case .detail:
IntroView()
}
default:
// 默认是语法速查
IssuesListFromCustomView(vm: IssueVM(guideName: "guide-syntax"))
}
switch type {
case .content:
// 默认是语法速查
IssuesListFromCustomView(vm: IssueVM(guideName: "guide-syntax"))
case .detail:
IntroView()
}
} // end switch
}
}

Expand Down
28 changes: 23 additions & 5 deletions SwiftPamphletApp/HomeUI/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
import SwiftUI

struct HomeView: View {
@State private var selectedDataLinkString: String?
@State private var selectedDataLinkString: String = ""
@State private var selectInfo: IOInfo? = nil
@State private var selectDev: DeveloperModel? = nil
@AppStorage("selectedDataLinkString") var sdLinkStr: String = ""

@AppStorage("isFirstRun") var isFirstRun = true
@Environment(\.scenePhase) var scenePhase

var body: some View {
NavigationSplitView {
Expand All @@ -19,9 +23,9 @@ struct HomeView: View {
selectInfo: $selectInfo
)
} content: {
if let link = selectedDataLinkString {
if !selectedDataLinkString.isEmpty {
DataLink.viewToShow(
for: link,
for: selectedDataLinkString,
selectInfo: $selectInfo,
selectDev: $selectDev,
selectInfoBindable: selectInfo,
Expand All @@ -38,9 +42,9 @@ struct HomeView: View {
}
} detail: {

if let link = selectedDataLinkString {
if !selectedDataLinkString.isEmpty {
DataLink.viewToShow(
for: link,
for: selectedDataLinkString,
selectInfo: $selectInfo,
selectDev: $selectDev,
selectInfoBindable: selectInfo,
Expand All @@ -51,6 +55,20 @@ struct HomeView: View {
IntroView()
}
}
.onAppear(perform: {
if isFirstRun {
isFirstRun = false
// 第一次运行需要处理的
}
selectedDataLinkString = sdLinkStr
})
.onChange(of: selectedDataLinkString, {
sdLinkStr = selectedDataLinkString
})
.onChange(of: scenePhase, {
guard scenePhase == .active else { return } // 只处理 active 状态
debugPrint("active")
})
.task {
#if DEBUG
let sandboxDirectory = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first!
Expand Down
2 changes: 1 addition & 1 deletion SwiftPamphletApp/HomeUI/SidebarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import SwiftUI

struct SidebarView: View {
@Binding var selectedDataLinkString: String?
@Binding var selectedDataLinkString: String

@Binding var selectInfo: IOInfo?

Expand Down
2 changes: 1 addition & 1 deletion SwiftPamphletApp/InfoOrganizer/Info/InfoListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct InfoListView: View {
.toolbar {
ToolbarItem(placement: .navigation) {
Button("添加资料", systemImage: "plus", action: addInfo)
.keyboardShortcut(KeyEquivalent("a"), modifiers: .option)
.keyboardShortcut(KeyEquivalent("i"), modifiers: .command)
}
ToolbarItem(placement: .navigation) {
Picker("分类", selection: $filterCate) {
Expand Down
48 changes: 23 additions & 25 deletions SwiftPamphletApp/InfoOrganizer/Info/InfoRowView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,32 @@ struct InfoRowView: View {

var body: some View {
VStack(alignment:.leading) {


HStack(alignment:.top) {
if let coverImg = info.coverImage {
if coverImg.url.isEmpty == false {
NukeImage(width: 60, height: 60, url: coverImg.url, contentModel: .fill)
} else if let imgData = coverImg.imgData {
if let nsImage = NSImage(data: imgData) {
Image(nsImage: nsImage)
.resizable()
.scaledToFill()
.frame(width: 60, height: 60)
.cornerRadius(5)
if let coverImg = info.coverImage {
ZStack {
Rectangle()
.fill(Color.clear)
.frame(height: 80)
GeometryReader { geometry in
if coverImg.url.isEmpty == false {
NukeImage(width: geometry.size.width, height: geometry.size.height, url: coverImg.url, contentModel: .fill)
} else if let imgData = coverImg.imgData {
if let nsImage = NSImage(data: imgData) {
Image(nsImage: nsImage)
.resizable()
.scaledToFill()
.frame(width: geometry.size.width, height: geometry.size.height)
.cornerRadius(5)
}
}
}

}
VStack(alignment: .leading) {
Text(info.name)
.fixedSize(horizontal: false, vertical: true)
Text(shortDes())
.fixedSize(horizontal: false, vertical: true)
.font(.footnote)
.foregroundColor(light: .secondary, dark: .secondary)
}
}

Text(info.name)
.fixedSize(horizontal: false, vertical: true)
Text(shortDes())
.fixedSize(horizontal: false, vertical: true)
.font(.footnote)
.foregroundColor(light: .secondary, dark: .secondary)

HStack(alignment: .center) {
if info.category != nil {
Expand All @@ -66,7 +65,6 @@ struct InfoRowView: View {
}
Text(howLongAgo(date: info.updateDate))
// Text(info.updateDate, style: .relative)


}
.foregroundColor(light: .secondary, dark: .secondary)
Expand All @@ -89,7 +87,7 @@ struct InfoRowView: View {
}

func shortDes() -> String {
let shortDes = info.des.trimmingCharacters(in: .whitespacesAndNewlines).split(separator: "\n")
let shortDes = info.des.trimmingCharacters(in: .whitespacesAndNewlines).components(separatedBy: .newlines)
if let re = shortDes.first {
return String(re)
}
Expand Down

0 comments on commit 84ca76d

Please sign in to comment.