Skip to content

Commit

Permalink
Merge branch 'dev' into sjmarf/fix-ipad-links
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjmarf authored Nov 1, 2024
2 parents f3f7f4d + d72c745 commit 2bafe7f
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 10 deletions.
3 changes: 3 additions & 0 deletions Mlem/App/Configuration/User Settings/CodableSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ struct CodableSettings: Codable {
var subscriptions_instanceLocation: InstanceLocation
var subscriptions_sort: SubscriptionListSort
var navigation_sidebarVisibleByDefault: Bool
var navigation_swipeAnywhere: Bool

// swiftlint:disable line_length function_body_length
init(from decoder: any Decoder) throws {
Expand Down Expand Up @@ -153,6 +154,7 @@ struct CodableSettings: Codable {
self.subscriptions_instanceLocation = try container.decodeIfPresent(InstanceLocation.self, forKey: .subscriptions_instanceLocation) ?? (UIDevice.isPad ? .bottom : .trailing)
self.subscriptions_sort = try container.decodeIfPresent(SubscriptionListSort.self, forKey: .subscriptions_sort) ?? .alphabetical
self.navigation_sidebarVisibleByDefault = try container.decodeIfPresent(Bool.self, forKey: .navigation_sidebarVisibleByDefault) ?? true
self.navigation_swipeAnywhere = try container.decodeIfPresent(Bool.self, forKey: .navigation_swipeAnywhere) ?? false
}

// swiftlint:enable line_length
Expand Down Expand Up @@ -227,6 +229,7 @@ struct CodableSettings: Codable {
self.subscriptions_instanceLocation = settings.subscriptionInstanceLocation
self.subscriptions_sort = settings.subscriptionSort
self.navigation_sidebarVisibleByDefault = settings.sidebarVisibleByDefault
self.navigation_swipeAnywhere = settings.swipeAnywhereToNavigate
}
// swiftlint:enable function_body_length
}
2 changes: 2 additions & 0 deletions Mlem/App/Configuration/User Settings/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class Settings: ObservableObject {
@AppStorage("tip.feedWelcomePrompt") var showFeedWelcomePrompt: Bool = true

@AppStorage("navigation.sidebarVisibleByDefault") var sidebarVisibleByDefault: Bool = true
@AppStorage("navigation.swipeAnywhere") var swipeAnywhereToNavigate: Bool = false

@AppStorage("menus.moderatorActionGrouping") var moderatorActionGrouping: ModeratorActionGrouping = .divider

Expand Down Expand Up @@ -138,5 +139,6 @@ class Settings: ObservableObject {
bypassImageProxyShown = settings.status_bypassImageProxyShown
autoBypassImageProxy = settings.privacy_autoBypassImageProxy
sidebarVisibleByDefault = settings.navigation_sidebarVisibleByDefault
swipeAnywhereToNavigate = settings.navigation_swipeAnywhere
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,18 @@ struct QuickSwipeView: ViewModifier {
}
}
}
.clipShape(RoundedRectangle(cornerRadius: config.behavior.cornerRadius)) // clip slidable card
.clipShape(.rect(cornerRadius: config.behavior.cornerRadius)) // clip slidable card
.background(shadowBackground)
.geometryGroup()
.offset(x: dragPosition) // using dragPosition so we can apply withAnimation() to it
.background(iconBackground)
// disables links from highlighting when tapped
.buttonStyle(.empty)
.clipShape(RoundedRectangle(cornerRadius: config.behavior.cornerRadius)) // clip entire view
.clipShape(.rect(cornerRadius: config.behavior.cornerRadius)) // clip entire view
.popupAnchor(model: popupModel)
} else {
content
.clipShape(.rect(cornerRadius: config.behavior.cornerRadius)) // clip entire view
}
}

Expand Down
11 changes: 5 additions & 6 deletions Mlem/App/Views/Pages/Person/PersonView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ struct PersonView: View {
@ViewBuilder
func content(person: any Person) -> some View {
FancyScrollView {
VStack(spacing: Constants.main.standardSpacing) {
VStack(spacing: 0) {
VStack(spacing: Constants.main.standardSpacing) {
ProfileHeaderView(person, fallback: .person)
bio(person: person)
Expand All @@ -133,7 +133,6 @@ struct PersonView: View {
.transition(.opacity)
} else {
VStack(spacing: 0) {
Divider()
ProgressView()
.padding(.top)
}
Expand All @@ -149,34 +148,34 @@ struct PersonView: View {
@ViewBuilder
func bio(person: any Person) -> some View {
if let bio = person.description_ {
Divider()
VStack(spacing: Constants.main.standardSpacing) {
let blocks: [BlockNode] = .init(bio)
if blocks.isSimpleParagraphs, bio.count < 300 {
MarkdownText(blocks, configuration: .default)
.multilineTextAlignment(.center)
.padding(.horizontal, Constants.main.standardSpacing)
dateLabel(person: person)
.frame(maxWidth: .infinity, alignment: .center)
} else {
Markdown(blocks, configuration: .default)
.padding(.horizontal, Constants.main.standardSpacing)
dateLabel(person: person)
.frame(maxWidth: .infinity, alignment: .leading)
}
}
.padding(Constants.main.standardSpacing)
.background(palette.secondaryGroupedBackground, in: .rect(cornerRadius: Constants.main.standardSpacing))
.paletteBorder(cornerRadius: Constants.main.standardSpacing)
.padding(.top, Constants.main.halfSpacing)
} else {
dateLabel(person: person)
.frame(maxWidth: .infinity, alignment: .center)
.padding(.bottom, Constants.main.halfSpacing)
}
}

@ViewBuilder
func dateLabel(person: any Person) -> some View {
ProfileDateView(profilable: person)
.padding(.horizontal, Constants.main.standardSpacing)
.padding(.vertical, 2)
}

@ViewBuilder
Expand Down
33 changes: 31 additions & 2 deletions Mlem/App/Views/Root/Tabs/Settings/GeneralSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ struct GeneralSettingsView: View {

// behavior
@Setting(\.upvoteOnSave) var upvoteOnSave
@Setting(\.quickSwipesEnabled) var swipeActionsEnabled
@Setting(\.jumpButton) var jumpButton
@Setting(\.markReadOnScroll) var markReadOnScroll
@Setting(\.autoplayMedia) var autoplayMedia
Expand All @@ -28,6 +27,10 @@ struct GeneralSettingsView: View {
@Setting(\.hapticLevel) var hapticLevel
@Setting(\.wrapCodeBlockLines) var wrapCodeBlockLines

// Gestures
@Setting(\.quickSwipesEnabled) var swipeActionsEnabled
@Setting(\.swipeAnywhereToNavigate) var swipeAnywhereToNavigate

var body: some View {
Form {
Section {
Expand Down Expand Up @@ -63,7 +66,6 @@ struct GeneralSettingsView: View {
}
Toggle("Mark Read on Scroll", isOn: $markReadOnScroll)
Toggle("Upvote on Save", isOn: $upvoteOnSave)
Toggle("Swipe Actions", isOn: $swipeActionsEnabled)
Picker("Jump Button", selection: $jumpButton) {
ForEach(CommentJumpButtonLocation.allCases, id: \.self) { item in
Text(item.label)
Expand All @@ -80,6 +82,33 @@ struct GeneralSettingsView: View {
Text("Behavior")
}

Section("Gestures") {
Toggle(
"Swipe Actions",
isOn: .init(
get: { swipeActionsEnabled },
set: {
swipeActionsEnabled = $0
if $0 {
swipeAnywhereToNavigate = false
}
}
)
)
Toggle(
"Swipe Anywhere to Navigate",
isOn: .init(
get: { swipeAnywhereToNavigate },
set: {
swipeAnywhereToNavigate = $0
if $0 {
swipeActionsEnabled = false
}
}
)
)
}

NavigationLink("Import/Export Settings", destination: .settings(.importExportSettings))
}
.navigationTitle("General")
Expand Down
31 changes: 31 additions & 0 deletions Mlem/App/Views/Shared/Navigation/NavigationLayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
//

import SwiftUI
import SwiftUIIntrospect
import UIKit

struct NavigationLayerView: View {
@Bindable var layer: NavigationLayer
let hasSheetModifiers: Bool

private let fullWidthGestureRecognizerDelegate: FullWidthGestureRecognizerDelegate = .init()

var body: some View {
Group {
if layer.hasNavigationStack {
Expand All @@ -22,6 +26,22 @@ struct NavigationLayerView: View {
.environment(\.isRootView, false)
}
}
.introspect(.navigationStack, on: .iOS(.v17, .v18)) { controller in
// This is for the "Swipe anywhere to navigate" setting
// https://stackoverflow.com/questions/20714595/extend-default-interactivepopgesturerecognizer-beyond-screen-edge
guard
let interactivePopGestureRecognizer = controller.interactivePopGestureRecognizer,
let targets = interactivePopGestureRecognizer.value(forKey: "targets")
else {
return
}

let fullWidthBackGestureRecognizer = UIPanGestureRecognizer()
fullWidthBackGestureRecognizer.setValue(targets, forKey: "targets")
fullWidthGestureRecognizerDelegate.navigationController = controller
fullWidthBackGestureRecognizer.delegate = fullWidthGestureRecognizerDelegate
controller.view.addGestureRecognizer(fullWidthBackGestureRecognizer)
}

} else {
rootView()
Expand Down Expand Up @@ -89,3 +109,14 @@ private struct SharingViewController: UIViewControllerRepresentable {
}
}
}

private class FullWidthGestureRecognizerDelegate: NSObject, UIGestureRecognizerDelegate {
var navigationController: UINavigationController?

func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
if !Settings.main.swipeAnywhereToNavigate { return false }
let isSystemSwipeToBackEnabled = navigationController?.interactivePopGestureRecognizer?.isEnabled == true
let isThereStackedViewControllers = (navigationController?.viewControllers.count ?? 0) > 1
return isSystemSwipeToBackEnabled && isThereStackedViewControllers
}
}
6 changes: 6 additions & 0 deletions Mlem/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,9 @@
},
"General" : {

},
"Gestures" : {

},
"GitHub Repository" : {

Expand Down Expand Up @@ -1328,6 +1331,9 @@
},
"Swipe Actions" : {

},
"Swipe Anywhere to Navigate" : {

},
"Switch Account" : {

Expand Down

0 comments on commit 2bafe7f

Please sign in to comment.