Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Navigation styling
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenHeaps committed Oct 31, 2023
1 parent e520c04 commit 62e827c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 49 deletions.
48 changes: 1 addition & 47 deletions Sources/BraveWallet/Crypto/CryptoTabsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,33 +58,7 @@ struct CryptoTabsView<DismissContent: ToolbarContent>: View {
)
.navigationTitle(Strings.Wallet.wallet)
.navigationBarTitleDisplayMode(.inline)
.introspectViewController(customize: { vc in
vc.navigationItem.do {
// no shadow when content is at top.
let noShadowAppearance: UINavigationBarAppearance = {
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.titleTextAttributes = [.foregroundColor: UIColor.braveLabel]
appearance.largeTitleTextAttributes = [.foregroundColor: UIColor.braveLabel]
appearance.backgroundColor = UIColor(braveSystemName: .pageBackground)
appearance.shadowColor = .clear
return appearance
}()
$0.scrollEdgeAppearance = noShadowAppearance
$0.compactScrollEdgeAppearance = noShadowAppearance
// shadow when content is scrolled behind navigation bar.
let shadowAppearance: UINavigationBarAppearance = {
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.titleTextAttributes = [.foregroundColor: UIColor.braveLabel]
appearance.largeTitleTextAttributes = [.foregroundColor: UIColor.braveLabel]
appearance.backgroundColor = UIColor(braveSystemName: .pageBackground)
return appearance
}()
$0.standardAppearance = shadowAppearance
$0.compactAppearance = shadowAppearance
}
})
.transparentUnlessScrolledNavigationAppearance()
.toolbar { sharedToolbarItems }
.background(settingsNavigationLink(for: .portfolio))
}
Expand Down Expand Up @@ -243,23 +217,3 @@ struct CryptoTabsView<DismissContent: ToolbarContent>: View {
.hidden()
}
}

private extension View {
func applyRegularNavigationAppearance() -> some View {
introspectViewController(customize: { vc in
vc.navigationItem.do {
let appearance: UINavigationBarAppearance = {
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.titleTextAttributes = [.foregroundColor: UIColor.braveLabel]
appearance.largeTitleTextAttributes = [.foregroundColor: UIColor.braveLabel]
appearance.backgroundColor = .braveBackground
return appearance
}()
$0.standardAppearance = appearance
$0.compactAppearance = appearance
$0.scrollEdgeAppearance = appearance
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct RestoreWalletContainerView: View {
.background(Color(.braveBackground))
}
.background(Color(.braveBackground).edgesIgnoringSafeArea(.all))
.transparentNavigationBar(backButtonTitle: Strings.Wallet.restoreWalletBackButtonTitle, backButtonDisplayMode: .generic)
.transparentUnlessScrolledNavigationAppearance()
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/BraveWallet/Crypto/Portfolio/PortfolioView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct PortfolioView: View {
VStack(spacing: 0) {
Color(braveSystemName: .pageBackground) // top scroll rubberband area
Color(braveSystemName: .containerBackground) // bottom drawer scroll rubberband area
}.edgesIgnoringSafeArea(.bottom)
}.edgesIgnoringSafeArea(.all)
)
}

Expand Down
1 change: 1 addition & 0 deletions Sources/BraveWallet/Crypto/UnlockWalletView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ struct UnlockWalletView: View {
}
.navigationTitle(Strings.Wallet.cryptoTitle)
.navigationBarTitleDisplayMode(.inline)
.transparentUnlessScrolledNavigationAppearance()
.ignoresSafeArea(.keyboard, edges: .bottom)
}

Expand Down
48 changes: 48 additions & 0 deletions Sources/BraveWallet/Extensions/ViewExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ extension View {
self
}
}

/// This function will use the help from `introspectViewController` to find the
/// containing `UIViewController` of the current SwiftUI view and configure its navigation
/// bar appearance to be transparent.
Expand All @@ -31,6 +32,53 @@ extension View {
vc.navigationItem.backButtonDisplayMode = backButtonDisplayMode
}
}

func applyRegularNavigationAppearance() -> some View {
introspectViewController(customize: { vc in
vc.navigationItem.do {
let appearance: UINavigationBarAppearance = {
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.titleTextAttributes = [.foregroundColor: UIColor.braveLabel]
appearance.largeTitleTextAttributes = [.foregroundColor: UIColor.braveLabel]
appearance.backgroundColor = .braveBackground
return appearance
}()
$0.standardAppearance = appearance
$0.compactAppearance = appearance
$0.scrollEdgeAppearance = appearance
}
})
}

func transparentUnlessScrolledNavigationAppearance() -> some View {
introspectViewController(customize: { vc in
vc.navigationItem.do {
// no shadow when content is at top.
let noShadowAppearance: UINavigationBarAppearance = {
let appearance = UINavigationBarAppearance()
appearance.configureWithTransparentBackground()
appearance.titleTextAttributes = [.foregroundColor: UIColor.braveLabel]
appearance.largeTitleTextAttributes = [.foregroundColor: UIColor.braveLabel]
appearance.backgroundColor = .clear
appearance.shadowColor = .clear
return appearance
}()
$0.scrollEdgeAppearance = noShadowAppearance
$0.compactScrollEdgeAppearance = noShadowAppearance
// shadow when content is scrolled behind navigation bar.
let shadowAppearance: UINavigationBarAppearance = {
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.titleTextAttributes = [.foregroundColor: UIColor.braveLabel]
appearance.largeTitleTextAttributes = [.foregroundColor: UIColor.braveLabel]
return appearance
}()
$0.standardAppearance = shadowAppearance
$0.compactAppearance = shadowAppearance
}
})
}

func addAccount(
keyringStore: KeyringStore,
Expand Down

0 comments on commit 62e827c

Please sign in to comment.