Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

feat(ios): pull down in a chat to reconnect to the computer

leepokaie3abbad653ae
diff --git a/apps/ios/Kit/Sources/CodyncUI/Thread/ConversationCollectionView.swift b/apps/ios/Kit/Sources/CodyncUI/Thread/ConversationCollectionView.swift
index d6e1a7d6..f6d6da02 100644
--- a/apps/ios/Kit/Sources/CodyncUI/Thread/ConversationCollectionView.swift
+++ b/apps/ios/Kit/Sources/CodyncUI/Thread/ConversationCollectionView.swift
@@ -33,6 +33,9 @@ class ConversationCollectionView: UICollectionView {
func followingAfterScroll(from previousOffset: CGFloat) -> Bool {
// Returning from overscroll moves upward too, but is not reading older messages.
if endOffset - contentOffset.y < Self.nearEnd { return true }
+ // Neither is pulling down past the top to refresh. Flipping here re-renders the list
+ // mid-pull, and every snapshot applied during a drag snaps the pull back.
+ if contentOffset.y < -adjustedContentInset.top { return following }
if contentOffset.y < previousOffset - 0.5 { return false }
return following
}
diff --git a/apps/ios/Kit/Sources/CodyncUI/Thread/ConversationList.swift b/apps/ios/Kit/Sources/CodyncUI/Thread/ConversationList.swift
index 21d8c594..35fc238a 100644
--- a/apps/ios/Kit/Sources/CodyncUI/Thread/ConversationList.swift
+++ b/apps/ios/Kit/Sources/CodyncUI/Thread/ConversationList.swift
@@ -27,6 +27,9 @@ struct ConversationList: View {
@Binding var following: Bool
/// The reader scrolled up near the top: time to bring in earlier messages.
var nearTop: (() -> Void)?
+ /// Letting go of a full pull past the top: the force refresh, its indicator held until it returns.
+ var refresh: (() async -> Void)?
+ @State private var pull = PullToRefresh()
/// The safe area (under the bars, above the composer and the keyboard) and the whole screen.
@State private var safeFrame = CGRect.zero
@State private var fullFrame = CGRect.zero
@@ -39,11 +42,14 @@ struct ConversationList: View {
.ignoresSafeArea()
// The list itself stays inside the safe area (so its rows never see one) and
// reaches out past it.
- ConversationCollection(rows: rows, following: $following, nearTop: nearTop,
+ ConversationCollection(rows: rows, following: $following, nearTop: nearTop, refresh: refresh, pull: pull,
outsets: UIEdgeInsets(top: max(0, safeFrame.minY - fullFrame.minY), left: 0,
bottom: max(0, fullFrame.maxY - safeFrame.maxY), right: 0))
.onGeometryChange(for: CGRect.self) { $0.frame(in: .global) } action: { safeFrame = $0 }
}
+ .overlay(alignment: .top) {
+ if refresh != nil { PullIndicator(pull: pull).padding(.top, 8) }
+ }
.overlay(alignment: .bottom) {
JumpToLatest(visible: !following && !rows.isEmpty) { following = true }
}
@@ -54,6 +60,8 @@ private struct ConversationCollection: UIViewRepresentable {
let rows: [ConversationRow]
@Binding var following: Bool
let nearTop: (() -> Void)?
+ let refresh: (() async -> Void)?
+ let pull: PullToRefresh
/// How far past its frame the list reaches: under the bars, the composer and the keyboard.
let outsets: UIEdgeInsets
@@ -215,6 +223,7 @@ private struct ConversationCollection: UIViewRepresentable {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let y = scrollView.contentOffset.y
defer { lastOffset = y }
+ trackPull(scrollView)
// Only the reader's own scrolling changes following; layout never does.
guard scrollView.isTracking || scrollView.isDecelerating else { return }
setFollowing(view.followingAfterScroll(from: lastOffset))
@@ -223,8 +232,31 @@ private struct ConversationCollection: UIViewRepresentable {
}
}
+ func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint,
+ targetContentOffset: UnsafeMutablePointer<CGPoint>) {
+ guard let parent, let refresh = parent.refresh, parent.pull.progress >= 1, !parent.pull.refreshing,
+ let container = view.superview as? ConversationContainer else { return }
+ // The chat eases back to just below the indicator and stays there while it turns. UIKit's
+ // own bounce would fight the new inset (and snapshots applied meanwhile clamp it), so it's
+ // stopped and the chat is moved here instead.
+ targetContentOffset.pointee = scrollView.contentOffset
+ parent.pull.refreshing = true
+ container.hold = PullToRefresh.hold
+ container.layoutIfNeeded()
+ DispatchQueue.main.async { [self] in
+ view.setContentOffset(view.contentOffset, animated: false)
+ animate(PullToRefresh.settle) { [view] in
+ guard let view else { return }
+ view.contentOffset.y = -view.adjustedContentInset.top
+ }
+ settle()
+ }
+ Task { await finishRefresh(refresh, pull: parent.pull, container: container) }
+ }
+
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
- if !decelerate { settle() }
+ // Past the top isn't a resting place: the bounce (or a refresh) settles it.
+ if !decelerate, scrollView.contentOffset.y >= -scrollView.adjustedContentInset.top { settle() }
}
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
@@ -245,6 +277,34 @@ private struct ConversationCollection: UIViewRepresentable {
if view.following { view.pinToEnd() }
}
+ /// Long enough to read as a refresh even when the link comes back at once; then the chat
+ /// eases back up instead of jumping.
+ private func finishRefresh(_ refresh: () async -> Void, pull: PullToRefresh, container: ConversationContainer) async {
+ let start = ContinuousClock.now
+ await refresh()
+ try? await Task.sleep(until: start + .milliseconds(600))
+ pull.refreshing = false
+ pull.progress = 0
+ animate(PullToRefresh.settle) { [view] in
+ container.hold = 0
+ container.layoutIfNeeded()
+ guard let view else { return }
+ let top = -view.adjustedContentInset.top
+ if view.contentOffset.y < top { view.contentOffset.y = top }
+ }
+ settle()
+ }
+
+ /// The ring follows the pull past the top; a tap of feedback says letting go will refresh.
+ private func trackPull(_ scrollView: UIScrollView) {
+ guard let pull = parent?.pull, parent?.refresh != nil, !pull.refreshing else { return }
+ let distance = -(scrollView.contentOffset.y + scrollView.adjustedContentInset.top)
+ let progress = min(max(distance / PullToRefresh.distance, 0), 1)
+ guard progress != pull.progress else { return }
+ if progress == 1, scrollView.isTracking { UIImpactFeedbackGenerator(style: .light).impactOccurred() }
+ pull.progress = progress
+ }
+
/// The reader stopped scrolling: resting at the end follows again; anywhere else stays put.
private func settle() {
setFollowing(view.endOffset - view.contentOffset.y < ConversationCollectionView.nearEnd)
@@ -285,6 +345,10 @@ private final class ConversationContainer: UIView {
var outsets = UIEdgeInsets.zero {
didSet { if outsets != oldValue { setNeedsLayout() } }
}
+ /// Extra room above the rows while a pull refreshes.
+ var hold: CGFloat = 0 {
+ didSet { if hold != oldValue { setNeedsLayout() } }
+ }
init(list: ConversationCollectionView) {
self.list = list
@@ -298,8 +362,9 @@ private final class ConversationContainer: UIView {
override func layoutSubviews() {
super.layoutSubviews()
list.frame = bounds.inset(by: UIEdgeInsets(top: -outsets.top, left: 0, bottom: -outsets.bottom, right: 0))
- if list.contentInset != outsets {
- list.contentInset = outsets
+ let insets = UIEdgeInsets(top: outsets.top + hold, left: 0, bottom: outsets.bottom, right: 0)
+ if list.contentInset != insets {
+ list.contentInset = insets
list.verticalScrollIndicatorInsets = outsets
if list.following { list.pinToEnd() }
}
diff --git a/apps/ios/Kit/Sources/CodyncUI/Thread/PullToRefresh.swift b/apps/ios/Kit/Sources/CodyncUI/Thread/PullToRefresh.swift
new file mode 100644
index 00000000..d6a1b794
--- /dev/null
+++ b/apps/ios/Kit/Sources/CodyncUI/Thread/PullToRefresh.swift
@@ -0,0 +1,54 @@
+import CodyncKit
+import SwiftUI
+
+/// A pull past the top of a chat: the arrow sweeps in with the pull and the refresh starts only
+/// when the reader lets go of a full circle, so a long pull never refreshes (or snaps back) under the
+/// finger. Only the indicator reads it, so a pull never re-renders the list.
+@MainActor @Observable final class PullToRefresh {
+ /// How far past the top a pull completes the circle.
+ static let distance: CGFloat = 110
+ /// Room kept open above the chat while it refreshes, for the indicator.
+ static let hold: CGFloat = 52
+ /// The chat easing back up once the refresh is done.
+ static let settle = Animation.spring(duration: 0.5, bounce: 0)
+ var progress: CGFloat = 0
+ var refreshing = false
+}
+
+struct PullIndicator: View {
+ let pull: PullToRefresh
+ @State private var turning = false
+ @Environment(\.accessibilityReduceMotion) private var reduceMotion
+
+ var body: some View {
+ // The system's arrow, swept in from its tail as the pull grows.
+ Image(systemName: "arrow.clockwise")
+ .font(.system(size: 17, weight: .medium))
+ .foregroundStyle(Palette.secondary)
+ .mask { Sweep(progress: pull.refreshing ? 1 : pull.progress) }
+ .rotationEffect(.degrees(turning ? 360 : 0))
+ .animation(turning && !reduceMotion ? .linear(duration: 0.8).repeatForever(autoreverses: false) : nil,
+ value: turning)
+ .padding(8)
+ .opacity(pull.refreshing ? 1 : min(1, pull.progress * 2))
+ .onChange(of: pull.refreshing) { _, refreshing in turning = refreshing }
+ .accessibilityHidden(!pull.refreshing)
+ .accessibilityLabel("Refreshing")
+ .allowsHitTesting(false)
+ }
+}
+
+/// A clockwise wedge from the arrow's tail (just above 3 o'clock), `progress` of the way round.
+private struct Sweep: Shape {
+ var progress: CGFloat
+
+ func path(in rect: CGRect) -> Path {
+ let center = CGPoint(x: rect.midX, y: rect.midY)
+ var path = Path()
+ path.move(to: center)
+ path.addArc(center: center, radius: hypot(rect.width, rect.height), startAngle: .degrees(-15),
+ endAngle: .degrees(-15 + 360 * progress), clockwise: false)
+ path.closeSubpath()
+ return path
+ }
+}
diff --git a/apps/ios/Kit/Sources/CodyncUI/Thread/ThreadView.swift b/apps/ios/Kit/Sources/CodyncUI/Thread/ThreadView.swift
index bafd0fbf..6220c433 100644
--- a/apps/ios/Kit/Sources/CodyncUI/Thread/ThreadView.swift
+++ b/apps/ios/Kit/Sources/CodyncUI/Thread/ThreadView.swift
@@ -379,7 +379,11 @@ extension ThreadView {
.padding(.top, 6)
})
}
- return ConversationList(rows: rows, following: $following) { showEarlier() }
+ // Pull to refresh reconnects, like Reconnect in the computer menu, until the link is back.
+ return ConversationList(rows: rows, following: $following, nearTop: { showEarlier() }, refresh: {
+ model.restartStream()
+ _ = try? await model.ready()
+ })
}
private var moreOnComputer: Bool {
diff --git a/apps/ios/Kit/Tests/CodyncUITests/ConversationScrollTests.swift b/apps/ios/Kit/Tests/CodyncUITests/ConversationScrollTests.swift
index 6471ca6b..fc5ed432 100644
--- a/apps/ios/Kit/Tests/CodyncUITests/ConversationScrollTests.swift
+++ b/apps/ios/Kit/Tests/CodyncUITests/ConversationScrollTests.swift
@@ -98,6 +98,8 @@ func bottomPinningPreservesNativeOverscrollDuringInteraction(_ phase: String) {
let view = ConversationCollectionView(frame: CGRect(x: 0, y: 0, width: 320, height: 600),
collectionViewLayout: TallConversationLayout())
view.layoutIfNeeded()
+ // Outside a window the layout's size never arrives; without it this chat would be short.
+ view.contentSize = TallConversationLayout().collectionViewContentSize
let end = view.endOffset
var previous = end
for offset in [end + 80, end + 40, end + 10, end] {
@@ -115,6 +117,19 @@ func bottomPinningPreservesNativeOverscrollDuringInteraction(_ phase: String) {
#expect(view.followingAfterScroll(from: end - 80))
}
+@MainActor @Test func pullingDownPastTheTopKeepsFollowing() {
+ let view = ConversationCollectionView(frame: CGRect(x: 0, y: 0, width: 320, height: 600),
+ collectionViewLayout: ShortConversationLayout())
+ view.layoutIfNeeded()
+ var previous = view.endOffset
+ for offset in [-40.0, -100, -160] {
+ view.contentOffset.y = offset
+ view.following = view.followingAfterScroll(from: previous)
+ #expect(view.following)
+ previous = offset
+ }
+}
+
@MainActor private final class InteractingConversationView: ConversationCollectionView {
var phase: String?
override var isTracking: Bool { phase == "tracking" }
@@ -126,3 +141,8 @@ func bottomPinningPreservesNativeOverscrollDuringInteraction(_ phase: String) {
override var collectionViewContentSize: CGSize { CGSize(width: 320, height: 5_000) }
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { [] }
}
+
+@MainActor private final class ShortConversationLayout: UICollectionViewLayout {
+ override var collectionViewContentSize: CGSize { CGSize(width: 320, height: 200) }
+ override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { [] }
+}
diff --git a/docs/features/chat-messages.md b/docs/features/chat-messages.md
index f919beab..4eaa66ac 100644
--- a/docs/features/chat-messages.md
+++ b/docs/features/chat-messages.md
@@ -42,4 +42,9 @@ Full conversation sheet.
`ConversationList.swift`; desktop: `.row-in` in `thread.css`; reduced motion: a 0.12 s fade).
- The list stays pinned to the bottom while the reader is there; scrolling up releases it and the
round "Jump to latest" button brings it back. Sending always returns to the bottom.
+- iPhone: earlier messages load when the top of the chat comes into view, so a short chat never
+ shows a lasting spinner. Pulling down past the top sweeps in the `arrow.clockwise` symbol; letting
+ go of a full sweep (`PullToRefresh.swift`) reconnects to the computer while the chat waits just
+ below the turning arrow, then eases back. A pull that isn't full refreshes nothing. The desktop
+ reconnects from the computer menu instead.
- The terminal UI lists the same messages; its steps line goes under the turn's last message.