Skip to content

Commit aa189f3

Browse files
author
たつぞう
committed
feat: Better list performance
1 parent e1d697f commit aa189f3

File tree

8 files changed

+81
-224
lines changed

8 files changed

+81
-224
lines changed

EhPanda.xcodeproj/project.pbxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
ABF45AE325F3313D00ECB568 /* SlideMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABF45AC525F3313D00ECB568 /* SlideMenu.swift */; };
5454
ABF45AE425F3313D00ECB568 /* TagCloudView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABF45AC725F3313D00ECB568 /* TagCloudView.swift */; };
5555
ABF45AE525F3313D00ECB568 /* Comment.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABF45AC825F3313D00ECB568 /* Comment.swift */; };
56-
ABF45AE625F3313D00ECB568 /* KRefreshScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABF45AC925F3313D00ECB568 /* KRefreshScrollView.swift */; };
5756
ABF45AE725F3313D00ECB568 /* RatingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABF45ACA25F3313D00ECB568 /* RatingView.swift */; };
5857
ABF45AE825F3313D00ECB568 /* LinkedText.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABF45ACB25F3313D00ECB568 /* LinkedText.swift */; };
5958
ABF45AE925F3313D00ECB568 /* AlertView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABF45ACC25F3313D00ECB568 /* AlertView.swift */; };
@@ -126,7 +125,6 @@
126125
ABF45AC525F3313D00ECB568 /* SlideMenu.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SlideMenu.swift; sourceTree = "<group>"; };
127126
ABF45AC725F3313D00ECB568 /* TagCloudView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TagCloudView.swift; sourceTree = "<group>"; };
128127
ABF45AC825F3313D00ECB568 /* Comment.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Comment.swift; sourceTree = "<group>"; };
129-
ABF45AC925F3313D00ECB568 /* KRefreshScrollView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KRefreshScrollView.swift; sourceTree = "<group>"; };
130128
ABF45ACA25F3313D00ECB568 /* RatingView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RatingView.swift; sourceTree = "<group>"; };
131129
ABF45ACB25F3313D00ECB568 /* LinkedText.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LinkedText.swift; sourceTree = "<group>"; };
132130
ABF45ACC25F3313D00ECB568 /* AlertView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlertView.swift; sourceTree = "<group>"; };
@@ -305,7 +303,6 @@
305303
ABC1FAB72642C37D00A9F352 /* NewDawnView.swift */,
306304
ABF45AC825F3313D00ECB568 /* Comment.swift */,
307305
ABF45ACD25F3313D00ECB568 /* Placeholder.swift */,
308-
ABF45AC925F3313D00ECB568 /* KRefreshScrollView.swift */,
309306
ABF45AC725F3313D00ECB568 /* TagCloudView.swift */,
310307
ABF45ACB25F3313D00ECB568 /* LinkedText.swift */,
311308
ABF45ACA25F3313D00ECB568 /* RatingView.swift */,
@@ -504,7 +501,6 @@
504501
ABEA1FE625A9B40B002966B9 /* Setting.swift in Sources */,
505502
ABC3C7962593699B00E0C11B /* Manga.swift in Sources */,
506503
ABC3C7872593699B00E0C11B /* EhPandaApp.swift in Sources */,
507-
ABF45AE625F3313D00ECB568 /* KRefreshScrollView.swift in Sources */,
508504
ABF313A525B1AB6600D47A2F /* Misc.swift in Sources */,
509505
ABA732DF25A852D800B3D9AB /* Filter.swift in Sources */,
510506
ABC1FAB82642C37D00A9F352 /* NewDawnView.swift in Sources */,

EhPanda/App/EhPandaApp.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ struct EhPandaApp: App {
1616
init() {
1717
configureWebImage()
1818
clearImageCachesIfNeeded()
19+
UIScrollView.appearance()
20+
.keyboardDismissMode = .onDrag
21+
UITableViewCell.appearance()
22+
.selectedBackgroundView = UIView()
1923
}
2024

2125
var body: some Scene {

EhPanda/App/Utility.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ func notificFeedback(style: UINotificationFeedbackGenerator.FeedbackType) {
195195
}
196196

197197
// MARK: Tools
198+
var animatedTransition: AnyTransition {
199+
AnyTransition.opacity.animation(.default)
200+
}
198201
func clearPasteboard() {
199202
UIPasteboard.general.string = ""
200203
}

EhPanda/View/Content/ContentView.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,8 @@ struct ContentView: View, StoreAccessor {
9797
onLazyVStackAppear(scrollProxy)
9898
}
9999
}
100+
.transition(animatedTransition)
100101
.ignoresSafeArea()
101-
.transition(
102-
AnyTransition
103-
.opacity
104-
.animation(
105-
.default
106-
)
107-
)
108102
.scaleEffect(scale)
109103
.offset(offset)
110104
.gesture(doubleTap)

EhPanda/View/Detail/AssociatedView.swift

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,26 @@ struct AssociatedView: View, StoreAccessor {
1919
}
2020

2121
var body: some View {
22-
ScrollView {
23-
LazyVStack {
24-
if !assciatedItem.mangas.isEmpty {
22+
Group {
23+
if !assciatedItem.mangas.isEmpty {
24+
List {
2525
ForEach(assciatedItem.mangas) { manga in
26-
NavigationLink(
27-
destination: DetailView(
28-
gid: manga.gid,
29-
depth: depth + 1
30-
)
31-
) {
26+
ZStack {
27+
NavigationLink(
28+
destination: DetailView(
29+
gid: manga.gid,
30+
depth: depth + 1
31+
)
32+
) {}
3233
MangaSummaryRow(manga: manga)
33-
.onAppear(perform: {
34-
onRowAppear(manga)
35-
})
3634
}
35+
.listRowBackground(Color.clear)
36+
.listRowSeparator(.hidden)
37+
.onAppear(perform: {
38+
onRowAppear(manga)
39+
})
3740
}
38-
.transition(
39-
AnyTransition
40-
.opacity
41-
.animation(.default)
42-
)
41+
.transition(animatedTransition)
4342
HStack(alignment: .center) {
4443
Spacer()
4544
ProgressView()
@@ -50,19 +49,20 @@ struct AssociatedView: View, StoreAccessor {
5049
.opacity(moreLoadFailedFlag ? 1 : 0)
5150
Spacer()
5251
}
52+
.listRowBackground(Color.clear)
53+
.listRowSeparator(.hidden)
5354
.frame(height: 30)
54-
} else if loadingFlag {
55-
LoadingView()
56-
.padding(.top, 30)
57-
} else if notFoundFlag {
58-
NotFoundView(retryAction: retryAction)
59-
.padding(.top, 30)
60-
} else {
61-
NetworkErrorView(retryAction: retryAction)
62-
.padding(.top, 30)
6355
}
56+
.refreshable(action: fetchAssociatedItems)
57+
.transition(animatedTransition)
58+
.listStyle(.plain)
59+
} else if loadingFlag {
60+
LoadingView()
61+
} else if notFoundFlag {
62+
NotFoundView(retryAction: retryAction)
63+
} else {
64+
NetworkErrorView(retryAction: retryAction)
6465
}
65-
.padding()
6666
}
6767
.onAppear(perform: onAppear)
6868
.navigationBarTitle(title)
@@ -119,9 +119,7 @@ private extension AssociatedView {
119119
}
120120

121121
func onAppear() {
122-
if assciatedItem.keyword != keyword {
123-
fetchAssociatedItems()
124-
}
122+
fetchAssociatedItemsIfNeeded()
125123
}
126124
func onRowAppear(_ item: Manga) {
127125
if item == assciatedItem.mangas.last {
@@ -139,4 +137,10 @@ private extension AssociatedView {
139137
func fetchMoreAssociatedItems() {
140138
store.dispatch(.fetchMoreAssociatedItems(depth: depth, keyword: keyword))
141139
}
140+
141+
func fetchAssociatedItemsIfNeeded() {
142+
if assciatedItem.keyword != keyword {
143+
fetchAssociatedItems()
144+
}
145+
}
142146
}

EhPanda/View/Detail/DetailView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ struct DetailView: View, StoreAccessor {
7272
.padding(.horizontal)
7373
.padding(.bottom, 20)
7474
}
75-
.transition(AnyTransition.opacity.animation(.default))
75+
.transition(animatedTransition)
7676
} else if detailInfo.mangaDetailLoading {
7777
LoadingView()
7878
} else if detailInfo.mangaDetailLoadFailed {

EhPanda/View/Home/HomeView.swift

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -486,53 +486,46 @@ private struct GenericList: View, StoreAccessor {
486486
self.moreLoadFailedFlag = moreLoadFailedFlag
487487
self.fetchAction = fetchAction
488488
self.loadMoreAction = loadMoreAction
489-
490-
UIScrollView.appearance().keyboardDismissMode = .onDrag
491489
}
492490

493491
var body: some View {
494-
KRefreshScrollView(
495-
progressTint: .gray,
496-
arrowTint: .primary,
497-
onUpdate: onUpdate
498-
) {
499-
if isTokenMatched {
500-
SearchBar(
501-
keyword: homeInfoBinding.searchKeyword,
502-
isTextFieldFocused: _isTextFieldFocused,
503-
commitAction: searchBarCommit,
504-
filterAction: searchBarFilter
505-
)
506-
.padding(.horizontal)
507-
.padding(.bottom, 10)
508-
}
509-
if !didLogin && isTokenMatched {
510-
NotLoginView(loginAction: toggleSetting)
511-
.padding(.top, 30)
512-
} else if loadingFlag {
513-
LoadingView()
514-
.padding(.top, 30)
515-
} else if loadFailedFlag {
516-
NetworkErrorView(retryAction: fetchAction)
517-
.padding(.top, 30)
518-
} else if notFoundFlag {
519-
NotFoundView(retryAction: fetchAction)
520-
.padding(.top, 30)
521-
} else {
492+
if !didLogin && isTokenMatched {
493+
NotLoginView(loginAction: toggleSetting)
494+
} else if loadingFlag {
495+
LoadingView()
496+
} else if loadFailedFlag {
497+
NetworkErrorView(retryAction: fetchAction)
498+
} else if notFoundFlag {
499+
NotFoundView(retryAction: fetchAction)
500+
} else {
501+
List {
502+
if isTokenMatched {
503+
SearchBar(
504+
keyword: homeInfoBinding.searchKeyword,
505+
isTextFieldFocused: _isTextFieldFocused,
506+
commitAction: searchBarCommit,
507+
filterAction: searchBarFilter
508+
)
509+
.listRowBackground(Color.clear)
510+
.listRowSeparator(.hidden)
511+
.padding(.bottom, 10)
512+
}
522513
ForEach(items ?? []) { item in
523-
NavigationLink(destination: DetailView(gid: item.id, depth: 0)) {
514+
ZStack {
515+
NavigationLink(
516+
destination: DetailView(
517+
gid: item.id, depth: 0
518+
)
519+
) {}
524520
MangaSummaryRow(manga: item)
525-
.onAppear {
526-
onRowAppear(item)
527-
}
521+
}
522+
.listRowBackground(Color.clear)
523+
.listRowSeparator(.hidden)
524+
.onAppear {
525+
onRowAppear(item)
528526
}
529527
}
530-
.padding(.horizontal)
531-
.transition(
532-
AnyTransition
533-
.opacity
534-
.animation(.default)
535-
)
528+
.transition(animatedTransition)
536529
HStack(alignment: .center) {
537530
Spacer()
538531
ProgressView()
@@ -543,8 +536,13 @@ private struct GenericList: View, StoreAccessor {
543536
.opacity(moreLoadFailedFlag ? 1 : 0)
544537
Spacer()
545538
}
539+
.listRowBackground(Color.clear)
540+
.listRowSeparator(.hidden)
546541
.frame(height: 30)
547542
}
543+
.transition(animatedTransition)
544+
.refreshable(action: onUpdate)
545+
.listStyle(.plain)
548546
}
549547
}
550548
}

0 commit comments

Comments
 (0)