Swiftpack.co - nightwill/WPArticleView as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by nightwill.
nightwill/WPArticleView 0.1.4
SwiftUI View for Wordpress JSON API
⭐️ 2
🕓 22 weeks ago
iOS macOS
.package(url: "https://github.com/nightwill/WPArticleView.git", from: "0.1.4")

WPArticleView

Installation

...
dependencies: [
    .package(url: "https://github.com/nightwill/WPArticleView.git", from: "0.1.0"),
],
targets: [
    .target( name: "YourTarget", dependencies: ["WPArticleView"]),
]
...

Usage:

import SwiftUI
import WPArticleView

struct ContentView: View {

    let htmlText: String
        
    var body: some View {
        WPArticleView(htmlBody: htmlText) { blocks in
            
            List(blocks.indices, id: \.self) { id in
                blocks[id]
            }
            
        } attributedText: { attributedText in
            
            Text(attributedText)
            
        } image: { imageURL in
            
            AsyncImage(url: imageURL) { image in
                image.resizable()
                    .aspectRatio(contentMode: .fill)
            } placeholder: {
                ProgressView()
            }
            
        } video: { videoURL in
                    
            VideoPlayer(player: AVPlayer(url: videoURL))
                    .frame(minHeight: 400)
                    
        }
    }
    
}

Or using ScrollView:

import SwiftUI
import WPArticleView

struct ContentView: View {
        
    var body: some View {
        ScrollView {
            LazyVStack(alignment: .leading, spacing: 16) {
                WPArticleView(htmlBody: htmlText) { blocks in
                    
                    ForEach(blocks.indices, id: \.self) { id in
                        blocks[id]
                    }
                    
                    
                } attributedText: { attributedText in
                    
                    Text(attributedText)
                    
                } image: { imageURL in
                    
                    AsyncImage(url: imageURL) { image in
                        image.resizable()
                            .aspectRatio(contentMode: .fill)
                    } placeholder: {
                        ProgressView()
                            .frame(maxWidth: .infinity)
                    }
                    
                } video: { videoURL in
                    
                    VideoPlayer(player: AVPlayer(url: videoURL))
                        .frame(minHeight: 400)
                    
                }
            }
            .padding(24)
        }
        
    }
    
}

GitHub

link
Stars: 2
Last commit: 22 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Dependencies

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics