use nsnotification to open web reader when selected from audio session

This commit is contained in:
Satindar Dhillon 2022-08-31 06:56:18 -07:00
parent d075b03a57
commit 41a5603593
4 changed files with 26 additions and 10 deletions

View file

@ -16,7 +16,6 @@ public struct MiniPlayer: View {
@Environment(\.colorScheme) private var colorScheme: ColorScheme
private let presentingView: AnyView
@State private var webReaderItem: LinkedItem?
@State var expanded = false
@State var offset: CGFloat = 0
@Namespace private var animation
@ -92,7 +91,6 @@ public struct MiniPlayer: View {
Button(
action: {
withAnimation(.interactiveSpring()) {
self.webReaderItem = nil
self.expanded = false
}
},
@ -145,7 +143,8 @@ public struct MiniPlayer: View {
}
.onTapGesture {
if expanded {
webReaderItem = item
expanded = false
NSNotification.pushReaderItem(objectID: item.objectID)
}
}
@ -292,12 +291,6 @@ public struct MiniPlayer: View {
}
}
}
.sheet(item: $webReaderItem) {
LinkItemDetailView(
linkedItemObjectID: $0.objectID,
isPDF: $0.isPDF
)
}
}
func onDragChanged(value: DragGesture.Value) {
@ -310,7 +303,6 @@ public struct MiniPlayer: View {
withAnimation(.interactiveSpring()) {
if value.translation.height > minExpandedHeight {
expanded = false
webReaderItem = nil
}
offset = 0
}

View file

@ -1,3 +1,4 @@
import CoreData
import Models
import Services
import SwiftUI
@ -112,6 +113,11 @@ import Views
viewModel.pushFeedItem(item: linkedItem)
viewModel.selectedLinkItem = linkedItem.objectID
}
.onReceive(NSNotification.pushReaderItemPublisher) { notification in
if let objectID = notification.userInfo?["objectID"] as? NSManagedObjectID {
viewModel.handleReaderItemNotification(objectID: objectID)
}
}
.onOpenURL { url in
withoutAnimation {
viewModel.linkRequest = nil

View file

@ -33,6 +33,10 @@ import Views
from: Date(timeIntervalSinceReferenceDate: 0)
)
func handleReaderItemNotification(objectID: NSManagedObjectID) {
selectedLinkItem = objectID
}
var cursor: String?
// These are used to make sure we handle search result

View file

@ -1,8 +1,10 @@
import CoreData
import Foundation
import Models
public extension NSNotification {
static let PushJSONArticle = Notification.Name("PushJSONArticle")
static let PushReaderItem = Notification.Name("PushReaderItem")
static let OperationSuccess = Notification.Name("OperationSuccess")
static let OperationFailure = Notification.Name("OperationFailure")
static let ReaderSettingsChanged = Notification.Name("ReaderSettingsChanged")
@ -11,6 +13,10 @@ public extension NSNotification {
NotificationCenter.default.publisher(for: PushJSONArticle)
}
static var pushReaderItemPublisher: NotificationCenter.Publisher {
NotificationCenter.default.publisher(for: PushReaderItem)
}
static var operationSuccessPublisher: NotificationCenter.Publisher {
NotificationCenter.default.publisher(for: OperationSuccess)
}
@ -38,6 +44,14 @@ public extension NSNotification {
)
}
static func pushReaderItem(objectID: NSManagedObjectID) {
NotificationCenter.default.post(
name: NSNotification.PushReaderItem,
object: nil,
userInfo: ["objectID": objectID]
)
}
static func operationSuccess(message: String) {
NotificationCenter.default.post(name: NSNotification.OperationSuccess, object: nil, userInfo: ["message": message])
}