feat(ios): update dependencies to track upstream repository (#11143)

This commit is contained in:
Lakr
2025-03-28 14:12:06 +08:00
committed by GitHub
parent af91a0217f
commit 08ee84e697
108 changed files with 96 additions and 37793 deletions
@@ -9,62 +9,62 @@ import SwiftUI
@main
struct TheApp: App {
var body: some Scene {
WindowGroup {
NavigationView {
Content()
.navigationTitle("MarkdownView")
.navigationBarTitleDisplayMode(.inline)
}
.navigationViewStyle(.stack)
var body: some Scene {
WindowGroup {
NavigationView {
Content()
.navigationTitle("MarkdownView")
.navigationBarTitleDisplayMode(.inline)
}
.navigationViewStyle(.stack)
}
}
}
}
import MarkdownParser
import MarkdownView
class ContentController: UIViewController {
let document = MarkdownParser().feed(testDocument)
let scrollView = UIScrollView()
let markdownView = MarkdownView(theme: .default)
let document = MarkdownParser().feed(testDocument)
let scrollView = UIScrollView()
let markdownView = MarkdownView(theme: .default)
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(scrollView)
scrollView.addSubview(markdownView)
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
scrollView.frame = view.bounds
let width = view.bounds.width - 32
let manifest = document.map {
let manifest = $0.manifest(theme: markdownView.theme)
manifest.setLayoutWidth(width)
manifest.layoutIfNeeded()
return manifest
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(scrollView)
scrollView.addSubview(markdownView)
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
scrollView.frame = view.bounds
let width = view.bounds.width - 32
let manifest = document.map {
let manifest = $0.manifest(theme: markdownView.theme)
manifest.setLayoutWidth(width)
manifest.layoutIfNeeded()
return manifest
}
markdownView.updateContentViews(manifest)
markdownView.frame = .init(
x: 16,
y: 16,
width: width,
height: markdownView.height
)
scrollView.contentSize = .init(
width: width,
height: markdownView.height + 100
)
}
markdownView.updateContentViews(manifest)
markdownView.frame = .init(
x: 16,
y: 16,
width: width,
height: markdownView.height
)
scrollView.contentSize = .init(
width: width,
height: markdownView.height + 100
)
}
}
struct Content: UIViewControllerRepresentable {
func makeUIViewController(context _: Context) -> ContentController {
ContentController()
}
func makeUIViewController(context _: Context) -> ContentController {
ContentController()
}
func updateUIViewController(_: ContentController, context _: Context) {}
func updateUIViewController(_: ContentController, context _: Context) {}
}
let testDocument = ###"""
@@ -13,8 +13,8 @@ let package = Package(
.library(name: "MarkdownView", targets: ["MarkdownView"]),
],
dependencies: [
.package(path: "../MarkdownParserCore"),
.package(url: "https://github.com/JohnSundell/Splash", from: "0.16.0"),
.package(url: "https://github.com/swiftlang/swift-cmark", from: "0.4.0"),
],
targets: [
.target(name: "MarkdownView", dependencies: [
@@ -22,8 +22,8 @@ let package = Package(
"Splash",
]),
.target(name: "MarkdownParser", dependencies: [
.product(name: "MarkdownParserCore", package: "MarkdownParserCore"),
.product(name: "MarkdownParserCoreExtension", package: "MarkdownParserCore"),
.product(name: "cmark-gfm", package: "swift-cmark"),
.product(name: "cmark-gfm-extensions", package: "swift-cmark"),
]),
]
)
@@ -10,11 +10,20 @@ import UIKit
extension UIView {
func diffableUpdate(reusingViews blockViews: inout [BlockView], manifests: [AnyBlockManifest]) {
defer {
assert(blockViews.count == manifests.count, "blockViews count must match manifests count")
}
var shouldRemovedIndices: [Int] = []
defer {
shouldRemovedIndices.sorted(by: >).forEach { index in
blockViews.remove(at: index)
}
}
for idx in 0 ..< max(blockViews.count, manifests.count) {
guard let manifest = manifests[safe: idx] else {
if let view = blockViews[safe: idx] {
view.removeFromSuperview()
blockViews.remove(at: idx)
shouldRemovedIndices.append(idx)
}
continue
}
@@ -39,6 +39,7 @@ public class MarkdownView: UIView {
)
anchorY = view.frame.maxY + theme.spacings.final
}
height = blockViews.map(\.frame.maxY).max() ?? 0
assert(subviews.count == blockViews.count)
}
}