diff --git a/RadixWallet.xcodeproj/project.pbxproj b/RadixWallet.xcodeproj/project.pbxproj index 159346b1ce..89667af2de 100644 --- a/RadixWallet.xcodeproj/project.pbxproj +++ b/RadixWallet.xcodeproj/project.pbxproj @@ -783,6 +783,7 @@ 5B8433A62CD011DE00CA00F5 /* PreAuthorizationClient+Test.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B8433A52CD011DC00CA00F5 /* PreAuthorizationClient+Test.swift */; }; 5B8433A82CD0128000CA00F5 /* PreAuthorizationClient+Live.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B8433A72CD0127900CA00F5 /* PreAuthorizationClient+Live.swift */; }; 5B8433AA2CD0131B00CA00F5 /* PreAuthorizationFailure.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B8433A92CD0131500CA00F5 /* PreAuthorizationFailure.swift */; }; + 5B8F770B2CD94CAD00154A76 /* VisibleHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B8F770A2CD94CA900154A76 /* VisibleHeaderView.swift */; }; 5B96DD372BD917B300722882 /* Text+Extra.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B96DD362BD917B300722882 /* Text+Extra.swift */; }; 5B9846BD2BBD5C8800E814F3 /* SensitiveInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 5B9846BC2BBD5C8800E814F3 /* SensitiveInfo.plist */; }; 5B9846C02BBD5F0800E814F3 /* SensitiveInfoClient+Interface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B9846BF2BBD5F0800E814F3 /* SensitiveInfoClient+Interface.swift */; }; @@ -2020,6 +2021,7 @@ 5B8433A52CD011DC00CA00F5 /* PreAuthorizationClient+Test.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PreAuthorizationClient+Test.swift"; sourceTree = ""; }; 5B8433A72CD0127900CA00F5 /* PreAuthorizationClient+Live.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PreAuthorizationClient+Live.swift"; sourceTree = ""; }; 5B8433A92CD0131500CA00F5 /* PreAuthorizationFailure.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreAuthorizationFailure.swift; sourceTree = ""; }; + 5B8F770A2CD94CA900154A76 /* VisibleHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VisibleHeaderView.swift; sourceTree = ""; }; 5B96DD362BD917B300722882 /* Text+Extra.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Text+Extra.swift"; sourceTree = ""; }; 5B9846BC2BBD5C8800E814F3 /* SensitiveInfo.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = SensitiveInfo.plist; sourceTree = ""; }; 5B9846BF2BBD5F0800E814F3 /* SensitiveInfoClient+Interface.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SensitiveInfoClient+Interface.swift"; sourceTree = ""; }; @@ -5539,6 +5541,7 @@ 5B27FBE82CC70AC2002975BE /* Components */ = { isa = PBXGroup; children = ( + 5B8F770A2CD94CA900154A76 /* VisibleHeaderView.swift */, 5B27FBD82CC67655002975BE /* HeadingView.swift */, 5B27FBEB2CC70E87002975BE /* ExpandableHeadingView.swift */, 5B03E3D42CC1487400E10A64 /* TransferLineView.swift */, @@ -7594,6 +7597,7 @@ 48CFC4042ADC10D900E77A5C /* KeychainHolder.swift in Sources */, 48CFC4392ADC10DA00E77A5C /* Sorted.swift in Sources */, 5B272DD92C36E93100B74F1F /* AppEventsClient+Live.swift in Sources */, + 5B8F770B2CD94CAD00154A76 /* VisibleHeaderView.swift in Sources */, 48CFC34B2ADC10D900E77A5C /* OneTimePersonaData.swift in Sources */, A408159A2C7E0D08005E65B9 /* MetadataOriginArrayValue.swift in Sources */, 48CFC3832ADC10D900E77A5C /* GeneralHelperViews.swift in Sources */, diff --git a/RadixWallet/Features/InteractionReview/Components/VisibleHeaderView.swift b/RadixWallet/Features/InteractionReview/Components/VisibleHeaderView.swift new file mode 100644 index 0000000000..4fe61aa7f2 --- /dev/null +++ b/RadixWallet/Features/InteractionReview/Components/VisibleHeaderView.swift @@ -0,0 +1,96 @@ +import SwiftUI + +extension InteractionReview { + struct VisibleHeaderView: SwiftUI.View { + let kind: InteractionReview.Kind + let metadata: DappMetadata.Ledger? + let content: Content + + init( + kind: InteractionReview.Kind, + metadata: DappMetadata.Ledger?, + @ViewBuilder content: () -> Content + ) { + self.kind = kind + self.metadata = metadata + self.content = content() + } + + @SwiftUI.State private var showNavigationTitle = false + + private let coordSpace: String = "InteractionReviewCoordSpace" + private let navTitleID: String = "InteractionReview.title" + private let showTitleHysteresis: CGFloat = .small3 + + var body: some View { + ScrollView(showsIndicators: false) { + VStack(spacing: .zero) { + header + + content + } + } + .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 + } + } + .toolbar { + ToolbarItem(placement: .principal) { + if showNavigationTitle { + navigationTitle + } + } + } + } + + private var header: some SwiftUI.View { + Common.HeaderView( + kind: kind, + name: metadata?.name?.rawValue, + thumbnail: metadata?.thumbnail + ) + .measurePosition(navTitleID, coordSpace: coordSpace) + .padding(.horizontal, .medium3) + .padding(.bottom, .medium3) + .background { + switch kind { + case .transaction: + JaggedEdge(shadowColor: InteractionReview.shadowColor, isTopEdge: true) + case .preAuthorization: + EmptyView() + } + } + } + + private var navigationTitle: some SwiftUI.View { + VStack(spacing: .zero) { + Text(title) + .textStyle(.body2Header) + .foregroundColor(.app.gray1) + + if let dAppName = metadata?.name?.rawValue { + Text(L10n.PreAuthorizationReview.subtitle(dAppName)) + .textStyle(.body2Regular) + .foregroundColor(.app.gray2) + } + } + } + + private var title: String { + switch kind { + case .transaction: + L10n.TransactionReview.title + case .preAuthorization: + L10n.PreAuthorizationReview.title + } + } + } +} diff --git a/RadixWallet/Features/InteractionReview/Helpers/InteractionReview+Extra.swift b/RadixWallet/Features/InteractionReview/Helpers/InteractionReview+Extra.swift index 3e23aeab16..4114d04679 100644 --- a/RadixWallet/Features/InteractionReview/Helpers/InteractionReview+Extra.swift +++ b/RadixWallet/Features/InteractionReview/Helpers/InteractionReview+Extra.swift @@ -9,4 +9,6 @@ extension InteractionReview { ) static let transferLineTrailingPadding: CGFloat = .huge3 + + static let shadowColor: Color = .app.gray2.opacity(0.4) } diff --git a/RadixWallet/Features/PreAuthorizationReview/PreAuthorizationReview+View.swift b/RadixWallet/Features/PreAuthorizationReview/PreAuthorizationReview+View.swift index 0c9a273099..1d1d9f3ef9 100644 --- a/RadixWallet/Features/PreAuthorizationReview/PreAuthorizationReview+View.swift +++ b/RadixWallet/Features/PreAuthorizationReview/PreAuthorizationReview+View.swift @@ -36,24 +36,10 @@ extension PreAuthorizationReview { struct View: SwiftUI.View { let store: StoreOf - @SwiftUI.State private var showNavigationTitle = false - - private let coordSpace: String = "PreAuthorizationReviewCoordSpace" - private let navTitleID: String = "PreAuthorizationReview.title" - private let showTitleHysteresis: CGFloat = .small3 - var body: some SwiftUI.View { WithViewStore(store, observe: \.viewState, send: { .view($0) }) { viewStore in content(viewStore) .controlState(viewStore.globalControlState) - .background(.app.white) - .toolbar { - ToolbarItem(placement: .principal) { - if showNavigationTitle { - navigationTitle(dAppName: viewStore.dAppName) - } - } - } .onAppear { store.send(.view(.appeared)) } @@ -61,25 +47,9 @@ extension PreAuthorizationReview { } } - private func navigationTitle(dAppName: String?) -> some SwiftUI.View { - VStack(spacing: .zero) { - Text(L10n.PreAuthorizationReview.title) - .textStyle(.body2Header) - .foregroundColor(.app.gray1) - - if let dAppName { - Text(L10n.PreAuthorizationReview.subtitle(dAppName)) - .textStyle(.body2Regular) - .foregroundColor(.app.gray2) - } - } - } - private func content(_ viewStore: ViewStoreOf) -> some SwiftUI.View { - ScrollView(showsIndicators: false) { - VStack(spacing: .zero) { - header(dAppMetadata: viewStore.dAppMetadata) - + Common.VisibleHeaderView(kind: .preAuthorization, metadata: viewStore.dAppMetadata) { + Group { Group { if let manifest = viewStore.displayMode.rawManifest { rawManifest(manifest) @@ -106,29 +76,6 @@ extension PreAuthorizationReview { } .animation(.easeInOut, value: viewStore.displayMode.rawManifest) } - .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 func header(dAppMetadata: DappMetadata.Ledger?) -> some SwiftUI.View { - Common.HeaderView( - kind: .preAuthorization, - name: dAppMetadata?.name?.rawValue, - thumbnail: dAppMetadata?.thumbnail - ) - .measurePosition(navTitleID, coordSpace: coordSpace) - .padding(.horizontal, .medium3) - .padding(.bottom, .medium3) } private func rawManifest(_ manifest: String) -> some SwiftUI.View { diff --git a/RadixWallet/Features/TransactionReviewFeature/TransactionReview+View.swift b/RadixWallet/Features/TransactionReviewFeature/TransactionReview+View.swift index 40825abc85..ee1f4d56f7 100644 --- a/RadixWallet/Features/TransactionReviewFeature/TransactionReview+View.swift +++ b/RadixWallet/Features/TransactionReviewFeature/TransactionReview+View.swift @@ -59,16 +59,8 @@ extension TransactionReview { @MainActor struct View: SwiftUI.View { - @SwiftUI.State private var showNavigationTitle: Bool = false - private let store: StoreOf - 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) - init(store: StoreOf) { self.store = store } @@ -89,22 +81,6 @@ extension TransactionReview { .brightness(viewStore.rawManifest == 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 { @@ -115,10 +91,8 @@ extension TransactionReview { @ViewBuilder private func coreView(with viewStore: ViewStoreOf) -> some SwiftUI.View { - ScrollView(showsIndicators: false) { - VStack(spacing: 0) { - header(viewStore.proposingDappMetadata) - + Common.VisibleHeaderView(kind: .transaction, metadata: viewStore.proposingDappMetadata) { + VStack(spacing: .zero) { if let manifest = viewStore.rawManifest { Common.RawManifestView(manifest: manifest) { viewStore.send(.copyRawTransactionTapped) @@ -154,38 +128,12 @@ extension TransactionReview { .padding(.vertical, .large3) .padding(.horizontal, .large2) .background { - JaggedEdge(shadowColor: shadowColor, isTopEdge: false) + JaggedEdge(shadowColor: Common.shadowColor, isTopEdge: false) } } .background(Common.gradientBackground) .animation(.easeInOut, value: viewStore.canToggleViewMode ? viewStore.rawManifest : 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 func header(_ proposingDappMetadata: DappMetadata.Ledger?) -> some SwiftUI.View { - Common.HeaderView( - kind: .transaction, - name: proposingDappMetadata?.name?.rawValue, - thumbnail: proposingDappMetadata?.thumbnail - ) - .measurePosition(navTitleID, coordSpace: coordSpace) - .padding(.horizontal, .medium3) - .padding(.bottom, .medium3) - .background { - JaggedEdge(shadowColor: shadowColor, isTopEdge: true) - } } @ViewBuilder