1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-27 12:26:31 +01:00

EC-847 improved watch list ui performance by removing the animations on the search box and going back to the simple List instead of the TrackableWithHeaderListView (#2256)

This commit is contained in:
Federico Maccaroni 2022-12-22 16:06:21 -03:00 committed by GitHub
parent e72932cbaa
commit 307c71ee07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,48 +4,21 @@ struct CipherListView: View {
@ObservedObject var viewModel = CipherListViewModel(CipherService.shared) @ObservedObject var viewModel = CipherListViewModel(CipherService.shared)
let AVATAR_ID: String = "avatarId" let AVATAR_ID: String = "avatarId"
@State private var contentOffset = CGFloat(0)
@State private var initialOffset = CGFloat(0)
var isHeaderVisible: Bool { var isHeaderVisible: Bool {
if !viewModel.searchTerm.isEmpty { return !viewModel.searchTerm.isEmpty || viewModel.filteredCiphers.count > 1
return true
}
let threshold = initialOffset + 15
return viewModel.filteredCiphers.count > 1 && contentOffset > threshold
} }
var body: some View { var body: some View {
NavigationView { NavigationView {
GeometryReader { geometry in GeometryReader { geometry in
ScrollViewReader { scrollProxy in ScrollViewReader { scrollProxy in
TrackableWithHeaderListView { offset in List {
withAnimation { if isHeaderVisible {
contentOffset = offset?.y ?? 0 Section() {
} getSearchSection(geometry.size.width)
} headerContent: {
Section() {
ZStack {
searchContent
.padding(5)
.background(
RoundedRectangle(cornerRadius: 5)
.foregroundColor(Color.ui.primary)
.frame(width: geometry.size.width,
alignment: .leading)
)
.opacity(isHeaderVisible ? 1 : 0)
} }
.background(
RoundedRectangle(cornerRadius: 5)
.foregroundColor(Color.black)
.frame(width: geometry.size.width, height: 60)
)
.offset(y:isHeaderVisible ? 0 : 5)
.padding(0)
} }
} content: {
if viewModel.user?.email != nil { if viewModel.user?.email != nil {
Section() { Section() {
avatarHeader avatarHeader
@ -74,10 +47,6 @@ struct CipherListView: View {
.onReceive(self.viewModel.$updateHack) { _ in .onReceive(self.viewModel.$updateHack) { _ in
DispatchQueue.main.asyncAfter(deadline: .now() + 0.15) { DispatchQueue.main.asyncAfter(deadline: .now() + 0.15) {
scrollProxy.scrollTo(AVATAR_ID, anchor: .top) scrollProxy.scrollTo(AVATAR_ID, anchor: .top)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.15){
self.initialOffset = self.contentOffset
}
} }
} }
} }
@ -133,6 +102,25 @@ struct CipherListView: View {
.multilineTextAlignment(.center) .multilineTextAlignment(.center)
} }
} }
func getSearchSection(_ maxWidth:CGFloat) -> some View {
return ZStack {
searchContent
.padding(5)
.background(
RoundedRectangle(cornerRadius: 5)
.foregroundColor(Color.ui.primary)
.frame(width: maxWidth,
alignment: .leading)
)
}
.background(
RoundedRectangle(cornerRadius: 5)
.foregroundColor(Color.black)
.frame(width: maxWidth, height: 60)
)
.padding(0)
}
} }
struct ContentView_Previews: PreviewProvider { struct ContentView_Previews: PreviewProvider {