Skip to content

Commit

Permalink
feat: Better list performance
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuz0u committed Jun 10, 2021
1 parent e1d697f commit aa189f3
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 224 deletions.
4 changes: 0 additions & 4 deletions EhPanda.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
ABF45AE325F3313D00ECB568 /* SlideMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABF45AC525F3313D00ECB568 /* SlideMenu.swift */; };
ABF45AE425F3313D00ECB568 /* TagCloudView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABF45AC725F3313D00ECB568 /* TagCloudView.swift */; };
ABF45AE525F3313D00ECB568 /* Comment.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABF45AC825F3313D00ECB568 /* Comment.swift */; };
ABF45AE625F3313D00ECB568 /* KRefreshScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABF45AC925F3313D00ECB568 /* KRefreshScrollView.swift */; };
ABF45AE725F3313D00ECB568 /* RatingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABF45ACA25F3313D00ECB568 /* RatingView.swift */; };
ABF45AE825F3313D00ECB568 /* LinkedText.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABF45ACB25F3313D00ECB568 /* LinkedText.swift */; };
ABF45AE925F3313D00ECB568 /* AlertView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABF45ACC25F3313D00ECB568 /* AlertView.swift */; };
Expand Down Expand Up @@ -126,7 +125,6 @@
ABF45AC525F3313D00ECB568 /* SlideMenu.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SlideMenu.swift; sourceTree = "<group>"; };
ABF45AC725F3313D00ECB568 /* TagCloudView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TagCloudView.swift; sourceTree = "<group>"; };
ABF45AC825F3313D00ECB568 /* Comment.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Comment.swift; sourceTree = "<group>"; };
ABF45AC925F3313D00ECB568 /* KRefreshScrollView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KRefreshScrollView.swift; sourceTree = "<group>"; };
ABF45ACA25F3313D00ECB568 /* RatingView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RatingView.swift; sourceTree = "<group>"; };
ABF45ACB25F3313D00ECB568 /* LinkedText.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LinkedText.swift; sourceTree = "<group>"; };
ABF45ACC25F3313D00ECB568 /* AlertView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlertView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -305,7 +303,6 @@
ABC1FAB72642C37D00A9F352 /* NewDawnView.swift */,
ABF45AC825F3313D00ECB568 /* Comment.swift */,
ABF45ACD25F3313D00ECB568 /* Placeholder.swift */,
ABF45AC925F3313D00ECB568 /* KRefreshScrollView.swift */,
ABF45AC725F3313D00ECB568 /* TagCloudView.swift */,
ABF45ACB25F3313D00ECB568 /* LinkedText.swift */,
ABF45ACA25F3313D00ECB568 /* RatingView.swift */,
Expand Down Expand Up @@ -504,7 +501,6 @@
ABEA1FE625A9B40B002966B9 /* Setting.swift in Sources */,
ABC3C7962593699B00E0C11B /* Manga.swift in Sources */,
ABC3C7872593699B00E0C11B /* EhPandaApp.swift in Sources */,
ABF45AE625F3313D00ECB568 /* KRefreshScrollView.swift in Sources */,
ABF313A525B1AB6600D47A2F /* Misc.swift in Sources */,
ABA732DF25A852D800B3D9AB /* Filter.swift in Sources */,
ABC1FAB82642C37D00A9F352 /* NewDawnView.swift in Sources */,
Expand Down
4 changes: 4 additions & 0 deletions EhPanda/App/EhPandaApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ struct EhPandaApp: App {
init() {
configureWebImage()
clearImageCachesIfNeeded()
UIScrollView.appearance()
.keyboardDismissMode = .onDrag
UITableViewCell.appearance()
.selectedBackgroundView = UIView()
}

var body: some Scene {
Expand Down
3 changes: 3 additions & 0 deletions EhPanda/App/Utility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ func notificFeedback(style: UINotificationFeedbackGenerator.FeedbackType) {
}

// MARK: Tools
var animatedTransition: AnyTransition {
AnyTransition.opacity.animation(.default)
}
func clearPasteboard() {
UIPasteboard.general.string = ""
}
Expand Down
8 changes: 1 addition & 7 deletions EhPanda/View/Content/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,8 @@ struct ContentView: View, StoreAccessor {
onLazyVStackAppear(scrollProxy)
}
}
.transition(animatedTransition)
.ignoresSafeArea()
.transition(
AnyTransition
.opacity
.animation(
.default
)
)
.scaleEffect(scale)
.offset(offset)
.gesture(doubleTap)
Expand Down
64 changes: 34 additions & 30 deletions EhPanda/View/Detail/AssociatedView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,26 @@ struct AssociatedView: View, StoreAccessor {
}

var body: some View {
ScrollView {
LazyVStack {
if !assciatedItem.mangas.isEmpty {
Group {
if !assciatedItem.mangas.isEmpty {
List {
ForEach(assciatedItem.mangas) { manga in
NavigationLink(
destination: DetailView(
gid: manga.gid,
depth: depth + 1
)
) {
ZStack {
NavigationLink(
destination: DetailView(
gid: manga.gid,
depth: depth + 1
)
) {}
MangaSummaryRow(manga: manga)
.onAppear(perform: {
onRowAppear(manga)
})
}
.listRowBackground(Color.clear)
.listRowSeparator(.hidden)
.onAppear(perform: {
onRowAppear(manga)
})
}
.transition(
AnyTransition
.opacity
.animation(.default)
)
.transition(animatedTransition)
HStack(alignment: .center) {
Spacer()
ProgressView()
Expand All @@ -50,19 +49,20 @@ struct AssociatedView: View, StoreAccessor {
.opacity(moreLoadFailedFlag ? 1 : 0)
Spacer()
}
.listRowBackground(Color.clear)
.listRowSeparator(.hidden)
.frame(height: 30)
} else if loadingFlag {
LoadingView()
.padding(.top, 30)
} else if notFoundFlag {
NotFoundView(retryAction: retryAction)
.padding(.top, 30)
} else {
NetworkErrorView(retryAction: retryAction)
.padding(.top, 30)
}
.refreshable(action: fetchAssociatedItems)
.transition(animatedTransition)
.listStyle(.plain)
} else if loadingFlag {
LoadingView()
} else if notFoundFlag {
NotFoundView(retryAction: retryAction)
} else {
NetworkErrorView(retryAction: retryAction)
}
.padding()
}
.onAppear(perform: onAppear)
.navigationBarTitle(title)
Expand Down Expand Up @@ -119,9 +119,7 @@ private extension AssociatedView {
}

func onAppear() {
if assciatedItem.keyword != keyword {
fetchAssociatedItems()
}
fetchAssociatedItemsIfNeeded()
}
func onRowAppear(_ item: Manga) {
if item == assciatedItem.mangas.last {
Expand All @@ -139,4 +137,10 @@ private extension AssociatedView {
func fetchMoreAssociatedItems() {
store.dispatch(.fetchMoreAssociatedItems(depth: depth, keyword: keyword))
}

func fetchAssociatedItemsIfNeeded() {
if assciatedItem.keyword != keyword {
fetchAssociatedItems()
}
}
}
2 changes: 1 addition & 1 deletion EhPanda/View/Detail/DetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct DetailView: View, StoreAccessor {
.padding(.horizontal)
.padding(.bottom, 20)
}
.transition(AnyTransition.opacity.animation(.default))
.transition(animatedTransition)
} else if detailInfo.mangaDetailLoading {
LoadingView()
} else if detailInfo.mangaDetailLoadFailed {
Expand Down
78 changes: 38 additions & 40 deletions EhPanda/View/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -486,53 +486,46 @@ private struct GenericList: View, StoreAccessor {
self.moreLoadFailedFlag = moreLoadFailedFlag
self.fetchAction = fetchAction
self.loadMoreAction = loadMoreAction

UIScrollView.appearance().keyboardDismissMode = .onDrag
}

var body: some View {
KRefreshScrollView(
progressTint: .gray,
arrowTint: .primary,
onUpdate: onUpdate
) {
if isTokenMatched {
SearchBar(
keyword: homeInfoBinding.searchKeyword,
isTextFieldFocused: _isTextFieldFocused,
commitAction: searchBarCommit,
filterAction: searchBarFilter
)
.padding(.horizontal)
.padding(.bottom, 10)
}
if !didLogin && isTokenMatched {
NotLoginView(loginAction: toggleSetting)
.padding(.top, 30)
} else if loadingFlag {
LoadingView()
.padding(.top, 30)
} else if loadFailedFlag {
NetworkErrorView(retryAction: fetchAction)
.padding(.top, 30)
} else if notFoundFlag {
NotFoundView(retryAction: fetchAction)
.padding(.top, 30)
} else {
if !didLogin && isTokenMatched {
NotLoginView(loginAction: toggleSetting)
} else if loadingFlag {
LoadingView()
} else if loadFailedFlag {
NetworkErrorView(retryAction: fetchAction)
} else if notFoundFlag {
NotFoundView(retryAction: fetchAction)
} else {
List {
if isTokenMatched {
SearchBar(
keyword: homeInfoBinding.searchKeyword,
isTextFieldFocused: _isTextFieldFocused,
commitAction: searchBarCommit,
filterAction: searchBarFilter
)
.listRowBackground(Color.clear)
.listRowSeparator(.hidden)
.padding(.bottom, 10)
}
ForEach(items ?? []) { item in
NavigationLink(destination: DetailView(gid: item.id, depth: 0)) {
ZStack {
NavigationLink(
destination: DetailView(
gid: item.id, depth: 0
)
) {}
MangaSummaryRow(manga: item)
.onAppear {
onRowAppear(item)
}
}
.listRowBackground(Color.clear)
.listRowSeparator(.hidden)
.onAppear {
onRowAppear(item)
}
}
.padding(.horizontal)
.transition(
AnyTransition
.opacity
.animation(.default)
)
.transition(animatedTransition)
HStack(alignment: .center) {
Spacer()
ProgressView()
Expand All @@ -543,8 +536,13 @@ private struct GenericList: View, StoreAccessor {
.opacity(moreLoadFailedFlag ? 1 : 0)
Spacer()
}
.listRowBackground(Color.clear)
.listRowSeparator(.hidden)
.frame(height: 30)
}
.transition(animatedTransition)
.refreshable(action: onUpdate)
.listStyle(.plain)
}
}
}
Expand Down
Loading

0 comments on commit aa189f3

Please sign in to comment.