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.3
SwiftUI View for Wordpress JSON API
⭐️ 1
🕓 31 weeks ago
iOS macOS
.package(url: "https://github.com/nightwill/WPArticleView.git", from: "0.1.3")

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]
            }
            
        } text: { 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]
                    }
                    
                    
                } text: { 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: 1
Last commit: 31 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Dependencies

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