Extract TransactionsSheetType to unify sheet presentation state#1838
Extract TransactionsSheetType to unify sheet presentation state#1838
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the sheet presentation logic by introducing a unified TransactionsSheetType enum, which replaces multiple state variables in TransactionsViewModel with a single isPresentingSheet property. This change simplifies the view logic in TransactionsNavigationStack by consolidating sheet modifiers. A review comment suggests further improving the readability of the view body by extracting the sheet's content logic into a separate private @ViewBuilder function.
| .sheet(item: $model.isPresentingSheet) { type in | ||
| switch type { | ||
| case .filter: | ||
| NavigationStack { | ||
| TransactionsFilterScene(model: $model.filterModel) | ||
| } | ||
| .presentationDetentsForCurrentDeviceSize(expandable: true) | ||
| .presentationDragIndicator(.visible) | ||
| .presentationBackground(Colors.grayBackground) | ||
| case .selectAsset(let selectType): | ||
| SelectAssetSceneNavigationStack( | ||
| model: SelectAssetViewModel( | ||
| wallet: model.wallet, | ||
| selectType: selectType, | ||
| searchService: assetSearchService, | ||
| assetsEnabler: assetsEnabler, | ||
| priceAlertService: priceAlertService, | ||
| activityService: activityService | ||
| ) | ||
| ) | ||
| ) | ||
| } | ||
| } |
There was a problem hiding this comment.
For better readability and maintainability, consider extracting the sheet's content view builder into a separate private @ViewBuilder function. This will make the body of your view cleaner and easier to read, especially since the switch statement contains non-trivial logic for each case.
For example, you could replace the closure with a method reference:
.sheet(item: $model.isPresentingSheet, content: sheetContent)And then define the sheetContent method within your TransactionsNavigationStack struct:
@ViewBuilder
private func sheetContent(for type: TransactionsSheetType) -> some View {
switch type {
case .filter:
NavigationStack {
TransactionsFilterScene(model: $model.filterModel)
}
.presentationDetentsForCurrentDeviceSize(expandable: true)
.presentationDragIndicator(.visible)
.presentationBackground(Colors.grayBackground)
case .selectAsset(let selectType):
SelectAssetSceneNavigationStack(
model: SelectAssetViewModel(
wallet: model.wallet,
selectType: selectType,
searchService: assetSearchService,
assetsEnabler: assetsEnabler,
priceAlertService: priceAlertService,
activityService: activityService
)
)
}
}
No description provided.