Fix Page control indicator for not reflecting current index of Image being previewed
Changelog-Fixed: Fix Page control indicator Signed-off-by: Swift Coder <scoder1747@gmail.com>
This commit is contained in:
committed by
Daniel D’Aquino
parent
8c321e479b
commit
184e566b1b
@@ -16,7 +16,7 @@ struct FullScreenCarouselView<Content: View>: View {
|
|||||||
@State var showMenu = true
|
@State var showMenu = true
|
||||||
@State private var imageDict: [URL: UIImage] = [:]
|
@State private var imageDict: [URL: UIImage] = [:]
|
||||||
let settings: UserSettingsStore
|
let settings: UserSettingsStore
|
||||||
@Binding var selectedIndex: Int
|
@ObservedObject var carouselSelection: CarouselSelection
|
||||||
let content: (() -> Content)?
|
let content: (() -> Content)?
|
||||||
|
|
||||||
init(video_coordinator: DamusVideoCoordinator, urls: [MediaUrl], showMenu: Bool = true, settings: UserSettingsStore, selectedIndex: Binding<Int>, @ViewBuilder content: @escaping () -> Content) {
|
init(video_coordinator: DamusVideoCoordinator, urls: [MediaUrl], showMenu: Bool = true, settings: UserSettingsStore, selectedIndex: Binding<Int>, @ViewBuilder content: @escaping () -> Content) {
|
||||||
@@ -24,7 +24,7 @@ struct FullScreenCarouselView<Content: View>: View {
|
|||||||
self.urls = urls
|
self.urls = urls
|
||||||
self._showMenu = State(initialValue: showMenu)
|
self._showMenu = State(initialValue: showMenu)
|
||||||
self.settings = settings
|
self.settings = settings
|
||||||
_selectedIndex = selectedIndex
|
self._carouselSelection = ObservedObject(initialValue: CarouselSelection(index: selectedIndex.wrappedValue))
|
||||||
self.content = content
|
self.content = content
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,12 +33,12 @@ struct FullScreenCarouselView<Content: View>: View {
|
|||||||
self.urls = urls
|
self.urls = urls
|
||||||
self._showMenu = State(initialValue: showMenu)
|
self._showMenu = State(initialValue: showMenu)
|
||||||
self.settings = settings
|
self.settings = settings
|
||||||
_selectedIndex = selectedIndex
|
self._carouselSelection = ObservedObject(initialValue: CarouselSelection(index: selectedIndex.wrappedValue))
|
||||||
self.content = nil
|
self.content = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var background: some ShapeStyle {
|
var background: some ShapeStyle {
|
||||||
if case .video = urls[safe: selectedIndex] {
|
if case .video = urls[safe: carouselSelection.index] {
|
||||||
return AnyShapeStyle(Color.black)
|
return AnyShapeStyle(Color.black)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -55,7 +55,7 @@ struct FullScreenCarouselView<Content: View>: View {
|
|||||||
Color(self.background_color)
|
Color(self.background_color)
|
||||||
.ignoresSafeArea()
|
.ignoresSafeArea()
|
||||||
|
|
||||||
TabView(selection: $selectedIndex) {
|
TabView(selection: $carouselSelection.index) {
|
||||||
ForEach(urls.indices, id: \.self) { index in
|
ForEach(urls.indices, id: \.self) { index in
|
||||||
VStack {
|
VStack {
|
||||||
if case .video = urls[safe: index] {
|
if case .video = urls[safe: index] {
|
||||||
@@ -108,7 +108,7 @@ struct FullScreenCarouselView<Content: View>: View {
|
|||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
if let url = urls[safe: selectedIndex],
|
if let url = urls[safe: carouselSelection.index],
|
||||||
let image = imageDict[url.url] {
|
let image = imageDict[url.url] {
|
||||||
|
|
||||||
ShareLink(item: Image(uiImage: image),
|
ShareLink(item: Image(uiImage: image),
|
||||||
@@ -127,7 +127,7 @@ struct FullScreenCarouselView<Content: View>: View {
|
|||||||
|
|
||||||
VStack {
|
VStack {
|
||||||
if urls.count > 1 {
|
if urls.count > 1 {
|
||||||
PageControlView(currentPage: $selectedIndex, numberOfPages: urls.count)
|
PageControlView(currentPage: $carouselSelection.index, numberOfPages: urls.count)
|
||||||
.frame(maxWidth: 0, maxHeight: 0)
|
.frame(maxWidth: 0, maxHeight: 0)
|
||||||
.padding(.top, 5)
|
.padding(.top, 5)
|
||||||
}
|
}
|
||||||
@@ -189,3 +189,11 @@ struct FullScreenCarouselView_Previews: PreviewProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Class to define object for monitoring selectedIndex and updating mutlples views
|
||||||
|
final class CarouselSelection: ObservableObject {
|
||||||
|
@Published var index: Int
|
||||||
|
init(index: Int) {
|
||||||
|
self.index = index
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user