Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for alpha #363

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions winston/components/FilterButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ struct FilterButton: View, Equatable {
var filterCallback: ((String) -> ())
var searchText: String
var searchCallback: ((String?) -> ())
var customFilterCallback: ((FilterData) -> ())
let colorDotSize: Double = 8
let hPadding: Double = 14
let height: Double = 32
let longPressDuration: Double = 0.275

// @GestureState private var pressingDown = false
@State private var pressingDown = false
@State private var editTimer: Timer? = nil

var body: some View {
let isSelected = filter.type == "search" ? searchText.lowercased() == filter.text.lowercased() : isSelected
Expand Down Expand Up @@ -76,6 +79,15 @@ struct FilterButton: View, Equatable {
}
.onLongPressGesture(minimumDuration: .infinity, maximumDistance: 10, perform: {}, onPressingChanged: { val in
pressingDown = val

if val && filter.type != "flair" {
editTimer = Timer.scheduledTimer(withTimeInterval: longPressDuration, repeats: false) { _ in
Hap.shared.play(intensity: 0.75, sharpness: 0.9)
customFilterCallback(filter)
}
} else {
editTimer?.invalidate()
}
})
}
}
68 changes: 53 additions & 15 deletions winston/components/FloatingFeedMenu/FloatingFeedMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,24 @@

import SwiftUI
import Combine

import Defaults

struct FloatingFeedMenu: View, Equatable {
static func == (lhs: FloatingFeedMenu, rhs: FloatingFeedMenu) -> Bool {
lhs.filters == rhs.filters && lhs.selected == rhs.selected && lhs.menuOpen == rhs.menuOpen
lhs.subId == rhs.subId && lhs.filters == rhs.filters && lhs.selected == rhs.selected && lhs.menuOpen == rhs.menuOpen
}

var subId: String
var filters: [FilterData]
var selected: String
var filterCallback: ((String) -> ())
var searchText: String
var searchCallback: ((String?) -> ())
var customFilterCallback: ((FilterData) -> ())

@State private var menuOpen = false
@State private var showingFilters = false
@State var compact: Bool = false

@Namespace private var ns

Expand All @@ -32,6 +35,21 @@ struct FloatingFeedMenu: View, Equatable {

var itemsSpacingDownscaled: Double { itemsSpacing - ((mainTriggerSize - actionsSize) / 2) }

@Default(.SubredditFeedDefSettings) var subredditFeedDefSettings
@Default(.PostLinkDefSettings) var postLinkDefSettings

init(subId: String, filters: [FilterData], selected: String, filterCallback: @escaping ((String) -> ()), searchText: String, searchCallback: @escaping ((String?) -> ()), customFilterCallback: @escaping ((FilterData) -> ())) {
self.subId = subId
self.filters = filters
self.selected = selected
self.filterCallback = filterCallback
self.searchText = searchText
self.searchCallback = searchCallback
self.customFilterCallback = customFilterCallback

_compact = State(initialValue: subredditFeedDefSettings.compactPerSubreddit[subId] ?? postLinkDefSettings.compactMode.enabled)
}

func dismiss() {
if menuOpen {
Hap.shared.play(intensity: 0.75, sharpness: 0.4)
Expand All @@ -53,7 +71,7 @@ struct FloatingFeedMenu: View, Equatable {
HStack(alignment: .bottom, spacing: 0) {
ZStack(alignment: .bottomTrailing) {
if !showingFilters, !selected.isEmpty, let selectedFilter = filters.first(where: { $0.id == selected }) {
FilterButton(filter: selectedFilter, isSelected: true, filterCallback: filterCallback, searchText: searchText, searchCallback: searchCallback)
FilterButton(filter: selectedFilter, isSelected: true, filterCallback: filterCallback, searchText: searchText, searchCallback: searchCallback, customFilterCallback: customFilterCallback)
.equatable()
.matchedGeometryEffect(id: "floating-\(selectedFilter.id)", in: ns, properties: .position)
.padding(.trailing, itemsSpacingDownscaled)
Expand All @@ -68,27 +86,34 @@ struct FloatingFeedMenu: View, Equatable {
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 8) {

ForEach(Array(customFilters.enumerated()).reversed(), id: \.element) {
let isSelected = selected == $1.id
FilterButton(filter: $1, isSelected: isSelected, filterCallback: filterCallback, searchText: searchText, searchCallback: searchCallback)
ForEach(Array(sortedFlairs.enumerated()).reversed(), id: \.element) { i, el in
let isSelected = selected == el.id
let placeholder = isSelected && !showingFilters
let elId = "floating-\(el.id)\(placeholder ? "-placeholder" : "")"
FilterButton(filter: el, isSelected: isSelected, filterCallback: filterCallback, searchText: searchText, searchCallback: searchCallback, customFilterCallback: customFilterCallback)
.equatable()
.matchedGeometryEffect(id: "floating-\($1.id)", in: ns)
.matchedGeometryEffect(id: elId, in: ns, properties: .position)
.scaleEffect(showingFilters || isSelected ? 1 : 0.01, anchor: .trailing)
.opacity((showingFilters || isSelected) && !placeholder ? 1 : 0)
.animation(.bouncy.delay(Double(showingFilters && !isSelected ? i + customFilters.count : 0) * 0.125), value: showingFilters)
.transition(.offset(x: 0.01))
.id(elId)
}

ForEach(Array(sortedFlairs.enumerated()).reversed(), id: \.element) { i, el in
ForEach(Array(customFilters.enumerated()).reversed(), id: \.element) { i, el in
let isSelected = selected == el.id
let placeholder = isSelected && !showingFilters
let elId = "floating-\(el.id)\(placeholder ? "-placeholder" : "")"
FilterButton(filter: el, isSelected: isSelected, filterCallback: filterCallback, searchText: searchText, searchCallback: searchCallback)

FilterButton(filter: el, isSelected: isSelected, filterCallback: filterCallback, searchText: searchText, searchCallback: searchCallback, customFilterCallback: customFilterCallback)
.equatable()
.matchedGeometryEffect(id: elId, in: ns, properties: .position)
.matchedGeometryEffect(id: "floating-\(el.id)", in: ns)
.scaleEffect(showingFilters || isSelected ? 1 : 0.01, anchor: .trailing)
.opacity((showingFilters || isSelected) && !placeholder ? 1 : 0)
.animation(.bouncy.delay(Double(showingFilters && !isSelected ? i : 0) * 0.125), value: showingFilters)
.transition(.offset(x: 0.01))
.id(elId)
}

}
.padding(.trailing, itemsSpacingDownscaled)
.padding(.leading, 12)
Expand Down Expand Up @@ -117,17 +142,30 @@ struct FloatingFeedMenu: View, Equatable {
.floating()
.transition(.comeFrom(.bottom, index: 1, total: 2))

Image(systemName: "hand.tap.fill")
Image(systemName: compact ? "doc.text.image" : "doc.plaintext")
.fontSize(22, .bold)
.frame(width: actionsSize, height: actionsSize)
.foregroundColor(Color.accentColor)
.floating()
.transition(.comeFrom(.bottom, index: 0, total: 2))
.onTapGesture {
compact = !compact
subredditFeedDefSettings.compactPerSubreddit[self.subId] = compact
}

Image(systemName: "plus")
.fontSize(22, .bold)
.frame(width: actionsSize, height: actionsSize)
.foregroundColor(Color.accentColor)
.floating()
.transition(.comeFrom(.bottom, index: 0, total: 2))
.onTapGesture {
customFilterCallback(FilterData())
}
}
}

FloatingMainTrigger(menuOpen: $menuOpen, showingFilters: $showingFilters, dismiss: dismiss, size: mainTriggerSize, actionsSize: actionsSize).equatable()

}
.padding([.trailing, .bottom], screenEdgeMargin)
}
Expand All @@ -138,9 +176,9 @@ struct FloatingFeedMenu: View, Equatable {


extension View {
func floatingMenu(filters: [FilterData], selected: String, filterCallback: @escaping ((String) -> ()), searchText: String, searchCallback: @escaping ((String?) -> ())) -> some View {
func floatingMenu(subId: String, filters: [FilterData], selected: String, filterCallback: @escaping ((String) -> ()), searchText: String, searchCallback: @escaping ((String?) -> ()), customFilterCallback: @escaping ((FilterData) -> ())) -> some View {
self
.overlay(FloatingFeedMenu(filters: filters, selected: selected, filterCallback: filterCallback, searchText: searchText, searchCallback: searchCallback).equatable(), alignment: .bottomTrailing)
.overlay(FloatingFeedMenu(subId: subId, filters: filters, selected: selected, filterCallback: filterCallback, searchText: searchText, searchCallback: searchCallback, customFilterCallback: customFilterCallback).equatable(), alignment: .bottomTrailing)
}
}

Expand Down
22 changes: 20 additions & 2 deletions winston/components/FloatingFeedMenu/FloatingMainTrigger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import SwiftUI
import Defaults

struct FloatingMainTrigger: View, Equatable {
static func == (lhs: FloatingMainTrigger, rhs: FloatingMainTrigger) -> Bool {
Expand All @@ -24,10 +25,12 @@ struct FloatingMainTrigger: View, Equatable {
@State private var toggleTimer: Timer? = nil
@GestureState private var pressingDown = false

@Default(.SubredditFeedDefSettings) var subredditFeedDefSettings

private let longPressDuration: Double = 0.275

var body: some View {
Image(systemName: toggled || menuOpen ? "xmark" : "newspaper.fill")
Image(systemName: toggled || menuOpen ? "xmark" : "slider.vertical.3")
.contentTransition(.symbolEffect)
.transaction { trans in
trans.animation = .easeInOut(duration: longPressDuration)
Expand Down Expand Up @@ -62,7 +65,22 @@ struct FloatingMainTrigger: View, Equatable {
}
}
)
.simultaneousGesture(TapGesture().onEnded(dismiss))
.simultaneousGesture(TapGesture().onEnded({
if menuOpen {
dismiss()
} else if subredditFeedDefSettings.openOptionsOnTap {
Hap.shared.play(intensity: 0.75, sharpness: 0.4)
withAnimation(.snappy(extraBounce: 0.3)) {
menuOpen = true
toggled = false
}
doThisAfter(0) {
withAnimation {
showingFilters = true
}
}
}
}))
.allowsHitTesting(!disable)
.onChange(of: pressingDown) {
if $0 {
Expand Down
8 changes: 4 additions & 4 deletions winston/components/Links/MixedContentLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ struct MixedContentLink: View, Equatable {
switch content {
case .first(let post):
if let winstonData = post.winstonData, let postSub = winstonData.subreddit {
PostLink(id: post.id, theme: theme, showSub: true, contentWidth: contentWidth, defSettings: postLinkDefSettings)
.environmentObject(post)
.environmentObject(postSub)
.environmentObject(winstonData)
PostLink(id: post.id, theme: theme, showSub: true, compactPerSubreddit: nil, contentWidth: contentWidth, defSettings: postLinkDefSettings)
.environmentObject(post)
.environmentObject(postSub)
.environmentObject(winstonData)
}
case .second(let comment):
VStack {
Expand Down
5 changes: 3 additions & 2 deletions winston/components/Links/PostLink/PostLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let POSTLINK_INNER_H_PAD: CGFloat = 16

struct PostLink: View, Equatable, Identifiable {
static func == (lhs: PostLink, rhs: PostLink) -> Bool {
return lhs.id == rhs.id && lhs.repostAvatarRequest?.url == rhs.repostAvatarRequest?.url && lhs.theme == rhs.theme && lhs.defSettings == rhs.defSettings
return lhs.id == rhs.id && lhs.repostAvatarRequest?.url == rhs.repostAvatarRequest?.url && lhs.theme == rhs.theme && lhs.defSettings == rhs.defSettings && lhs.compactPerSubreddit == rhs.compactPerSubreddit
}

// var disableOuterVSpacing = false
Expand All @@ -26,13 +26,14 @@ struct PostLink: View, Equatable, Identifiable {
var theme: SubPostsListTheme
var showSub = false
var secondary = false
let compactPerSubreddit: Bool?
let contentWidth: CGFloat
var defSettings: PostLinkDefSettings = Defaults[.PostLinkDefSettings]

var body: some View {

Group {
if defSettings.compactMode.enabled {
if compactPerSubreddit ?? defSettings.compactMode.enabled {
PostLinkCompact(
id: id,
controller: controller,
Expand Down
1 change: 1 addition & 0 deletions winston/components/Links/PostLink/PostLinkNormal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ struct PostLinkNormal: View, Equatable, Identifiable {
theme: theme,
showSub: true,
secondary: true,
compactPerSubreddit: false,
contentWidth: contentWidth,
defSettings: defSettings
)
Expand Down
8 changes: 4 additions & 4 deletions winston/components/Links/PostLink/getPostContentWidth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func getPostDimensions(post: Post, winstonData: PostWinstonData? = nil, columnWi

if let extractedMedia = extractedMedia {
switch extractedMedia {
case .link(_), .post(_), .comment(_), .subreddit(_), .user(_):
case .link(_), .post(_), .comment(_), .subreddit(_), .user(_), .repost(_):
urlTagHeight = OnlyURL.height
default:
break
Expand All @@ -146,16 +146,16 @@ func getPostDimensions(post: Post, winstonData: PostWinstonData? = nil, columnWi

var appendStr = ""
let titleAttr = NSMutableAttributedString(string: title, attributes: [.font: UIFont.systemFont(ofSize: theme.titleText.size + 0.35, weight: theme.titleText.weight.ut)])
let titleAttrBlankSpace = NSAttributedString(string: " ", attributes: [.font: UIFont.systemFont(ofSize: theme.titleText.size + 0.35, weight: theme.titleText.weight.ut)])
let titleAttrBlankSpace = NSAttributedString(string: " ", attributes: [.font: UIFont.systemFont(ofSize: theme.titleText.size + 0.35, weight: theme.titleText.weight.ut)])
if data.over_18 ?? false {
titleAttr.append(titleAttrBlankSpace)
appendStr += "NSFW"
}
if let flair = data.link_flair_text, !flair.isEmpty {
if let flair = flairWithoutEmojis(str: data.link_flair_text)?.first, !flair.isEmpty {
titleAttr.append(titleAttrBlankSpace)
appendStr += flair
}
let append = NSMutableAttributedString(string: appendStr, attributes: [.font: UIFont.systemFont(ofSize: ((theme.titleText.size - 1) * 100) / 120, weight: theme.titleText.weight.ut)])
let append = NSMutableAttributedString(string: appendStr, attributes: [.font: UIFont.systemFont(ofSize: ((theme.titleText.size - 2) * 100) / 120, weight: .semibold)])
if !appendStr.isEmpty {
titleAttr.append(append)
titleAttr.append(titleAttrBlankSpace)
Expand Down
2 changes: 1 addition & 1 deletion winston/components/Media/MediaPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct OnlyURL: View {
.padding(.horizontal, 6)
.padding(.vertical, 2)
.frame(maxHeight: OnlyURL.height)
.background(Capsule(style: .continuous).fill(Color.accentColor.opacity(0.2)))
.background(Capsule(style: .continuous).fill(Color.accentColor.opacity(0.3)))
.fontSize(15, .medium)
.lineLimit(1)
.foregroundColor(.white)
Expand Down
5 changes: 3 additions & 2 deletions winston/components/SubredditPostsIOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct SubredditPostsIOS: View, Equatable {
@Binding var reachedEndOfFeed: Bool

@Default(.PostLinkDefSettings) private var postLinkDefSettings
@Default(.SubredditFeedDefSettings) private var feedDefSettings

@Environment(\.contentWidth) private var contentWidth

Expand Down Expand Up @@ -69,7 +70,7 @@ struct SubredditPostsIOS: View, Equatable {
Section {
ForEach(Array(posts.enumerated()), id: \.self.element.id) { i, post in
if let sub = subreddit ?? post.winstonData?.subreddit, let winstonData = post.winstonData {
PostLink(id: post.id, theme: selectedTheme.postLinks, showSub: showSub, contentWidth: contentWidth, defSettings: postLinkDefSettings)
PostLink(id: post.id, theme: selectedTheme.postLinks, showSub: showSub, compactPerSubreddit: feedDefSettings.compactPerSubreddit[sub.id], contentWidth: contentWidth, defSettings: postLinkDefSettings)
.environmentObject(sub)
.environmentObject(post)
.environmentObject(winstonData)
Expand Down Expand Up @@ -135,6 +136,6 @@ struct SubredditPostsIOS: View, Equatable {
.listStyle(.plain)
.listRowSeparator(.hidden)
.listSectionSeparator(.hidden)
.floatingMenu(filters: filters, selected: filter, filterCallback: filterCallback, searchText: searchText, searchCallback: searchCallback)
.floatingMenu(subId: subreddit?._id ?? "", filters: filters, selected: filter, filterCallback: filterCallback, searchText: searchText, searchCallback: searchCallback, customFilterCallback: editCustomFilter)
}
}
5 changes: 3 additions & 2 deletions winston/components/SubredditPostsIPAD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct SubredditPostsIPAD: View, Equatable {
@Environment(\.contentWidth) var contentWidth

@Default(.PostLinkDefSettings) private var postLinkDefSettings
@Default(.SubredditFeedDefSettings) private var feedDefSettings

func loadMorePosts() {
if !searchText.isEmpty {
Expand Down Expand Up @@ -84,7 +85,7 @@ struct SubredditPostsIPAD: View, Equatable {
contentForData: { post, i in
Group {
if let sub = subreddit ?? post.winstonData?.subreddit, let winstonData = post.winstonData {
PostLink(id: post.id, theme: selectedTheme.postLinks, showSub: showSub, contentWidth: contentWidth, defSettings: postLinkDefSettings)
PostLink(id: post.id, theme: selectedTheme.postLinks, showSub: showSub, compactPerSubreddit: feedDefSettings.compactPerSubreddit[sub.id], contentWidth: contentWidth, defSettings: postLinkDefSettings)
// .swipyRev(size: winstonData.postDimensions.size, actionsSet: postLinkDefSettings.swipeActions, entity: post)
.environmentObject(post)
.environmentObject(sub)
Expand Down Expand Up @@ -130,7 +131,7 @@ struct SubredditPostsIPAD: View, Equatable {
.id(UUID())
}
}
.floatingMenu(filters: filters, selected: filter, filterCallback: filterCallback, searchText: searchText, searchCallback: searchCallback)
.floatingMenu(subId: subreddit?.id ?? "", filters: filters, selected: filter, filterCallback: filterCallback, searchText: searchText, searchCallback: searchCallback, customFilterCallback: editCustomFilter)
.navigationBarTitleDisplayMode(.inline)
}
}
8 changes: 6 additions & 2 deletions winston/extensions/Transitions/blurTransitions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,12 @@ extension AnyTransition {
identity: BlurAndSlideH(isActive: true, left: false)
)
}
static var scaleAndBlur: AnyTransition { AnyTransition(.blurReplace) }

static var scaleAndBlur: AnyTransition {
.modifier(
active: ScaleAndBlurEffect(isActive: false),
identity: ScaleAndBlurEffect(isActive: true)
)
}
static var fadeBlur: AnyTransition {
.modifier(
active: BlurAndFadeEffect(isActive: false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ struct SubredditFeedDefSettings: Equatable, Hashable, Codable, Defaults.Serializ
var compactPerSubreddit: Dictionary<String, Bool> = .init()
var chunkLoadSize: Int = 25
var perSubredditSort: Bool = false
var openOptionsOnTap: Bool = false
var subredditSorts: Dictionary<String, SubListingSortOption> = .init()
}
2 changes: 1 addition & 1 deletion winston/models/RedditAPI/subs/fetchSubPosts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ extension RedditAPI {
subID += "&restrict_sr=on"

// Add preferred sort to search url
subID += "&sort=\(Defaults[.SubredditFeedDefSettings].preferredSort)"
subID += "&sort=\(Defaults[.SubredditFeedDefSettings].preferredSearchSort)"
}

if let after = after {
Expand Down
Loading