https://github.com/jtcodes/swipingmediaview
Photos like media swiping for SwiftUI
https://github.com/jtcodes/swipingmediaview
gifs image media package photo photos swift-package-manager swiftui uipageviewcontroller video
Last synced: about 1 year ago
JSON representation
Photos like media swiping for SwiftUI
- Host: GitHub
- URL: https://github.com/jtcodes/swipingmediaview
- Owner: jtCodes
- Created: 2022-09-09T22:43:51.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-07-04T05:37:52.000Z (almost 2 years ago)
- Last Synced: 2025-03-27T23:51:05.510Z (over 1 year ago)
- Topics: gifs, image, media, package, photo, photos, swift-package-manager, swiftui, uipageviewcontroller, video
- Language: Swift
- Homepage:
- Size: 46.9 KB
- Stars: 11
- Watchers: 2
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SwipingMediaView
### Photos like media swiping for SwiftUI

### Features
- Supports images, gifs and videos
- Pinch to zoom
- Drag to dismiss
- Download images (Important: you must add Privacy - Photo Library Additions Usage Description to info.plist in order to get the download button to work)
### Installation via Swift Package Manager
You can install `SwipingMediaView` using Swift Package Manager in Xcode:
1. Open your Xcode project.
2. Navigate to `File` > `Swift Packages` > `Add Package Dependency`.
3. Enter the repository URL: `https://github.com/jtCodes/SwipingMediaView.git`
4. Specify the version you want to use. You can specify a version number, a branch name, or a commit hash.
5. Once added, you can import `SwipingMediaView` in your SwiftUI files and start using it.
### Simple example
```Swift
import SwiftUI
import SwipingMediaView
struct ContentView: View {
@State var isPresented: Bool = false
@State var currentIndex: Int = 1
var mediaItems: [SwipingMediaItem] = []
init() {
self.mediaItems = [SwipingMediaItem(url: "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/TearsOfSteel.mp4",
type: .video),
SwipingMediaItem(url: "https://i.redd.it/8t6vk567khm91.jpg",
type: .image,
shouldShowDownloadButton: true),
SwipingMediaItem(url: "https://i.redd.it/gczavw14bfm91.gif",
type: .gif)]
}
var body: some View {
ZStack {
Color.green
VStack() {
Text(String(currentIndex))
Spacer()
Button("Present gallery view") {
isPresented = true
}
}.padding(100)
}
.background(Color.blue)
// FullScreenCover works well in presenting SwipingMediaView
.fullScreenCover(isPresented: $isPresented) {
ZStack{
SwipingMediaView(mediaItems: mediaItems,
isPresented: $isPresented,
currentIndex: $currentIndex,
startingIndex: currentIndex)
}
// Adding a clear background helper here to achieve on drag fading background effect
.background(BackgroundCleanerView())
// Ignoring safe area so pinch to zoom don't get cut off
.ignoresSafeArea(.all)
}
.ignoresSafeArea(.all)
}
}
```
### Example with horizontal scrolled images and on swipe handling
```Swift
struct ContentView: View {
@State var isPresented: Bool = false
@State var currentIndex: Int = 1
var images: [String] = []
var mediaItems: [SwipingMediaItem] = []
init() {
for i in 0..<64 {
images.append("https://picsum.photos/250?image=" + String(i))
mediaItems.append(SwipingMediaItem(url: "https://picsum.photos/250?image=" + String(i),
type: .image,
title: "Image " + String(i)))
}
}
var body: some View {
ZStack {
Color.green.opacity(0.5)
VStack() {
Text("Current index: " + String(currentIndex))
Spacer()
}.padding(100)
// Horizontal scrolled image view.
// This is responsible for bringing up the full screen SwipingMediaView.
ScrollViewReader { proxy in
ScrollView(.horizontal, showsIndicators: false) {
HStack {
ForEach(0..