Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AVW-2908] Transaction Review Header #1079

Merged
merged 2 commits into from
Apr 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,16 @@ extension TransactionReview {

@MainActor
public struct View: SwiftUI.View {
@SwiftUI.State private var showNavigationTitle: Bool = false

private let store: StoreOf<TransactionReview>

private let coordSpace: String = "TransactionReviewCoordSpace"
private let navTitleID: String = "TransactionReview.title"
private let showTitleHysteresis: CGFloat = .small3

private let shadowColor: Color = .app.gray2.opacity(0.4)

public init(store: StoreOf<TransactionReview>) {
self.store = store
}
Expand All @@ -121,6 +129,22 @@ extension TransactionReview {
.brightness(viewStore.rawTransaction == nil ? 0 : -0.15)
}
}

ToolbarItem(placement: .principal) {
if showNavigationTitle {
VStack(spacing: 0) {
Text(L10n.TransactionReview.title)
.textStyle(.body2Header)
.foregroundColor(.app.gray1)

if let name = viewStore.proposingDappMetadata?.name {
Text(L10n.TransactionReview.proposingDappSubtitle(name.rawValue))
.textStyle(.body2Regular)
.foregroundColor(.app.gray2)
}
}
}
}
}
.destinations(with: store)
.onAppear {
Expand All @@ -134,6 +158,7 @@ extension TransactionReview {
ScrollView(showsIndicators: false) {
VStack(spacing: 0) {
header(viewStore.proposingDappMetadata)
.measurePosition(navTitleID, coordSpace: coordSpace)
.padding(.horizontal, .medium3)
.padding(.bottom, .medium3)
.background {
Expand Down Expand Up @@ -220,10 +245,20 @@ extension TransactionReview {
.background(.app.gray5.gradient.shadow(.inner(color: shadowColor, radius: 15)))
.animation(.easeInOut, value: viewStore.canToggleViewMode ? viewStore.rawTransaction : nil)
}
.coordinateSpace(name: coordSpace)
.onPreferenceChange(PositionsPreferenceKey.self) { positions in
guard let offset = positions[navTitleID]?.maxY else {
showNavigationTitle = true
return
}
if showNavigationTitle, offset > showTitleHysteresis {
showNavigationTitle = false
} else if !showNavigationTitle, offset < 0 {
showNavigationTitle = true
}
}
}

private let shadowColor: Color = .app.gray2.opacity(0.4)

private func header(_ proposingDappMetadata: DappMetadata.Ledger?) -> some SwiftUI.View {
VStack(alignment: .leading, spacing: .small3) {
HStack(spacing: .zero) {
Expand Down
Loading