Some scaffolding for multiselect

This commit is contained in:
Jackson Harper 2023-10-30 18:44:13 +08:00
parent 77c69043bc
commit 27632c6924
5 changed files with 107 additions and 66 deletions

View file

@ -34,7 +34,8 @@ public struct ShareExtensionView: View {
public init(viewModel: ShareExtensionViewModel,
labelsViewModel: LabelsViewModel,
extensionContext: NSExtensionContext?) {
extensionContext: NSExtensionContext?)
{
_viewModel = StateObject(wrappedValue: viewModel)
_labelsViewModel = StateObject(wrappedValue: labelsViewModel)
self.extensionContext = extensionContext

View file

@ -32,7 +32,7 @@ struct FeedCardNavigationLink: View {
@EnvironmentObject var audioController: AudioController
let item: LinkedItem
let isInMultiSelectMode: Bool
@ObservedObject var viewModel: HomeFeedViewModel
var body: some View {

View file

@ -86,70 +86,7 @@ struct AnimatingCellHeight: AnimatableModifier {
}
// .navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .barLeading) {
VStack(alignment: .leading) {
let title = (LinkedItemFilter(rawValue: viewModel.appliedFilter) ?? LinkedItemFilter.inbox).displayName
Text(title)
.font(Font.system(size: isListScrolled ? 10 : 18, weight: .semibold))
if prefersListLayout, isListScrolled {
Text(listTitle)
.font(Font.system(size: 15, weight: .regular))
.foregroundColor(Color.appGrayText)
}
}.frame(maxWidth: .infinity, alignment: .leading)
}
ToolbarItem(placement: .barTrailing) {
Button("", action: {})
.disabled(true)
.overlay {
if viewModel.isLoading, !prefersListLayout, enableGrid {
ProgressView()
}
}
}
ToolbarItem(placement: UIDevice.isIPhone ? .barLeading : .barTrailing) {
if enableGrid {
Button(
action: { prefersListLayout.toggle() },
label: {
Label("Toggle Feed Layout", systemImage: prefersListLayout ? "square.grid.2x2" : "list.bullet")
}
)
} else {
EmptyView()
}
}
ToolbarItem(placement: .barTrailing) {
Button(
action: { searchPresented = true },
label: {
Image(systemName: "magnifyingglass")
.resizable()
.frame(width: 18, height: 18)
.padding(.vertical)
.foregroundColor(.appGrayTextContrast)
}
)
}
ToolbarItem(placement: .barTrailing) {
if UIDevice.isIPhone {
Menu(content: {
Button(action: { settingsPresented = true }, label: {
Label(LocalText.genericProfile, systemImage: "person.circle")
})
Button(action: { addLinkPresented = true }, label: {
Label("Add Link", systemImage: "plus.circle")
})
}, label: {
Image.utilityMenu
})
.foregroundColor(.appGrayTextContrast)
} else {
EmptyView()
}
}
toolbarItems
}
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
loadItems(isRefresh: false)
@ -215,6 +152,92 @@ struct AnimatingCellHeight: AnimatableModifier {
}
}
}
var toolbarItems: some ToolbarContent {
Group {
ToolbarItem(placement: .barLeading) {
VStack(alignment: .leading) {
let title = (LinkedItemFilter(rawValue: viewModel.appliedFilter) ?? LinkedItemFilter.inbox).displayName
Text(title)
.font(Font.system(size: isListScrolled ? 10 : 18, weight: .semibold))
if prefersListLayout, isListScrolled {
Text(listTitle)
.font(Font.system(size: 15, weight: .regular))
.foregroundColor(Color.appGrayText)
}
}.frame(maxWidth: .infinity, alignment: .leading)
}
ToolbarItem(placement: .barTrailing) {
Button("", action: {})
.disabled(true)
.overlay {
if viewModel.isLoading, !prefersListLayout, enableGrid {
ProgressView()
}
}
}
ToolbarItem(placement: UIDevice.isIPhone ? .barLeading : .barTrailing) {
if enableGrid {
Button(
action: { prefersListLayout.toggle() },
label: {
Label("Toggle Feed Layout", systemImage: prefersListLayout ? "square.grid.2x2" : "list.bullet")
}
)
} else {
EmptyView()
}
}
ToolbarItem(placement: .barTrailing) {
Button(
action: { searchPresented = true },
label: {
Image(systemName: "magnifyingglass")
.resizable()
.frame(width: 18, height: 18)
.padding(.vertical)
.foregroundColor(.appGrayTextContrast)
}
)
}
ToolbarItem(placement: .barTrailing) {
if UIDevice.isIPhone {
Menu(content: {
// Button(action: {
// // withAnimation {
// viewModel.isInMultiSelectMode.toggle()
// // }
// }, label: {
// Label(viewModel.isInMultiSelectMode ? "End Multiselect" : "Select Multiple", systemImage: "checkmark.circle")
// })
Button(action: { addLinkPresented = true }, label: {
Label("Add Link", systemImage: "plus.circle")
})
Button(action: { settingsPresented = true }, label: {
Label(LocalText.genericProfile, systemImage: "person.circle")
})
}, label: {
Image.utilityMenu
})
.foregroundColor(.appGrayTextContrast)
} else {
EmptyView()
}
}
// if viewModel.isInMultiSelectMode {
// ToolbarItemGroup(placement: .bottomBar) {
// Button(action: {}, label: { Image(systemName: "archivebox") })
// Button(action: {}, label: { Image(systemName: "trash") })
// Button(action: {}, label: { Image.label })
// Spacer()
// Button(action: { viewModel.isInMultiSelectMode = false }, label: { Text("Cancel") })
// }
// }
}
}
}
@MainActor
@ -531,6 +554,7 @@ struct AnimatingCellHeight: AnimatableModifier {
ForEach(viewModel.items) { item in
FeedCardNavigationLink(
item: item,
isInMultiSelectMode: viewModel.isInMultiSelectMode,
viewModel: viewModel
)
.background(GeometryReader { geometry in

View file

@ -24,6 +24,7 @@ import Views
@Published var itemToSnoozeID: String?
@Published var linkRequest: LinkRequest?
@Published var showLoadingBar = false
@Published var isInMultiSelectMode = false
@Published var appliedSort = LinkedItemSort.newest.rawValue
@Published var selectedLinkItem: NSManagedObjectID? // used by mac app only

View file

@ -281,3 +281,18 @@ public struct LibraryItemCard: View {
LabelsFlowLayout(labels: nonFlairLabels)
}
}
struct CircleCheckboxToggleStyle: ToggleStyle {
func makeBody(configuration: Configuration) -> some View {
Button(action: {
configuration.isOn.toggle()
}, label: {
HStack {
Image(systemName: configuration.isOn ? "checkmark.circle" : "circle")
.font(Font.system(size: 18))
.foregroundColor(configuration.isOn ? Color.blue : Color.appGrayTextContrast)
}
})
.buttonStyle(.plain)
}
}