Something went wrong. Try again.
A slopfork of Sam Henri Gold's Twitter client, reskinned like Tweetie 2 / Twitter for iPhone circa 2012. Personal use.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106import ComposableArchitectureimport Modelsimport SwiftUIimport TwitterUI
package struct FeedView<Header: View>: View { let store: StoreOf<FeedFeature> let header: Header
package init(store: StoreOf<FeedFeature>, @ContentBuilder header: () -> Header) { self.store = store self.header = header() }
/// Bound by item, so posts arriving above never move what's on screen. @State private var position = ScrollPosition(idType: FeedItem.ID.self)
package var body: some View { ScrollView { LazyVStack(spacing: 0) { header
if case .userMedia = store.source { FeedMediaGrid(store: store) } else { FeedRows(store: store) }
FeedFooter(store: store) } .scrollTargetLayout() .readableContentWidth() .background { ClassicRefreshControlStyle() } } .scrollPosition($position, anchor: .top) .onScrollGeometryChange(for: Bool.self) { geometry in geometry.contentOffset.y <= -geometry.contentInsets.top + 8 } action: { _, isAtTop in store.send(.isAtTopChanged(isAtTop)) } .onScrollPhaseChange { oldPhase, phase in if store.marksViewed, oldPhase.isScrolling != phase.isScrolling { store.send(.scrollPhaseChanged(isScrolling: phase.isScrolling)) } guard phase == .idle, let id = position.viewID(type: FeedItem.ID.self) else { return } store.send(.scrollStopped(topItemID: id)) } // Notifications are only seen while they're on screen. .onAppear { if store.marksViewed { store.send(.visibilityChanged(isOnScreen: true)) } } .onDisappear { if store.marksViewed { store.send(.visibilityChanged(isOnScreen: false)) } } .onChange(of: store.scrollToTopRequests) { // Like the status bar's scroll to top: straight there, no bounce. withAnimation(.smooth) { position.scrollTo(edge: .top) } } .onChange(of: store.restoringTopItemID, initial: true) { guard let topItemID = store.restoringTopItemID else { return } position.scrollTo(id: topItemID, anchor: .top) store.send(.topItemRestored) } // Just under the column's bar (the overlay keeps to the safe area the bar insets), pointing up at where the // new posts are. .overlay(alignment: .top) { ZStack { if store.newPostCount > 0 { NewPostsButton(count: store.newPostCount) { // Like the status bar's scroll to top: straight there, no bounce. withAnimation(.smooth) { position.scrollTo(edge: .top) } store.send(.newPostsButtonTapped) } .padding(.top, 8) .transition(.move(edge: .top).combined(with: .opacity)) } } .animation(.snappy, value: store.newPostCount > 0) } .feedInteractions(store: store) }}
/// Newer posts waiting above where the reader is: said quietly, never by moving them.private struct NewPostsButton: View { let count: Int let action: () -> Void
var body: some View { Button(action: action) { Label(count == 1 ? "1 new Tweet" : "\(count) new Tweets", twitterIcon: .arrowUp) .font(.subheadline.weight(.semibold)) .padding(.horizontal, 6) } .buttonStyle(.classicProminent) .sensoryFeedback(.increase, trigger: count) }}
extension FeedView where Header == EmptyView { package init(store: StoreOf<FeedFeature>) { self.store = store header = EmptyView() }}