From 22eedb04a4d932cfb0ac50d3f39f34e5fb5aa21c Mon Sep 17 00:00:00 2001 From: Ching Date: Sun, 7 May 2023 18:37:26 +0800 Subject: [PATCH] =?UTF-8?q?feat(View):=20=E5=A2=9E=E5=8A=A0=20MainTableVie?= =?UTF-8?q?w=20=E5=92=8C=20ToolBar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加 MainTableView 和 ToolBar Signed-off-by: Ching --- duduji.xcodeproj/project.pbxproj | 76 ++++++++++++++++ duduji/ContentView.swift | 8 +- duduji/Core/Components/Avatar.swift | 26 ++++++ duduji/Core/Components/StatusRow.swift | 87 +++++++++++++++++++ duduji/Core/Components/ToolBar.swift | 36 ++++++++ duduji/Core/Feeds/Views/TimeLineTabView.swift | 27 ++++++ duduji/Core/Feeds/Views/TimeLineView.swift | 54 +----------- duduji/Core/MainTab/Views/MainTabView.swift | 83 ++++++++++++++++++ .../Views/NotificationTabView.swift | 30 +++++++ .../Notification/Views/NotificationView.swift | 20 +++++ duduji/dudujiApp.swift | 4 +- 11 files changed, 390 insertions(+), 61 deletions(-) create mode 100644 duduji/Core/Components/Avatar.swift create mode 100644 duduji/Core/Components/StatusRow.swift create mode 100644 duduji/Core/Components/ToolBar.swift create mode 100644 duduji/Core/Feeds/Views/TimeLineTabView.swift create mode 100644 duduji/Core/MainTab/Views/MainTabView.swift create mode 100644 duduji/Core/Notification/Views/NotificationTabView.swift create mode 100644 duduji/Core/Notification/Views/NotificationView.swift diff --git a/duduji.xcodeproj/project.pbxproj b/duduji.xcodeproj/project.pbxproj index c1281e3..c64e076 100644 --- a/duduji.xcodeproj/project.pbxproj +++ b/duduji.xcodeproj/project.pbxproj @@ -15,6 +15,13 @@ 24A07CEB2A029C6A00F4ECA8 /* InstanceInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24A07CEA2A029C6A00F4ECA8 /* InstanceInfo.swift */; }; 24A07CED2A029DF200F4ECA8 /* AccountListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24A07CEC2A029DF200F4ECA8 /* AccountListView.swift */; }; 24A07CF32A03E80200F4ECA8 /* TimeLineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24A07CF22A03E80200F4ECA8 /* TimeLineView.swift */; }; + 24A07CF52A0763B600F4ECA8 /* StatusRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24A07CF42A0763B600F4ECA8 /* StatusRow.swift */; }; + 24A07CFA2A076E5400F4ECA8 /* MainTabView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24A07CF92A076E5400F4ECA8 /* MainTabView.swift */; }; + 24A07CFC2A07A26A00F4ECA8 /* TimeLineTabView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24A07CFB2A07A26A00F4ECA8 /* TimeLineTabView.swift */; }; + 24A07D022A07A31F00F4ECA8 /* NotificationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24A07D012A07A31F00F4ECA8 /* NotificationView.swift */; }; + 24A07D052A07A33900F4ECA8 /* NotificationTabView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24A07D042A07A33900F4ECA8 /* NotificationTabView.swift */; }; + 24C1E5962A07A9D300F09364 /* Avatar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24C1E5952A07A9D300F09364 /* Avatar.swift */; }; + 24C1E59A2A07AC6D00F09364 /* ToolBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24C1E5992A07AC6D00F09364 /* ToolBar.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -28,6 +35,13 @@ 24A07CEA2A029C6A00F4ECA8 /* InstanceInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceInfo.swift; sourceTree = ""; }; 24A07CEC2A029DF200F4ECA8 /* AccountListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountListView.swift; sourceTree = ""; }; 24A07CF22A03E80200F4ECA8 /* TimeLineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimeLineView.swift; sourceTree = ""; }; + 24A07CF42A0763B600F4ECA8 /* StatusRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusRow.swift; sourceTree = ""; }; + 24A07CF92A076E5400F4ECA8 /* MainTabView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTabView.swift; sourceTree = ""; }; + 24A07CFB2A07A26A00F4ECA8 /* TimeLineTabView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimeLineTabView.swift; sourceTree = ""; }; + 24A07D012A07A31F00F4ECA8 /* NotificationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationView.swift; sourceTree = ""; }; + 24A07D042A07A33900F4ECA8 /* NotificationTabView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationTabView.swift; sourceTree = ""; }; + 24C1E5952A07A9D300F09364 /* Avatar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Avatar.swift; sourceTree = ""; }; + 24C1E5992A07AC6D00F09364 /* ToolBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToolBar.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -98,6 +112,8 @@ 24A07CE02A02702800F4ECA8 /* Core */ = { isa = PBXGroup; children = ( + 24A07CFE2A07A30200F4ECA8 /* Notification */, + 24A07CF62A076E2C00F4ECA8 /* MainTab */, 24A07CEE2A03E7BA00F4ECA8 /* Feeds */, 24A07CE42A02714000F4ECA8 /* Authentication */, 24A07CE32A02709900F4ECA8 /* Components */, @@ -116,6 +132,9 @@ isa = PBXGroup; children = ( 24A07CEA2A029C6A00F4ECA8 /* InstanceInfo.swift */, + 24A07CF42A0763B600F4ECA8 /* StatusRow.swift */, + 24C1E5952A07A9D300F09364 /* Avatar.swift */, + 24C1E5992A07AC6D00F09364 /* ToolBar.swift */, ); path = Components; sourceTree = ""; @@ -158,6 +177,7 @@ isa = PBXGroup; children = ( 24A07CF22A03E80200F4ECA8 /* TimeLineView.swift */, + 24A07CFB2A07A26A00F4ECA8 /* TimeLineTabView.swift */, ); path = Views; sourceTree = ""; @@ -169,6 +189,55 @@ path = ViewModels; sourceTree = ""; }; + 24A07CF62A076E2C00F4ECA8 /* MainTab */ = { + isa = PBXGroup; + children = ( + 24A07CF82A076E3A00F4ECA8 /* ViewModels */, + 24A07CF72A076E3600F4ECA8 /* Views */, + ); + path = MainTab; + sourceTree = ""; + }; + 24A07CF72A076E3600F4ECA8 /* Views */ = { + isa = PBXGroup; + children = ( + 24A07CF92A076E5400F4ECA8 /* MainTabView.swift */, + ); + path = Views; + sourceTree = ""; + }; + 24A07CF82A076E3A00F4ECA8 /* ViewModels */ = { + isa = PBXGroup; + children = ( + ); + path = ViewModels; + sourceTree = ""; + }; + 24A07CFE2A07A30200F4ECA8 /* Notification */ = { + isa = PBXGroup; + children = ( + 24A07D002A07A30C00F4ECA8 /* ViewModels */, + 24A07CFF2A07A30900F4ECA8 /* Views */, + ); + path = Notification; + sourceTree = ""; + }; + 24A07CFF2A07A30900F4ECA8 /* Views */ = { + isa = PBXGroup; + children = ( + 24A07D012A07A31F00F4ECA8 /* NotificationView.swift */, + 24A07D042A07A33900F4ECA8 /* NotificationTabView.swift */, + ); + path = Views; + sourceTree = ""; + }; + 24A07D002A07A30C00F4ECA8 /* ViewModels */ = { + isa = PBXGroup; + children = ( + ); + path = ViewModels; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -239,12 +308,19 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 24C1E59A2A07AC6D00F09364 /* ToolBar.swift in Sources */, 24A07CD22A026DDA00F4ECA8 /* ContentView.swift in Sources */, + 24C1E5962A07A9D300F09364 /* Avatar.swift in Sources */, + 24A07CFC2A07A26A00F4ECA8 /* TimeLineTabView.swift in Sources */, 24A07CF32A03E80200F4ECA8 /* TimeLineView.swift in Sources */, 24A07CD02A026DDA00F4ECA8 /* dudujiApp.swift in Sources */, + 24A07D052A07A33900F4ECA8 /* NotificationTabView.swift in Sources */, + 24A07CFA2A076E5400F4ECA8 /* MainTabView.swift in Sources */, 24A07CEB2A029C6A00F4ECA8 /* InstanceInfo.swift in Sources */, 24A07CE92A02730700F4ECA8 /* AddAccountView.swift in Sources */, 24A07CED2A029DF200F4ECA8 /* AccountListView.swift in Sources */, + 24A07CF52A0763B600F4ECA8 /* StatusRow.swift in Sources */, + 24A07D022A07A31F00F4ECA8 /* NotificationView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/duduji/ContentView.swift b/duduji/ContentView.swift index 60c3cc0..83953e0 100644 --- a/duduji/ContentView.swift +++ b/duduji/ContentView.swift @@ -9,13 +9,7 @@ import SwiftUI struct ContentView: View { var body: some View { - VStack { - Image(systemName: "globe") - .imageScale(.large) - .foregroundColor(.accentColor) - Text("Hello, world!") - } - .padding() + MainTabView() } } diff --git a/duduji/Core/Components/Avatar.swift b/duduji/Core/Components/Avatar.swift new file mode 100644 index 0000000..076db24 --- /dev/null +++ b/duduji/Core/Components/Avatar.swift @@ -0,0 +1,26 @@ +// +// Avatar.swift +// duduji +// +// Created by ching on 2023/5/7. +// + +import SwiftUI + +struct Avatar: View { + var body: some View { + Circle() + .fill(Color.blue) + .frame(width: 24, height: 24) + .overlay( + Circle() + .stroke(.gray.opacity(0.5), lineWidth: 2) + ) + } +} + +struct AvatarView_Previews: PreviewProvider { + static var previews: some View { + Avatar() + } +} diff --git a/duduji/Core/Components/StatusRow.swift b/duduji/Core/Components/StatusRow.swift new file mode 100644 index 0000000..336c6f2 --- /dev/null +++ b/duduji/Core/Components/StatusRow.swift @@ -0,0 +1,87 @@ +// +// StatusRow.swift +// duduji +// +// Created by ching on 2023/5/7. +// + +import SwiftUI + +struct StatusRow: View { + var body: some View { + VStack { + HStack(alignment: .center, spacing: 2) { + Image(systemName: "arrow.rectanglepath") + Circle() + .fill(Color.blue) + .frame(width: 12, height: 12) + Text("小傻猪猪仔") + .bold() + Text("转发") + Spacer() + } + .font(.caption) + .foregroundColor(.gray) + .padding(.horizontal) + HStack { + RoundedRectangle(cornerRadius: 6) + .fill(Color.blue) + .frame(width: 48, height: 48) + .overlay( + RoundedRectangle(cornerRadius: 6) + .stroke(.gray.opacity(0.35), lineWidth: 1) + ) + + VStack(alignment: .leading, spacing: 4) { + HStack(alignment: .firstTextBaseline, spacing: 2) { + Text("科代") + .bold() + Text(verbatim: "@kedai@nofan.xyz") + .textContentType(.none) + .font(.subheadline) + .foregroundColor(.gray) + } + HStack { + Text("4分钟前") + Text("·") + Image(systemName: "globe.americas") + } + .foregroundColor(.gray) + .font(.subheadline) + } + Spacer() + // Image(systemName: "ellipsis") + // .font(.title2) + // .foregroundColor(.gray) + } + .padding(.horizontal) + + HStack { + Text("偶然刷到一个 INS视频,帅帅的藏族模特走\n 路,但配乐的一个蒙古歌,歌词还是汉语中文。\n 一群西方人在下面评论:多么美好的藏族文化啊!\n 一时间不知道说啥。。。\n 嗐,白人") + .multilineTextAlignment(.leading) + Spacer() + } + .padding(.horizontal) + + HStack { + RoundedRectangle(cornerRadius: 6) + .fill(Color.blue) + .frame(width: 192, height: 192) + .overlay( + RoundedRectangle(cornerRadius: 6) + .stroke(.gray.opacity(0.35), lineWidth: 1) + ) + Spacer() + } + .padding(.horizontal) + } + Divider() + .padding(.vertical) + } +} + +struct StatusRow_Previews: PreviewProvider { + static var previews: some View { + StatusRow() + } +} diff --git a/duduji/Core/Components/ToolBar.swift b/duduji/Core/Components/ToolBar.swift new file mode 100644 index 0000000..568f558 --- /dev/null +++ b/duduji/Core/Components/ToolBar.swift @@ -0,0 +1,36 @@ +// +// ToolBar.swift +// duduji +// +// Created by ching on 2023/5/7. +// + +import SwiftUI + +struct ToolBar: ToolbarContent { + var body: some ToolbarContent { + ToolbarItem(placement: .navigationBarLeading) { + Button { + // switch account button + } label: { + Avatar() + } + } + + ToolbarItem(placement: .navigationBarTrailing) { + Button { + // toot button + } label: { + Image(systemName: "square.and.pencil") + } + } + } +} + +// +// struct ToolBarAvatar_Previews: PreviewProvider { +// static var previews: some View { +// +// ToolBarAvatar() +// } +// } diff --git a/duduji/Core/Feeds/Views/TimeLineTabView.swift b/duduji/Core/Feeds/Views/TimeLineTabView.swift new file mode 100644 index 0000000..2e6d93a --- /dev/null +++ b/duduji/Core/Feeds/Views/TimeLineTabView.swift @@ -0,0 +1,27 @@ +// +// TimeLineTabView.swift +// duduji +// +// Created by ching on 2023/5/7. +// + +import SwiftUI + +struct TimeLineTabView: View { + var body: some View { + NavigationStack { + TimeLineView() + .toolbar { + ToolBar() + } + .navigationTitle("title") + .navigationBarTitleDisplayMode(.inline) + } + } +} + +struct TimeLineTabView_Previews: PreviewProvider { + static var previews: some View { + TimeLineTabView() + } +} diff --git a/duduji/Core/Feeds/Views/TimeLineView.swift b/duduji/Core/Feeds/Views/TimeLineView.swift index 0855cab..2c3565a 100644 --- a/duduji/Core/Feeds/Views/TimeLineView.swift +++ b/duduji/Core/Feeds/Views/TimeLineView.swift @@ -11,59 +11,9 @@ struct TimeLineView: View { var body: some View { ScrollView { LazyVStack { - HStack(alignment: .center, spacing: 2) { - Image(systemName: "arrow.rectanglepath") - Circle() - .fill(Color.blue) - .frame(width: 12, height: 12) - Text("小傻猪猪仔") - .bold() - Text("转发") - Spacer() + ForEach(0 ... 25, id: \.self) { _ in + StatusRow() } - .font(.caption) - .foregroundColor(.gray) - .padding(.horizontal) - HStack { - RoundedRectangle(cornerRadius: 6) - .fill(Color.blue) - .frame(width: 48, height: 48) - .overlay( - RoundedRectangle(cornerRadius: 6) - .stroke(.gray.opacity(0.35), lineWidth: 1) - ) - - VStack(alignment: .leading, spacing: 4) { - HStack(alignment: .firstTextBaseline, spacing: 2) { - Text("科代") - .bold() - Text(verbatim: "@kedai@nofan.xyz") - .textContentType(.none) - .font(.subheadline) - .foregroundColor(.gray) - } - HStack { - Text("4分钟前") - Text("·") - Image(systemName: "globe.americas") - } - .foregroundColor(.gray) - .font(.subheadline) - } - Spacer() -// Image(systemName: "ellipsis") -// .font(.title2) -// .foregroundColor(.gray) - } - .padding(.horizontal) - - HStack { - Text("偶然刷到一个 INS视频,帅帅的藏族模特走\n 路,但配乐的一个蒙古歌,歌词还是汉语中文。\n 一群西方人在下面评论:多么美好的藏族文化啊!\n 一时间不知道说啥。。。\n 嗐,白人") - .multilineTextAlignment(.leading) - Spacer() - } - .padding(.horizontal) - Divider() } } } diff --git a/duduji/Core/MainTab/Views/MainTabView.swift b/duduji/Core/MainTab/Views/MainTabView.swift new file mode 100644 index 0000000..6bec957 --- /dev/null +++ b/duduji/Core/MainTab/Views/MainTabView.swift @@ -0,0 +1,83 @@ +// +// MainTabView.swift +// duduji +// +// Created by ching on 2023/5/7. +// + +import SwiftUI + +struct MainTabView: View { + @State private var selectedIndex = 0 + + var body: some View { + TabView(selection: $selectedIndex) { + TimeLineTabView() + .onTapGesture { + self.selectedIndex = 0 + } + .tabItem { + Label("时间线", systemImage: "rectangle.stack") + } + .tag(0) + NotificationTabView() + .onTapGesture { + self.selectedIndex = 1 + } + .tabItem { + Label("通知", systemImage: "bell.fill") + } + .tag(1) + TimeLineView() + .onTapGesture { + self.selectedIndex = 2 + } + .tabItem { + Label("探索", systemImage: "magnifyingglass") + } + .tag(2) + TimeLineView() + .onTapGesture { + self.selectedIndex = 3 + } + .tabItem { + Label("私信", systemImage: "tray.fill") + } + .tag(3) + TimeLineView() + .onTapGesture { + self.selectedIndex = 4 + } + .tabItem { + Label("个人主页", systemImage: "person.circle.fill") + } + .tag(4) + } + .navigationTitle(title(for: selectedIndex)) +// } +// .navigationBarTitleDisplayMode(.inline) + } + + func title(for tab: Int) -> String { + switch tab { + case 0: + return "Home" + case 1: + return "Notification" + case 2: + return "Explore" + case 3: + return "Message" + case 4: + return "Profile" + default: + return "" + } + } +} + +struct MainTabView_Previews: PreviewProvider { + static var previews: some View { + MainTabView() + } +} diff --git a/duduji/Core/Notification/Views/NotificationTabView.swift b/duduji/Core/Notification/Views/NotificationTabView.swift new file mode 100644 index 0000000..248ce0a --- /dev/null +++ b/duduji/Core/Notification/Views/NotificationTabView.swift @@ -0,0 +1,30 @@ +// +// NotificationTabView.swift +// duduji +// +// Created by ching on 2023/5/7. +// + +import SwiftUI + +struct NotificationTabView: View { + var body: some View { + NavigationStack { + NotificationView() + .toolbar { + ToolBar() +// ToolbarTitleMenu { +// Text("222") +// } + } + .navigationTitle("通知") + .navigationBarTitleDisplayMode(.inline) + } + } +} + +struct NotificationTabView_Previews: PreviewProvider { + static var previews: some View { + NotificationTabView() + } +} diff --git a/duduji/Core/Notification/Views/NotificationView.swift b/duduji/Core/Notification/Views/NotificationView.swift new file mode 100644 index 0000000..acd9e55 --- /dev/null +++ b/duduji/Core/Notification/Views/NotificationView.swift @@ -0,0 +1,20 @@ +// +// NotificationView.swift +// duduji +// +// Created by ching on 2023/5/7. +// + +import SwiftUI + +struct NotificationView: View { + var body: some View { + Text("Notification View") + } +} + +struct NotificationView_Previews: PreviewProvider { + static var previews: some View { + NotificationView() + } +} diff --git a/duduji/dudujiApp.swift b/duduji/dudujiApp.swift index ca40328..083fc89 100644 --- a/duduji/dudujiApp.swift +++ b/duduji/dudujiApp.swift @@ -11,8 +11,8 @@ import SwiftUI struct dudujiApp: App { var body: some Scene { WindowGroup { -// ContentView() - AccountListView() + ContentView() +// AccountListView() } } }