2023-02-02 21:41:10 -06:00
|
|
|
//
|
|
|
|
// FeedDetailStoryView.swift
|
|
|
|
// NewsBlur
|
|
|
|
//
|
|
|
|
// Created by David Sinclair on 2023-02-01.
|
|
|
|
// Copyright © 2023 NewsBlur. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
/// Story view within the feed detail, only used in grid layout.
|
|
|
|
struct StoryView: View {
|
|
|
|
let cache: StoryCache
|
|
|
|
|
|
|
|
let story: Story
|
|
|
|
|
|
|
|
let interaction: FeedDetailInteraction
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
VStack {
|
2023-03-03 21:38:55 -07:00
|
|
|
StoryHeaderView(cache: cache, story: story, interaction: interaction)
|
|
|
|
StoryPagesView(story: story, interaction: interaction)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct StoryHeaderView: View {
|
|
|
|
let cache: StoryCache
|
|
|
|
|
|
|
|
let story: Story
|
|
|
|
|
|
|
|
let interaction: FeedDetailInteraction
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
ZStack {
|
|
|
|
Color.themed([0xFFFDEF, 0xEEECCD, 0x303A40, 0x303030])
|
|
|
|
|
|
|
|
HStack {
|
|
|
|
Text(story.title)
|
|
|
|
.padding()
|
2023-02-02 21:41:10 -06:00
|
|
|
|
2023-03-03 21:38:55 -07:00
|
|
|
Spacer()
|
|
|
|
|
|
|
|
if let image = previewImage {
|
|
|
|
gridPreview(image: image)
|
2023-02-02 21:41:10 -06:00
|
|
|
}
|
2023-03-03 21:38:55 -07:00
|
|
|
|
|
|
|
Text(story.dateString)
|
|
|
|
.padding()
|
2023-02-02 21:41:10 -06:00
|
|
|
}
|
2023-03-03 21:38:55 -07:00
|
|
|
}
|
|
|
|
.font(.custom("WhitneySSm-Medium", size: 14, relativeTo: .body))
|
|
|
|
.foregroundColor(Color.themed([0x686868, 0xA0A0A0]))
|
|
|
|
.frame(height: 50)
|
|
|
|
.clipShape(RoundedRectangle(cornerRadius: 10))
|
|
|
|
.onTapGesture {
|
|
|
|
interaction.hid(story: story)
|
2023-02-02 21:41:10 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var previewImage: UIImage? {
|
2023-03-02 15:31:21 -07:00
|
|
|
guard cache.settings.preview != .none, let image = cache.appDelegate.cachedImage(forStoryHash: story.hash), image.isKind(of: UIImage.self) else {
|
2023-02-02 21:41:10 -06:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return image
|
|
|
|
}
|
|
|
|
|
|
|
|
@ViewBuilder
|
|
|
|
func gridPreview(image: UIImage) -> some View {
|
|
|
|
Image(uiImage: image)
|
|
|
|
.resizable()
|
|
|
|
.scaledToFill()
|
2023-03-03 21:38:55 -07:00
|
|
|
.frame(width: 76, height: 36)
|
|
|
|
.clipShape(RoundedRectangle(cornerRadius: 6))
|
2023-02-02 21:41:10 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct StoryPagesView: UIViewControllerRepresentable {
|
|
|
|
typealias UIViewControllerType = StoryPagesViewController
|
|
|
|
|
|
|
|
let appDelegate = NewsBlurAppDelegate.shared!
|
|
|
|
|
2023-03-03 21:38:55 -07:00
|
|
|
let story: Story
|
|
|
|
|
|
|
|
let interaction: FeedDetailInteraction
|
|
|
|
|
2023-02-02 21:41:10 -06:00
|
|
|
func makeUIViewController(context: Context) -> StoryPagesViewController {
|
|
|
|
appDelegate.detailViewController.prepareStoriesForGridView()
|
|
|
|
|
|
|
|
return appDelegate.storyPagesViewController
|
|
|
|
}
|
|
|
|
|
|
|
|
func updateUIViewController(_ storyPagesViewController: StoryPagesViewController, context: Context) {
|
|
|
|
storyPagesViewController.updatePage(withActiveStory: appDelegate.storiesCollection.locationOfActiveStory(), updateFeedDetail: false)
|
2023-03-03 21:38:55 -07:00
|
|
|
|
|
|
|
interaction.reading(story: story)
|
|
|
|
|
2023-04-19 21:35:34 -07:00
|
|
|
let size = storyPagesViewController.currentPage.webView.scrollView.contentSize
|
2023-03-03 21:38:55 -07:00
|
|
|
|
2023-04-19 21:35:34 -07:00
|
|
|
storyPagesViewController.preferredContentSize = CGSize(width: size.width, height: 200)
|
2023-03-03 21:38:55 -07:00
|
|
|
|
|
|
|
storyPagesViewController.currentPage.webView.evaluateJavaScript(
|
|
|
|
"document.body.lastChild.getBoundingClientRect().bottom + window.scrollY"
|
|
|
|
) { (result, _) in
|
|
|
|
guard let height = result as? CGFloat, height > 0 else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-04-19 21:35:34 -07:00
|
|
|
storyPagesViewController.preferredContentSize = CGSize(width: size.width, height: height + 80)
|
2023-03-03 21:38:55 -07:00
|
|
|
}
|
2023-02-02 21:41:10 -06:00
|
|
|
}
|
|
|
|
}
|