Skip to content

Commit

Permalink
feat: add initial selected index in image viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
juandahurt committed Aug 28, 2022
1 parent 534493f commit 9bac3e4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ struct ImageViewerExample: View {
Spacer()
}.imageViewer(
urls: urls,
isVisible: $isVisible
isVisible: $isVisible,
selectedIndex: 1
)
.navigationBarHidden(true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public struct PuraceImageViewer: View {
Spacer()

indicator
}.frame(height: 50)
}.frame(height: 60)
.opacity((abs(dragOffset) >= .zero && abs(dragOffset) <= 5) ? 1 : 0.0002)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,26 @@ import SwiftUI
public struct PuraceImageViewerModifier: ViewModifier {
let urls: [URL?]
@Binding var isVisible: Bool
let selectedIndex: Int

public init(urls: [URL?], isVisible: Binding<Bool>) {
public init(urls: [URL?], isVisible: Binding<Bool>, selectedIndex: Int) {
self.urls = urls
self._isVisible = isVisible
self.selectedIndex = selectedIndex
}

public func body(content: Content) -> some View {
ZStack {
content
if isVisible {
PuraceImageViewer(urls: urls, isVisible: $isVisible)
PuraceImageViewer(urls: urls, isVisible: $isVisible, index: selectedIndex)
}
}
}
}

public extension View {
func imageViewer(urls: [URL?], isVisible: Binding<Bool>) -> some View {
modifier(PuraceImageViewerModifier(urls: urls, isVisible: isVisible))
func imageViewer(urls: [URL?], isVisible: Binding<Bool>, selectedIndex: Int = 0) -> some View {
modifier(PuraceImageViewerModifier(urls: urls, isVisible: isVisible, selectedIndex: selectedIndex))
}
}

0 comments on commit 9bac3e4

Please sign in to comment.