-
Notifications
You must be signed in to change notification settings - Fork 894
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…Menu View (brave/brave-ios#8175) * Integrate new MainMenuView to replace context menu used for 3-dot menu in Wallet * Fix entire Wallet dismissing on lock / auto-lock on iOS 16.4 and later
- Loading branch information
1 parent
03a764b
commit ddabb30
Showing
15 changed files
with
377 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
/* Copyright 2023 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import SwiftUI | ||
import Strings | ||
import Preferences | ||
|
||
struct MainMenuView: View { | ||
|
||
let isFromPortfolio: Bool | ||
@Binding var isShowingSettings: Bool | ||
let keyringStore: KeyringStore | ||
|
||
@ObservedObject private var isShowingBalances = Preferences.Wallet.isShowingBalances | ||
@ObservedObject private var isShowingGraph = Preferences.Wallet.isShowingGraph | ||
@ObservedObject private var isShowingNFTs = Preferences.Wallet.isShowingNFTsTab | ||
|
||
@Environment(\.presentationMode) @Binding private var presentationMode | ||
@Environment(\.openURL) private var openWalletURL | ||
|
||
@ScaledMetric var rowHeight: CGFloat = 52 | ||
@State private var viewHeight: CGFloat = 0 | ||
|
||
var body: some View { | ||
ScrollView { | ||
LazyVStack(spacing: 0) { | ||
Button(action: { | ||
presentationMode.dismiss() | ||
keyringStore.lock() | ||
}) { | ||
MenuRowView( | ||
iconBraveSystemName: "leo.lock", | ||
title: Strings.Wallet.lockWallet | ||
) | ||
} | ||
.frame(height: rowHeight) | ||
|
||
Button(action: { | ||
isShowingSettings = true | ||
presentationMode.dismiss() | ||
}) { | ||
MenuRowView( | ||
iconBraveSystemName: "leo.settings", | ||
title: Strings.Wallet.walletSettings | ||
) | ||
} | ||
.frame(height: rowHeight) | ||
|
||
if isFromPortfolio { | ||
Divider() | ||
portfolioSettings | ||
} | ||
|
||
Divider() | ||
Button(action: { | ||
openWalletURL(WalletConstants.braveWalletSupportURL) | ||
}) { | ||
MenuRowView( | ||
iconBraveSystemName: "leo.help.outline", | ||
title: Strings.Wallet.helpCenter, | ||
accessoryContent: { | ||
Image(braveSystemName: "leo.launch") | ||
.imageScale(.large) | ||
.foregroundColor(Color(braveSystemName: .buttonBackground)) | ||
} | ||
) | ||
} | ||
.frame(height: rowHeight) | ||
} | ||
.padding(.vertical, 8) | ||
.readSize { size in | ||
self.viewHeight = size.height | ||
} | ||
} | ||
.background(Color(braveSystemName: .containerBackground)) | ||
.osAvailabilityModifiers({ view in | ||
if #available(iOS 16, *) { | ||
view | ||
.presentationDetents([ | ||
.height(viewHeight) | ||
]) | ||
} else { | ||
view | ||
} | ||
}) | ||
} | ||
|
||
@ViewBuilder private var portfolioSettings: some View { | ||
MenuRowView( | ||
iconBraveSystemName: "leo.eye.on", | ||
title: Strings.Wallet.balances, | ||
accessoryContent: { | ||
Toggle(isOn: $isShowingBalances.value) { | ||
EmptyView() | ||
} | ||
.tint(Color(braveSystemName: .buttonBackground)) | ||
} | ||
) | ||
.frame(height: rowHeight) | ||
|
||
MenuRowView( | ||
iconBraveSystemName: "leo.graph", | ||
title: Strings.Wallet.graph, | ||
accessoryContent: { | ||
Toggle(isOn: $isShowingGraph.value) { | ||
EmptyView() | ||
} | ||
.tint(Color(braveSystemName: .buttonBackground)) | ||
} | ||
) | ||
.frame(height: rowHeight) | ||
|
||
MenuRowView( | ||
iconBraveSystemName: "leo.nft", | ||
title: Strings.Wallet.nftsTab, | ||
accessoryContent: { | ||
Toggle(isOn: $isShowingNFTs.value) { | ||
EmptyView() | ||
} | ||
.tint(Color(braveSystemName: .buttonBackground)) | ||
} | ||
) | ||
.frame(height: rowHeight) | ||
} | ||
} | ||
|
||
#if DEBUG | ||
struct MainMenuView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
Color.white | ||
.sheet(isPresented: .constant(true), content: { | ||
MainMenuView( | ||
isFromPortfolio: true, | ||
isShowingSettings: .constant(false), | ||
keyringStore: .previewStoreWithWalletCreated | ||
) | ||
}) | ||
} | ||
} | ||
#endif | ||
|
||
private struct MenuRowView<AccessoryContent: View>: View { | ||
|
||
let iconBraveSystemName: String | ||
let title: String | ||
let accessoryContent: () -> AccessoryContent | ||
|
||
init( | ||
iconBraveSystemName: String, | ||
title: String, | ||
accessoryContent: @escaping () -> AccessoryContent = { EmptyView() } | ||
) { | ||
self.iconBraveSystemName = iconBraveSystemName | ||
self.title = title | ||
self.accessoryContent = accessoryContent | ||
} | ||
|
||
var body: some View { | ||
HStack(spacing: 12) { | ||
Image(braveSystemName: iconBraveSystemName) | ||
.imageScale(.medium) | ||
.foregroundColor(Color(braveSystemName: .iconDefault)) | ||
Text(title) | ||
.foregroundColor(Color(braveSystemName: .textPrimary)) | ||
Spacer() | ||
accessoryContent() | ||
} | ||
.font(.callout.weight(.semibold)) | ||
.padding(.horizontal) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.