Skip to content

Commit

Permalink
Support for creator update detail screens
Browse files Browse the repository at this point in the history
  • Loading branch information
mickmaccallum committed Dec 16, 2024
1 parent ef38dd9 commit 04ccf57
Show file tree
Hide file tree
Showing 9 changed files with 315 additions and 275 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ class FeedItemReactor: ObservableObject {
@Published var currentReactions: [ParraReactionSummary]

let feedItemId: String
let reactionOptionGroups: [ParraReactionOptionGroup]
@Published var reactionOptionGroups: [ParraReactionOptionGroup]

var showReactions: Bool {
return !reactionOptionGroups.isEmpty
}

func addNewReaction(
option: ParraReactionOption,
Expand Down
27 changes: 11 additions & 16 deletions ios/Sources/Parra/Containers/Views/Reactions/FeedReactionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,10 @@ struct FeedReactionView: View {

init?(
feedItemId: String,
reactionOptionGroups: [ParraReactionOptionGroup]?,
reactions: [ParraReactionSummary]?
reactor: ObservedObject<FeedItemReactor>
) {
guard let reactionOptionGroups, !reactionOptionGroups.isEmpty else {
return nil
}

self.feedItemId = feedItemId
self._reactor = StateObject(
wrappedValue: FeedItemReactor(
feedItemId: feedItemId,
reactionOptionGroups: reactionOptionGroups,
reactions: reactions ?? []
)
)
self._reactor = reactor
}

// MARK: - Internal
Expand Down Expand Up @@ -60,6 +49,7 @@ struct FeedReactionView: View {
isReactionPickerPresented = true
}
}
.contentShape(.rect)
.onChange(of: pickerSelectedReaction) { oldValue, newValue in
if let newValue, oldValue == nil {
reactor.addNewReaction(
Expand Down Expand Up @@ -91,15 +81,20 @@ struct FeedReactionView: View {

@State private var isReactionPickerPresented: Bool = false
@State private var pickerSelectedReaction: ParraReactionOption?
@StateObject private var reactor: FeedItemReactor
@ObservedObject private var reactor: FeedItemReactor
}

#Preview {
ParraAppPreview {
FeedReactionView(
feedItemId: .uuid,
reactionOptionGroups: ParraReactionOptionGroup.validStates(),
reactions: ParraReactionSummary.validStates()
reactor: ObservedObject(
wrappedValue: FeedItemReactor(
feedItemId: .uuid,
reactionOptionGroups: ParraReactionOptionGroup.validStates(),
reactions: ParraReactionSummary.validStates()
)
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public struct ParraFeedListView: View {
ForEach(
Array(items.enumerated()),
id: \.element
) { index, item in
) {
index,
item in
if case .feedItemYoutubeVideo(let data) = item.data {
FeedYouTubeVideoView(
youtubeVideo: data,
Expand Down Expand Up @@ -78,13 +80,15 @@ public struct ParraFeedListView: View {
}
} else if case .creatorUpdate(let data) = item.data {
FeedCreatorUpdateView(
creatorUpdate: data,
feedItemId: item.id,
reactionOptions: item.reactionOptions?.elements,
reactions: item.reactions?.elements,
containerGeometry: containerGeometry,
spacing: spacing,
performActionForFeedItemData: performActionForFeedItemData
params: FeedCreatorUpdateParams(
creatorUpdate: data,
feedItemId: item.id,
reactionOptions: item.reactionOptions?.elements,
reactions: item.reactions?.elements,
containerGeometry: containerGeometry,
spacing: spacing,
performActionForFeedItemData: performActionForFeedItemData
)
)
} else {
EmptyView()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ struct CreatorUpdateAttachmentsView: View {
content
.background(parraTheme.palette.secondaryBackground.toParraColor())
.sheet(isPresented: $isShowingFullScreen) {
FullScreenGalleryView(
photos: layout.allImages,
selectedPhoto: $selectedPhoto
)
NavigationStack {
FullScreenGalleryView(
photos: layout.allImages,
selectedPhoto: $selectedPhoto
)
}
.transition(.opacity)
.presentationDragIndicator(.visible)
.presentationDetents([.large])
}
}

Expand All @@ -126,8 +126,15 @@ struct CreatorUpdateAttachmentsView: View {
func renderSingle(
_ image: ParraImageAsset
) -> some View {
let width = containerGeometry.size.width - outerSpacing * 2
let height = (image.size.height / image.size.width) * width
let width = max(
containerGeometry.size.width - outerSpacing * 2,
0.0
)

let height = max(
(image.size.height / image.size.width) * width,
0.0
)

renderImageButton(
for: image,
Expand Down Expand Up @@ -176,7 +183,10 @@ struct CreatorUpdateAttachmentsView: View {
_ leftImage: ParraImageAsset,
_ rightImage: ParraImageAsset
) -> some View {
let width = (containerGeometry.size.width - outerSpacing * 2 - innerSpacing) / 2
let width = max(
(containerGeometry.size.width - outerSpacing * 2 - innerSpacing) / 2,
0.0
)

renderDouble(leftImage, rightImage, width, width)
}
Expand All @@ -186,8 +196,15 @@ struct CreatorUpdateAttachmentsView: View {
_ leftImage: ParraImageAsset,
_ rightImage: ParraImageAsset
) -> some View {
let width = (containerGeometry.size.width - outerSpacing * 2 - innerSpacing) / 2
let height = (leftImage.size.height / leftImage.size.width) * width
let width = max(
(containerGeometry.size.width - outerSpacing * 2 - innerSpacing) / 2,
0.0
)

let height = max(
(leftImage.size.height / leftImage.size.width) * width,
0.0
)

renderDouble(leftImage, rightImage, width, height)
}
Expand All @@ -199,10 +216,17 @@ struct CreatorUpdateAttachmentsView: View {
) -> some View {
let imagesBeforeFold = otherImages.prefix(maxToDisplay - 1)
let requiresShowMore = otherImages.count > maxToDisplay - 1
let width = (containerGeometry.size.width - outerSpacing * 2 - innerSpacing) / 2
let height = CGFloat(imagesBeforeFold.count) * width + CGFloat(
imagesBeforeFold.count - 1
) * innerSpacing
let width = max(
(containerGeometry.size.width - outerSpacing * 2 - innerSpacing) / 2,
0.0
)

let height = max(
CGFloat(imagesBeforeFold.count) * width + CGFloat(
imagesBeforeFold.count - 1
) * innerSpacing,
0.0
)

HStack(spacing: innerSpacing) {
renderImageButton(
Expand Down Expand Up @@ -255,10 +279,19 @@ struct CreatorUpdateAttachmentsView: View {
) -> some View {
let imagesBeforeFold = otherImages.prefix(maxToDisplay - 1)
let requiresShowMore = otherImages.count > maxToDisplay - 1
let width = containerGeometry.size.width - outerSpacing * 2
let height = (topImage.size.height / topImage.size.width) * width
let smallSize = (width - CGFloat(imagesBeforeFold.count - 1) * innerSpacing) /
CGFloat(imagesBeforeFold.count)
let width = max(
containerGeometry.size.width - outerSpacing * 2,
0.0
)
let height = max(
(topImage.size.height / topImage.size.width) * width,
0.0
)
let smallSize = max(
(width - CGFloat(imagesBeforeFold.count - 1) * innerSpacing) /
CGFloat(imagesBeforeFold.count),
0.0
)

VStack(spacing: innerSpacing) {
renderImageButton(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// FeedCreatorUpdateDetailHeaderView.swift
// Parra
//
// Created by Mick MacCallum on 12/16/24.
//

import SwiftUI
import UIKit

struct FeedCreatorUpdateDetailHeaderView: View {
let creatorUpdate: ParraCreatorUpdateAppStub
let feedItemId: String
let containerGeometry: GeometryProxy
@ObservedObject var reactor: FeedItemReactor

var body: some View {
VStack(spacing: 0) {
FeedCreatorUpdateHeaderView(
creatorUpdate: creatorUpdate
)
.padding([.horizontal, .top], 16)

FeedCreatorUpdateContentView(
creatorUpdate: creatorUpdate
)
.padding(.horizontal, 16)

if let attachments = creatorUpdate.attachments?.elements,
!attachments.isEmpty,
containerGeometry.size.width > 0 && containerGeometry.size.height > 0
{
ParraPaywalledContentView(
entitlement: creatorUpdate.attachmentPaywall?.entitlement,
context: creatorUpdate.attachmentPaywall?.context
) { requiredEntitlement, unlock in
CreatorUpdateAttachmentsView(
attachments: attachments,
containerGeometry: containerGeometry,
requiredEntitlement: requiredEntitlement
) {
do {
try await unlock()
} catch {
Logger.error("Error unlocking attachment", error)
}
}
} unlockedContentBuilder: {
CreatorUpdateAttachmentsView(
attachments: attachments,
containerGeometry: containerGeometry
)
}
.padding(.top, 8)
}

if reactor.showReactions {
FeedReactionView(
feedItemId: feedItemId,
reactor: _reactor
)
.padding()
.frame(
maxWidth: .infinity,
alignment: .leading
)
}
}
}
}
Loading

0 comments on commit 04ccf57

Please sign in to comment.