Gemini/GeminiRenderer/DocumentView.swift

50 lines
1.3 KiB
Swift
Raw Normal View History

2020-07-13 22:12:04 +00:00
//
// DocumentView.swift
// GeminiRenderer
//
// Created by Shadowfacts on 7/12/20.
//
import SwiftUI
import GeminiFormat
public struct DocumentView: View {
private let document: Document
private let blocks: [RenderingBlock]
2020-07-15 03:15:56 +00:00
private let changeURL: ((URL) -> Void)?
2020-07-13 22:12:04 +00:00
2020-07-15 03:15:56 +00:00
public init(document: Document, changeURL: ((URL) -> Void)? = nil) {
2020-07-13 22:12:04 +00:00
self.document = document
self.blocks = document.renderingBlocks
2020-07-15 03:15:56 +00:00
self.changeURL = changeURL
2020-07-13 22:12:04 +00:00
}
public var body: some View {
ScrollView(.vertical) {
MaybeLazyVStack(alignment: .leading) {
ForEach(blocks.indices) { (index) in
2020-07-15 03:15:56 +00:00
RenderingBlockView(block: blocks[index], changeURL: changeURL)
2020-07-13 22:12:04 +00:00
}
}.padding()
}
}
}
struct DocumentView_Previews: PreviewProvider {
static var doc: Document {
Document(url: URL(string: "gemini://example.com")!, lines: [
.heading("Hello World", level: .h1),
.text("Some text"),
.preformattedToggle(alt: "blah"),
.preformattedText("test"),
.preformattedToggle(alt: nil),
.quote("whatever"),
.unorderedListItem("something")
])
}
static var previews: some View {
DocumentView(document: doc)
}
}