Skip to content

Commit

Permalink
添加资料后没法滚动到顶部的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ming1016 committed May 8, 2024
1 parent d8bdc2d commit 2441c9e
Show file tree
Hide file tree
Showing 8 changed files with 241 additions and 131 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Swift开发的手册,是个 macOS 程序,已上线 App Store [点击安装](

使用 SwiftData、Observable、NavigationSplitView 重构了戴铭的开发小册子,可自己添加管理资料。

本解决了几个问题
本版本解决了以下几个问题

第一个,存储的问题。以前使用的是三方数据库,写法比较繁琐且和 SwiftUI 结合的不好。现在用的是 SwiftData,写法简洁了很多,代码也好维护了。更多技术重构细节可以直接查看代码。

Expand Down
12 changes: 8 additions & 4 deletions SwiftPamphletApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
08522BE427CF5C55005FF059 /* SwiftUI颜色(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 08522BE327CF5C55005FF059 /* SwiftUI颜色(ap).md */; };
08522BE927CF6E3B005FF059 /* SwiftUI Effect(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 08522BE827CF6E3A005FF059 /* SwiftUI Effect(ap).md */; };
08522BED27CF7A0C005FF059 /* Keyboard(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 08522BEC27CF7A0C005FF059 /* Keyboard(ap).md */; };
0858C5C72BEBD230004F4C04 /* ContentUnavailableView(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 0858C5C62BEBD230004F4C04 /* ContentUnavailableView(ap).md */; };
085BB77427D22FCA00E8F69A /* SwiftUI动画(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 085BB77327D22FCA00E8F69A /* SwiftUI动画(ap).md */; };
085BB77627D22FE300E8F69A /* SwiftUI Canvas(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 085BB77527D22FE300E8F69A /* SwiftUI Canvas(ap).md */; };
08659BC72BE8FD84009B7C00 /* SwiftUI数据流(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 08659BC62BE8FD84009B7C00 /* SwiftUI数据流(ap).md */; };
Expand Down Expand Up @@ -363,6 +364,7 @@
08522BE327CF5C55005FF059 /* SwiftUI颜色(ap).md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = "SwiftUI颜色(ap).md"; sourceTree = "<group>"; };
08522BE827CF6E3A005FF059 /* SwiftUI Effect(ap).md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = "SwiftUI Effect(ap).md"; sourceTree = "<group>"; };
08522BEC27CF7A0C005FF059 /* Keyboard(ap).md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = "Keyboard(ap).md"; sourceTree = "<group>"; };
0858C5C62BEBD230004F4C04 /* ContentUnavailableView(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "ContentUnavailableView(ap).md"; sourceTree = "<group>"; };
085BB77327D22FCA00E8F69A /* SwiftUI动画(ap).md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = "SwiftUI动画(ap).md"; sourceTree = "<group>"; };
085BB77527D22FE300E8F69A /* SwiftUI Canvas(ap).md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = "SwiftUI Canvas(ap).md"; sourceTree = "<group>"; };
08659BC62BE8FD84009B7C00 /* SwiftUI数据流(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "SwiftUI数据流(ap).md"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -979,6 +981,7 @@
08BE635727C63F3A002BC6A8 /* ControlGroup(ap).md */,
08BE635B27C65C7C002BC6A8 /* GroupBox(ap).md */,
08026C3A2869A21000792EF1 /* Advanced layout control(ap).md */,
0858C5C62BEBD230004F4C04 /* ContentUnavailableView(ap).md */,
);
path = "布局组件";
sourceTree = "<group>";
Expand Down Expand Up @@ -1335,6 +1338,7 @@
08BE636427C886D2002BC6A8 /* LazyVStack和LazyHStack(ap).md in Resources */,
08449030279ECF7D00B61353 /* 1.md in Resources */,
08522BDA27CF5029005FF059 /* Slider(ap).md in Resources */,
0858C5C72BEBD230004F4C04 /* ContentUnavailableView(ap).md in Resources */,
08448FD5279EC62700B61353 /* Sets(ap).md in Resources */,
08448F75279EB62B00B61353 /* Scanner(ap).md in Resources */,
08BE632C27BE3762002BC6A8 /* Link(ap).md in Resources */,
Expand Down Expand Up @@ -1526,7 +1530,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_ASSET_PATHS = "\"SwiftPamphletApp/Preview Content\"";
DEVELOPMENT_TEAM = 962Z8PV35L;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -1540,7 +1544,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 14.0;
MARKETING_VERSION = 6.2;
MARKETING_VERSION = 6.3;
OTHER_LDFLAGS = (
"-Xlinker",
"-interposable",
Expand Down Expand Up @@ -1569,7 +1573,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_ASSET_PATHS = "\"SwiftPamphletApp/Preview Content\"";
DEVELOPMENT_TEAM = 962Z8PV35L;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -1583,7 +1587,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 14.0;
MARKETING_VERSION = 6.2;
MARKETING_VERSION = 6.3;
PRODUCT_BUNDLE_IDENTIFIER = com.starming.SwiftPamphletAppByMing;
PRODUCT_NAME = "戴铭的开发小册子";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
67 changes: 37 additions & 30 deletions SwiftPamphletApp/Guide/GuideDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,40 +53,47 @@ struct GuideDetailView: View {
}
}
.inspector(isPresented: $isShowInspector) {
HStack {
// 关闭
Button(action: {
isShowInspector = false
selectInfo = nil
}, label: {
Image(systemName: "xmark.circle")
})
.help("CMD + d")
.keyboardShortcut(KeyEquivalent("d"), modifiers: .command)
Spacer()
Text("资料")
.font(.title)
Spacer()
Button("添加资料") {
let info = IOInfo(name: "新增\(t)资料 - \(SMDate.nowDateString())", url: "", des: "", relateName: t)
modelContext.insert(info)
selectInfo = info
ScrollViewReader(content: { proxy in
HStack {
// 关闭
Button(action: {
isShowInspector = false
selectInfo = nil
}, label: {
Image(systemName: "xmark.circle")
})
.help("CMD + d")
.keyboardShortcut(KeyEquivalent("d"), modifiers: .command)
Spacer()
Text("资料")
.font(.title)
Spacer()
Button("添加资料") {
let info = IOInfo(name: "新增\(t)资料 - \(SMDate.nowDateString())", url: "", des: "", relateName: t)
modelContext.insert(info)
selectInfo = info
withAnimation(.easeInOut) {
proxy.scrollTo(selectInfo, anchor: .top)
}
}
}
}
.padding(EdgeInsets(top: 10, leading: 10, bottom: 2, trailing: 10))
List(selection: $selectInfo) {
ForEach(infos) { info in
InfoRowView(info: info)
.tag(info)
.onAppear {
if info == infos.last {
if limit <= infos.count {
limit += 50
.padding(EdgeInsets(top: 10, leading: 10, bottom: 2, trailing: 10))
List(selection: $selectInfo) {
ForEach(infos) { info in
InfoRowView(info: info)
.tag(info)
.onAppear {
if info == infos.last {
if limit <= infos.count {
limit += 50
}
}
}
}
}

}
}
.id(selectInfo)
})
}
.onAppear {
isShowInspector = asIsShowPamphletInspector
Expand Down
1 change: 1 addition & 0 deletions SwiftPamphletApp/Guide/GuideListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ final class GuideListModel {
L(t: "ControlGroup"),
L(t: "GroupBox"),
L(t: "Advanced layout control"),
L(t: "ContentUnavailableView"),
]),
L(t: "视图组件使用",sub: [
L(t: "Form"),
Expand Down
10 changes: 5 additions & 5 deletions SwiftPamphletApp/InfoOrganizer/Info/EditInfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ import SMNetwork
struct EditInfoView: View {
@Environment(\.modelContext) var modelContext
@Bindable var info: IOInfo

@Query(IOCategory.all) var categories: [IOCategory]

@State private var showSheet = false

// Inspector
Expand All @@ -30,14 +28,11 @@ struct EditInfoView: View {
@State var inspectorType: InspectorType = .category
@AppStorage(SPC.isShowInspector) var asIsShowInspector: Bool = false
@AppStorage(SPC.inspectorType) var asInspectorType: Int = 0

// Tab
@State var selectedTab = 1

@State var isStopLoadingWeb = false
// webarchive
@State var savingDataTrigger = false

// 图集
@State var selectedPhotos = [PhotosPickerItem]()
@State var addWebImageUrl = ""
Expand Down Expand Up @@ -396,6 +391,7 @@ struct EditInfoView: View {
} label: {
Image(systemName: "safari")
}
.help("浏览器打开")
// 本地存
Button {
if info.webArchive == nil {
Expand All @@ -410,6 +406,7 @@ struct EditInfoView: View {
Image(systemName: "square.and.arrow.down.fill")
}
}
.help("离线内容")
} // end if
}
}
Expand All @@ -422,16 +419,19 @@ struct EditInfoView: View {
Image(systemName: info.star ? "star.fill" : "star")
}
.toggleStyle(.button)
.help("收藏")
Toggle(isOn: $info.isArchived) {
Image(systemName: info.isArchived ? "archivebox.fill" : "archivebox")
}
.toggleStyle(.button)
.help("归档")

Button(action: {
info.updateDate = Date.now
}, label: {
Image(systemName: "arrow.up.square")
})
.help("提到前面")
}
}

Expand Down
Loading

0 comments on commit 2441c9e

Please sign in to comment.