... to shared container instead of migrating This commit is a reimplementation of DamusUserDefaults that mirrors settings from the app to the shared container (instead of migrating values over). This new implementation brings the benefit of being backwards compatible with the user's settings. That is, even if the user upgrades or downgrades between various versions and changes settings along the way, the main settings in the app will stay consistent between Damus versions — that is, changes to the settings would not be lost between downgrades/upgrades General settings test ---------------------- PASS Device: iPhone 15 Pro simulator iOS: 17.0.1 Damus: This commit Setup: A device with non-standard settings Steps: 1. Flash Damus on the device 2. Check any non-default settings that were there before. Ensure that settings remained the same. PASS 3. Change one setting (any setting) to a non-default value 4. Restart Damus 5. Ensure settings change in step 3 persisted on the device Notification settings test -------------------------- PASS Device: iPhone 15 Pro simulator iOS: 17.0.1 Damus: This commit Setup: - Two phones running Damus on different accounts - Local relay with strfry-push-notify test setup - Apple push notification test tool Coverage: 1. Mention notifications 2. DM notifications 3. Reaction notifications 4. Repost notifications Steps for each notification type: 1. Use the secondary phone to generate a push notification 2. Trigger the push notification (Send push notification from test tool) 3. Ensure that the notification is received on the other device 4. Turn off notifications for that notification type on settings 5. Trigger the same push notification (Resend push notification from test tool) 6. Ensure that the notification is not received on the other device 7. Turn on notifications for that notification type on settings 8. Trigger the same push notification (Resend from test tool) 9. Ensure that notification appears on the device Result: PASS (notifications are received when enabled and not received when disabled) Signed-off-by: Daniel D’Aquino <daniel@daquino.me> Signed-off-by: William Casarin <jb55@jb55.com>
89 lines
2.6 KiB
Swift
89 lines
2.6 KiB
Swift
//
|
|
// TimelineView.swift
|
|
// damus
|
|
//
|
|
// Created by William Casarin on 2022-04-18.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct TimelineView<Content: View>: View {
|
|
@ObservedObject var events: EventHolder
|
|
@Binding var loading: Bool
|
|
|
|
let damus: DamusState
|
|
let show_friend_icon: Bool
|
|
let filter: (NostrEvent) -> Bool
|
|
let content: Content?
|
|
|
|
init(events: EventHolder, loading: Binding<Bool>, damus: DamusState, show_friend_icon: Bool, filter: @escaping (NostrEvent) -> Bool, content: (() -> Content)? = nil) {
|
|
self.events = events
|
|
self._loading = loading
|
|
self.damus = damus
|
|
self.show_friend_icon = show_friend_icon
|
|
self.filter = filter
|
|
self.content = content?()
|
|
}
|
|
|
|
var body: some View {
|
|
MainContent
|
|
}
|
|
|
|
var MainContent: some View {
|
|
ScrollViewReader { scroller in
|
|
ScrollView {
|
|
if let content {
|
|
content
|
|
}
|
|
|
|
Color.white.opacity(0)
|
|
.id("startblock")
|
|
.frame(height: 1)
|
|
|
|
InnerTimelineView(events: events, damus: damus, filter: loading ? { _ in true } : filter)
|
|
.redacted(reason: loading ? .placeholder : [])
|
|
.shimmer(loading)
|
|
.disabled(loading)
|
|
.background(GeometryReader { proxy -> Color in
|
|
handle_scroll_queue(proxy, queue: self.events)
|
|
return Color.clear
|
|
})
|
|
}
|
|
.buttonStyle(BorderlessButtonStyle())
|
|
.coordinateSpace(name: "scroll")
|
|
.onReceive(handle_notify(.scroll_to_top)) { () in
|
|
events.flush()
|
|
self.events.should_queue = false
|
|
scroll_to_event(scroller: scroller, id: "startblock", delay: 0.0, animate: true, anchor: .top)
|
|
}
|
|
}
|
|
.onAppear {
|
|
events.flush()
|
|
}
|
|
}
|
|
}
|
|
|
|
struct TimelineView_Previews: PreviewProvider {
|
|
@StateObject static var events = test_event_holder
|
|
static var previews: some View {
|
|
TimelineView<AnyView>(events: events, loading: .constant(true), damus: test_damus_state, show_friend_icon: true, filter: { _ in true })
|
|
}
|
|
}
|
|
|
|
|
|
protocol ScrollQueue {
|
|
var should_queue: Bool { get }
|
|
func set_should_queue(_ val: Bool)
|
|
}
|
|
|
|
func handle_scroll_queue(_ proxy: GeometryProxy, queue: ScrollQueue) {
|
|
let offset = -proxy.frame(in: .named("scroll")).origin.y
|
|
guard offset >= 0 else {
|
|
return
|
|
}
|
|
let val = offset > 0
|
|
if queue.should_queue != val {
|
|
queue.set_should_queue(val)
|
|
}
|
|
}
|