Account: scrolling banner

This commit is contained in:
Thomas Ricouard 2022-12-21 12:47:07 +01:00
parent 2cd28c13f3
commit ae9f78e737
2 changed files with 15 additions and 6 deletions

View File

@ -11,6 +11,11 @@ struct AccountDetailHeaderView: View {
let account: Account let account: Account
@Binding var relationship: Relationshionship? @Binding var relationship: Relationshionship?
@Binding var following: Bool @Binding var following: Bool
@Binding var scrollOffset: CGFloat
private var bannerHeight: CGFloat {
200 + (scrollOffset > 0 ? scrollOffset * 2 : 0)
}
var body: some View { var body: some View {
VStack(alignment: .leading) { VStack(alignment: .leading) {
@ -27,13 +32,13 @@ struct AccountDetailHeaderView: View {
content: { image in content: { image in
image.resizable() image.resizable()
.aspectRatio(contentMode: .fill) .aspectRatio(contentMode: .fill)
.frame(height: 200) .frame(height: bannerHeight)
.frame(width: proxy.frame(in: .local).width) .frame(width: proxy.frame(in: .local).width)
.clipped() .clipped()
}, },
placeholder: { placeholder: {
Color.gray Color.gray
.frame(height: 200) .frame(height: bannerHeight)
} }
) )
if relationship?.followedBy == true { if relationship?.followedBy == true {
@ -48,7 +53,8 @@ struct AccountDetailHeaderView: View {
} }
.background(Color.gray) .background(Color.gray)
} }
.frame(height: 200) .frame(height: bannerHeight)
.offset(y: scrollOffset > 0 ? -scrollOffset : 0)
.contentShape(Rectangle()) .contentShape(Rectangle())
.onTapGesture { .onTapGesture {
routeurPath.presentedSheet = .imageDetail(url: account.header) routeurPath.presentedSheet = .imageDetail(url: account.header)
@ -135,6 +141,7 @@ struct AccountDetailHeaderView_Previews: PreviewProvider {
AccountDetailHeaderView(isCurrentUser: false, AccountDetailHeaderView(isCurrentUser: false,
account: .placeholder(), account: .placeholder(),
relationship: .constant(.placeholder()), relationship: .constant(.placeholder()),
following: .constant(true)) following: .constant(true),
scrollOffset: .constant(0))
} }
} }

View File

@ -82,7 +82,8 @@ public struct AccountDetailView: View {
AccountDetailHeaderView(isCurrentUser: isCurrentUser, AccountDetailHeaderView(isCurrentUser: isCurrentUser,
account: .placeholder(), account: .placeholder(),
relationship: .constant(.placeholder()), relationship: .constant(.placeholder()),
following: .constant(false)) following: .constant(false),
scrollOffset: $scrollOffset)
.redacted(reason: .placeholder) .redacted(reason: .placeholder)
case let .data(account): case let .data(account):
AccountDetailHeaderView(isCurrentUser: isCurrentUser, AccountDetailHeaderView(isCurrentUser: isCurrentUser,
@ -99,7 +100,8 @@ public struct AccountDetailView: View {
await viewModel.unfollow() await viewModel.unfollow()
} }
} }
})) }),
scrollOffset: $scrollOffset)
case let .error(error): case let .error(error):
Text("Error: \(error.localizedDescription)") Text("Error: \(error.localizedDescription)")
} }