Improved the FolderItem component to for the Browse module to support the folder swipe actions.

This commit is contained in:
Javier Cicchelli 2022-12-14 00:44:01 +01:00
parent 5c402f8958
commit 02c6626d94

View File

@ -12,7 +12,8 @@ struct FolderItem: View {
// MARK: Properties
let name: String
let item: Model
let delete: ItemIdClosure
// MARK: Body
@ -22,7 +23,7 @@ struct FolderItem: View {
.icon(size: 32)
.foregroundColor(.red)
Text(name)
Text(item.name)
.itemName()
Image.chevronRight
@ -31,6 +32,24 @@ struct FolderItem: View {
.font(.headline)
}
.padding(.vertical, 8)
.swipeActions(
edge: .trailing,
allowsFullSwipe: true
) {
Button {
delete(item.id)
} label: {
Label {
Text(
"browse.swipe_action.delete_item.text",
bundle: .module
)
} icon: {
Image.trash
}
}
.tint(.red)
}
}
}
@ -46,10 +65,20 @@ private extension Image {
struct BrowseItem_Previews: PreviewProvider {
static var previews: some View {
FolderItem(name: "Some folder name goes in here...")
.previewDisplayName("Folder item")
FolderItem(item: Folder(
id: "1234567890",
name: "Some folder name goes in here..."
)) { _ in
// delete closure with item id.
}
.previewDisplayName("Folder item")
FolderItem(name: "Some very, extremely long folder name goes in here...")
.previewDisplayName("Folder item with long name")
FolderItem(item: Folder(
id: "1234567890",
name: "Some very, extremely long folder name goes in here..."
)) { _ in
// delete closire with item id.
}
.previewDisplayName("Folder item with long name")
}
}