I have List and on click of any cell in sheet it is presenting new View and it is working initially.
I have delete option in each cell which will delete particular cell from list and when I delete any cell and click on other cells in List it is not presenting View.
Anyone knows what could be the issue?
Here is the code to present sheet:
struct StoriesView: View {
enum StoriesSheet: Identifiable {
var id: Int {
switch self {
case .showStory:
return 0
case .addStory:
return 1
case .capturePicture:
return 2
case .editStory:
return 3
case .report:
return 4
}
}
case addStory(data: Data)
case capturePicture(_ type: CaptureImageType)
case showStory(_ story: Story)
case editStory(_ story: Story)
case report(_ story: Story)
}
@StateObject var viewModel = StoriesViewModel()
@State var showRefreshView: Bool = false
@State var showRefreshOnBottom: Bool = false
@State var pullStatus: CGFloat = 0
// Camera
@State var showGetPictureActionSheet = false
@State var currentSheet: StoriesSheet?
var body: some View {
RefreshableList(showRefreshView: $showRefreshView, pullStatus: $pullStatus, action: {
viewModel.apply(.onRefresh)
}, showRefreshOnBottom: $showRefreshOnBottom) {
Group {
if viewModel.shouldShowStories {
storiesList() .padding(.bottom, 80)
.listRowInsets(EdgeInsets())
} else {
EmptyFeedView(imageName: "camera", description: "new_story_description", buttonText: "new_story") {
showGetPictureActionSheet = true
}.frame(minWidth: 0, maxWidth: .infinity, minHeight: 500, maxHeight: .infinity, alignment: .center)
.padding()
}
}.sheet(item: $currentSheet, content: { sheet in
getContent(for: sheet)
})
}
.onAppear {
viewModel.apply(.onRefresh)
}.actionSheet(isPresented: $showGetPictureActionSheet, content: {
getPictureActionSheet()
}).navigationBarItems(leading: EmptyView(), trailing: CameraButton(didSelectType: { (type) in
currentSheet = .capturePicture(type)
}))
}
private func storiesList() -> StoriesListView {
StoriesListView(storiesList: viewModel.storiesList) { story in
self.viewModel.selectedStory = story
currentSheet = .showStory(story)
} didInteractWithStory: { (story, interaction) in
interact(interaction, with: story)
}
}
private func interact(_ interaction: StoryInteraction, with story: Story) {
switch interaction {
case .edit:
currentSheet = .editStory(story)
case .report:
currentSheet = .report(story)
}
}
private func getContent(for sheet: StoriesSheet) -> some View {
switch sheet {
case .showStory(let story):
guard let selectedStory = viewModel.selectedStory else {
return AnyView(StoryDetailView(story: story))
}
return AnyView(StoryDetailView(story: selectedStory))
case .capturePicture(let type):
return AnyView(ImagePicker(type: type) { (data) in
if let data = data {
currentSheet = .addStory(data: data)
} else {
currentSheet = nil
}
})
case .addStory(let data):
return AnyView(AddEditStoryView(viewModel: AddStoryViewModel(imageData: data)))
case .editStory(let story):
return AnyView(AddEditStoryView(viewModel: EditStoryViewModel(story)))
case .report(let story):
return AnyView(ReportReasonSelectionView(story))
}
}
private func getPictureActionSheet() -> ActionSheet {
return ActionSheet(
title: Text("sheet_image_title").font(.system(.headline)),
buttons: [cameraActionSheetButton(),
libraryActionSheetButton(),
.cancel()])
}
private func cameraActionSheetButton() -> Alert.Button {
.default(Text("sheet_image_take_photo"), action: {
currentSheet = .capturePicture(.camera)
})
}
private func libraryActionSheetButton() -> Alert.Button {
.default(Text("sheet_image_pick"), action: {
currentSheet = .capturePicture(.photoLibrary)
})
}
}
Please check Attached complete code for showing story.
Any help will be appreciated. Thanks in Advance.