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.
Rust acpagent-client-protocolai-agentsai-assistantclaudeclaude-codecodexcoding-agentscursorgeminigemini-cligrok-bot-alternativeiosiphonelinuxmacosmcpopen-sourcerustself-hosted
feat(ios): smoother chat on a UIKit message list
leepokaieea16548efb2
diff --git a/apps/ios/Kit/Sources/CodyncUI/Thread/ConversationFollow.swift b/apps/ios/Kit/Sources/CodyncUI/Thread/ConversationFollow.swiftdeleted file mode 100644index b3abfde1..00000000--- a/apps/ios/Kit/Sources/CodyncUI/Thread/ConversationFollow.swift+++ /dev/null@@ -1,158 +0,0 @@-import CodyncKit-import SwiftUI--extension View {- /// Reports whether the top of the content is within half a screen.- @ViewBuilder func nearTop(_ changed: @escaping (Bool) -> Void) -> some View {- if #available(iOS 18, *) {- onScrollGeometryChange(for: Bool.self) { geometry in- geometry.contentOffset.y + geometry.contentInsets.top < geometry.containerSize.height / 2- } action: { _, near in- changed(near)- }- } else {- self- }- }-- /// A conversation's scrolling: opens at the newest message and follows it (`following`) as- /// messages arrive and replies grow. Scrolling away stops following, so the text being read- /// stays put; scrolling back to the end resumes it.- /// `keepingPlace`: earlier messages are going in above; the message with this id stays put.- @ViewBuilder func followsConversation(_ following: Binding<Bool>, keepingPlace: Binding<String?> = .constant(nil)) -> some View {- if #available(iOS 18, *) {- modifier(FollowConversation(following: following, keepingPlace: keepingPlace))- } else {- defaultScrollAnchor(.bottom)- }- }-}--/// Follows the newest message: pinned to the end until the reader scrolls up (their own input,-/// never layout), pinned again once they're back at the end. While the reader is scrolling,-/// nothing moves under them. Pinning always goes through the scroll view's own end-/// (`scrollTo(edge:)`), never a computed offset, and after the layout pass, not inside it.-@available(iOS 18, *)-private struct FollowConversation: ViewModifier {- @Binding var following: Bool- /// Earlier messages are going in above: keep this message where it is on screen.- @Binding var keepingPlace: String?- @State private var position = ScrollPosition(edge: .bottom)- @State private var phase = ScrollPhase.idle- /// Not observed: updated every scrolled frame, read by the handlers.- @State private var state = FollowState()- @Environment(\.accessibilityReduceMotion) private var reduceMotion-- private static let nearEnd: CGFloat = 32- private var readerScrolling: Bool {- phase == .interacting || phase == .decelerating || phase == .tracking- }-- private struct Place: Equatable {- var offset: CGFloat- var content: CGFloat- var viewport: CGFloat- var distanceToEnd: CGFloat- }-- func body(content: Content) -> some View {- content- .environment(\.conversationScrolling, readerScrolling)- .scrollPosition($position)- .defaultScrollAnchor(.bottom, for: .initialOffset)- .onScrollGeometryChange(for: Place.self) { geometry in- let end = geometry.contentSize.height + geometry.contentInsets.bottom - geometry.containerSize.height- return Place(offset: geometry.contentOffset.y, content: geometry.contentSize.height,- viewport: geometry.containerSize.height,- distanceToEnd: max(end, -geometry.contentInsets.top) - geometry.contentOffset.y)- } action: { old, raw in- // Geometry's offsets and insets don't always add up to the real end; where a pin- // to the end actually lands says how far off they are.- if state.pinned, !readerScrolling, raw.content == old.content {- state.correction = raw.distanceToEnd- }- state.pinned = false- var new = raw- new.distanceToEnd -= state.correction- state.distanceToEnd = new.distanceToEnd- if keepingPlace != nil, !following, new.content != old.content {- keepPlace()- } else if readerScrolling, new.offset < old.offset - 0.5 {- // The reader moved up: stop following.- following = false- } else if !following, new.offset > old.offset, new.distanceToEnd < Self.nearEnd {- following = true- } else if following, !readerScrolling, abs(new.distanceToEnd) > 0.5, !state.pinPending {- // Grown below the view, or shrunk out from under it. Pin after this layout- // pass, not inside it.- state.pinPending = true- DispatchQueue.main.async {- state.pinPending = false- if following, !readerScrolling { pin(nil) }- }- }- }- .onScrollPhaseChange { _, new in- let wasScrolling = readerScrolling- phase = new- if wasScrolling, !readerScrolling { settle() }- }- .onChange(of: following) { _, follow in- if follow { pin(Motion.conversation) }- }- }-- /// The reader stopped scrolling: resting at the end follows again; anywhere else stays put.- private func settle() {- let atEnd = state.distanceToEnd < Self.nearEnd- if atEnd, following { pin(nil) }- following = atEnd- }-- private func keepPlace() {- guard let id = keepingPlace else { return }- var transaction = Transaction()- transaction.disablesAnimations = true- withTransaction(transaction) { position.scrollTo(id: id, anchor: .top) }- }-- private func pin(_ animation: Animation?) {- state.pinned = animation == nil- var transaction = Transaction(animation: animation.flatMap { Motion.reduced($0, reduceMotion) })- transaction.disablesAnimations = animation == nil- withTransaction(transaction) { position.scrollTo(edge: .bottom) }- }-}--/// What the follower knows between frames, outside SwiftUI's change tracking.-@MainActor private final class FollowState {- var distanceToEnd: CGFloat = 0- /// How far the computed end sits from where pinning to the end really lands.- var correction: CGFloat = 0- /// An instant pin was just requested; the next geometry shows where it landed.- var pinned = false- var pinPending = false-}--/// Scrolled away from the newest messages: a round button back down to them.-struct JumpToLatest: View {- let visible: Bool- let action: () -> Void- @Environment(\.accessibilityReduceMotion) private var reduceMotion-- var body: some View {- ZStack {- if visible {- Button("Jump to latest", systemImage: "arrow.down", action: action)- .labelStyle(.iconOnly)- .buttonStyle(IconButtonStyle())- .frosted(in: Circle())- .shadow(color: .black.opacity(0.12), radius: 10, y: 3)- .help("Jump to latest")- .padding(.bottom, 10)- .transition(.scale(scale: 0.8).combined(with: .opacity))- }- }- .animation(Motion.reduced(Motion.layout, reduceMotion), value: visible)- }-}diff --git a/apps/ios/Kit/Sources/CodyncUI/Thread/ConversationList.swift b/apps/ios/Kit/Sources/CodyncUI/Thread/ConversationList.swiftnew file mode 100644index 00000000..44e54589--- /dev/null+++ b/apps/ios/Kit/Sources/CodyncUI/Thread/ConversationList.swift@@ -0,0 +1,360 @@+import CodyncKit+import SwiftUI+import UIKit++/// One row of a conversation: a message, a separator, the working indicator…+struct ConversationRow {+ let id: String+ /// The reader's own new message: the list goes back down to it.+ var isUserMessage = false+ let content: AnyView++ init(_ id: String, isUserMessage: Bool = false, @ViewBuilder content: () -> some View) {+ self.id = id+ self.isUserMessage = isUserMessage+ self.content = AnyView(content())+ }+}++/// A conversation's scrolling list, in UIKit (a collection view of hosted SwiftUI rows): only+/// the rows on screen exist, and a changed row re-renders alone. It opens at the newest+/// message and follows it (`following`) as messages arrive and replies grow. Scrolling away+/// stops following, so the text being read stays put (rows going in above keep it in place);+/// scrolling back to the end resumes it. Content runs under the bars and the composer+/// (what lies outside the safe area becomes the list's insets).+struct ConversationList: View {+ let rows: [ConversationRow]+ @Binding var following: Bool+ /// The reader scrolled up near the top: time to bring in earlier messages.+ var nearTop: (() -> Void)?+ /// 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++ var body: some View {+ ZStack {+ GeometryReader { _ in+ Color.clear.onGeometryChange(for: CGRect.self) { $0.frame(in: .global) } action: { fullFrame = $0 }+ }+ .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,+ 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: .bottom) {+ JumpToLatest(visible: !following && !rows.isEmpty) { following = true }+ }+ }+}++private struct ConversationCollection: UIViewRepresentable {+ let rows: [ConversationRow]+ @Binding var following: Bool+ let nearTop: (() -> Void)?+ /// How far past its frame the list reaches: under the bars, the composer and the keyboard.+ let outsets: UIEdgeInsets++ func makeCoordinator() -> Coordinator { Coordinator() }++ func makeUIView(context: Context) -> ConversationContainer {+ let view = ConversationContainer(list: context.coordinator.makeView())+ context.coordinator.update(self, context: context)+ return view+ }++ func updateUIView(_ view: ConversationContainer, context: Context) {+ context.coordinator.update(self, context: context)+ }++ @MainActor final class Coordinator: NSObject, UICollectionViewDelegate {+ private var view: ConversationCollectionView!+ private var dataSource: UICollectionViewDiffableDataSource<Int, String>!+ private var contents: [String: AnyView] = [:]+ private var environment = EnvironmentValues()+ private let scrolling = ScrollingFlag()+ private var parent: ConversationCollection?+ /// What the list is telling `following` (it reaches the binding after the update).+ private var pending: Bool?+ private var lastId: String?+ private var lastOffset: CGFloat = 0+ private var reduceMotion = false++ func makeView() -> ConversationCollectionView {+ let size = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .estimated(80))+ let group = NSCollectionLayoutGroup.vertical(layoutSize: size, subitems: [NSCollectionLayoutItem(layoutSize: size)])+ let section = NSCollectionLayoutSection(group: group)+ section.contentInsets = NSDirectionalEdgeInsets(top: 8, leading: 0, bottom: 8, trailing: 0)+ let view = ConversationCollectionView(frame: .zero, collectionViewLayout: UICollectionViewCompositionalLayout(section: section))+ view.backgroundColor = .clear+ view.contentInsetAdjustmentBehavior = .never+ view.showsVerticalScrollIndicator = false+ view.showsHorizontalScrollIndicator = false+ view.alwaysBounceVertical = true+ view.keyboardDismissMode = .interactive+ view.allowsSelection = false+ view.delegate = self+ if #available(iOS 26, *) { view.topEdgeEffect.style = .soft }+ // Tapping the conversation puts the keyboard away; the rows still get the tap.+ let tap = UITapGestureRecognizer(target: view, action: #selector(UIView.endEditing(_:)))+ tap.cancelsTouchesInView = false+ view.addGestureRecognizer(tap)++ let cell = UICollectionView.CellRegistration<UICollectionViewCell, String> { [weak self] cell, _, id in+ guard let self else { return }+ cell.backgroundConfiguration = .clear()+ cell.contentConfiguration = UIHostingConfiguration {+ ConversationCell(scrolling: scrolling, content: contents[id] ?? AnyView(EmptyView()))+ .environment(\.self, environment)+ // A reused cell starts fresh (no state carried over from another row).+ .id(id)+ }+ .margins(.all, 0)+ }+ dataSource = UICollectionViewDiffableDataSource(collectionView: view) { view, indexPath, id in+ view.dequeueConfiguredReusableCell(using: cell, for: indexPath, item: id)+ }+ self.view = view+ return view+ }++ func update(_ parent: ConversationCollection, context: Context) {+ self.parent = parent+ environment = context.environment+ reduceMotion = context.environment.accessibilityReduceMotion+ var seen = Set<String>()+ // A repeated id would crash the data source; the first one wins.+ let rows = parent.rows.filter { seen.insert($0.id).inserted }+ contents = Dictionary(rows.map { ($0.id, $0.content) }, uniquingKeysWith: { a, _ in a })++ if let container = view.superview as? ConversationContainer, container.outsets != parent.outsets {+ // The keyboard or the composer moved: the end moves with them.+ animate(context.transaction.animation) {+ container.outsets = parent.outsets+ container.layoutIfNeeded()+ }+ }++ // "Jump to latest", or the reader's own message just went out.+ let sent = rows.last.map { $0.id != lastId && $0.isUserMessage } ?? false+ var jump = false+ if let pending {+ if parent.following == pending { self.pending = nil }+ } else if parent.following != view.following {+ view.following = parent.following+ jump = parent.following+ }+ if sent { setFollowing(true) }++ let ids = rows.map(\.id)+ let old = dataSource.snapshot().itemIdentifiers+ var snapshot = NSDiffableDataSourceSnapshot<Int, String>()+ snapshot.appendSections([0])+ snapshot.appendItems(ids)+ // Rows that stay re-render with their new content (SwiftUI skips what didn't change).+ let kept = Set(old)+ snapshot.reconfigureItems(ids.filter(kept.contains))+ let first = lastId == nil+ lastId = rows.last?.id++ if old == ids || first {+ dataSource.apply(snapshot, animatingDifferences: false)+ } else if view.following, !reduceMotion {+ // New rows slide in as the list moves up to them, in one motion.+ UIView.animate(springDuration: 0.42, bounce: 0) {+ self.dataSource.apply(snapshot, animatingDifferences: true)+ self.view.layoutIfNeeded()+ self.view.pinToEnd()+ }+ } else {+ applyKeepingPlace(snapshot)+ }+ if jump || sent { view.scrollToEnd(animated: !reduceMotion) }+ }++ /// Rows going in or out above: the first row on screen stays where it is.+ private func applyKeepingPlace(_ snapshot: NSDiffableDataSourceSnapshot<Int, String>) {+ let anchor = view.indexPathsForVisibleItems.min().flatMap { path in+ dataSource.itemIdentifier(for: path).map { ($0, (view.layoutAttributesForItem(at: path)?.frame.minY ?? 0) - view.contentOffset.y) }+ }+ dataSource.apply(snapshot, animatingDifferences: false)+ guard !view.following, let (id, offset) = anchor, let path = dataSource.indexPath(for: id) else { return }+ view.layoutIfNeeded()+ if let frame = view.layoutAttributesForItem(at: path)?.frame {+ view.contentOffset.y = frame.minY - offset+ }+ }++ private func animate(_ animation: Animation?, _ changes: @escaping () -> Void) {+ if #available(iOS 18, *), animation != nil, !reduceMotion {+ UIView.animate(animation ?? .default, changes: changes)+ } else {+ changes()+ }+ }++ private func setFollowing(_ follow: Bool) {+ guard view.following != follow else { return }+ view.following = follow+ pending = follow+ // Not during SwiftUI's update of this view.+ DispatchQueue.main.async { [weak self] in self?.parent?.following = follow }+ }++ // MARK: scrolling++ func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {+ scrolling.active = true+ }++ func scrollViewDidScroll(_ scrollView: UIScrollView) {+ let y = scrollView.contentOffset.y+ defer { lastOffset = y }+ // Only the reader's own scrolling changes following; layout never does.+ guard scrollView.isTracking || scrollView.isDecelerating else { return }+ if y < lastOffset - 0.5 {+ setFollowing(false)+ } else if y > lastOffset, view.endOffset - y < ConversationCollectionView.nearEnd {+ setFollowing(true)+ }+ if !view.following, y + scrollView.adjustedContentInset.top < scrollView.bounds.height / 2 {+ parent?.nearTop?()+ }+ }++ func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {+ if !decelerate { settle() }+ }++ func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {+ settle()+ }++ func scrollViewShouldScrollToTop(_ scrollView: UIScrollView) -> Bool {+ setFollowing(false)+ return true+ }++ func scrollViewDidScrollToTop(_ scrollView: UIScrollView) {+ parent?.nearTop?()+ }++ func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {+ view.scrollingToEnd = false+ if view.following { view.pinToEnd() }+ }++ /// The reader stopped scrolling: resting at the end follows again; anywhere else stays put.+ private func settle() {+ scrolling.active = false+ setFollowing(view.endOffset - view.contentOffset.y < ConversationCollectionView.nearEnd)+ if view.following { view.pinToEnd() }+ }+ }+}++/// Holds the end in place: while following, every layout pass (a reply growing, a row going+/// in, the keyboard) ends at the bottom, unless the reader has the list in hand.+private final class ConversationCollectionView: UICollectionView {+ static let nearEnd: CGFloat = 32+ var following = true+ /// An animated scroll down is under way; layout leaves it alone.+ var scrollingToEnd = false++ var endOffset: CGFloat {+ max(contentSize.height + adjustedContentInset.bottom - bounds.height, -adjustedContentInset.top)+ }++ override func layoutSubviews() {+ super.layoutSubviews()+ if following, !isTracking, !isDecelerating, !scrollingToEnd { pinToEnd() }+ }++ func pinToEnd() {+ let end = endOffset+ if abs(contentOffset.y - end) > 0.5 { contentOffset.y = end }+ }++ func scrollToEnd(animated: Bool) {+ let end = endOffset+ guard animated, abs(contentOffset.y - end) > 1 else { return pinToEnd() }+ scrollingToEnd = true+ setContentOffset(CGPoint(x: contentOffset.x, y: end), animated: true)+ }+}++/// Holds the list inside the safe area and lets it reach past it by `outsets`, which become+/// its content insets: rows scroll under the bars and the composer but never get a safe area+/// of their own (a row taking one as padding near an edge would resize itself as it moves).+private final class ConversationContainer: UIView {+ let list: ConversationCollectionView+ var outsets = UIEdgeInsets.zero {+ didSet { if outsets != oldValue { setNeedsLayout() } }+ }++ init(list: ConversationCollectionView) {+ self.list = list+ super.init(frame: .zero)+ addSubview(list)+ }++ @available(*, unavailable)+ required init?(coder: NSCoder) { fatalError("not used") }++ 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+ list.verticalScrollIndicatorInsets = outsets+ if list.following { list.pinToEnd() }+ }+ }++ override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {+ list.frame.contains(point)+ }+}++/// The reader is scrolling: rows read it through `conversationScrolling`.+@Observable @MainActor private final class ScrollingFlag {+ var active = false+}++private struct ConversationCell: View {+ let scrolling: ScrollingFlag+ let content: AnyView++ var body: some View {+ content+ .padding(.horizontal, 16)+ .frame(maxWidth: .infinity, alignment: .leading)+ .environment(\.conversationScrolling, scrolling.active)+ }+}++/// Scrolled away from the newest messages: a round button back down to them.+struct JumpToLatest: View {+ let visible: Bool+ let action: () -> Void+ @Environment(\.accessibilityReduceMotion) private var reduceMotion++ var body: some View {+ ZStack {+ if visible {+ Button("Jump to latest", systemImage: "arrow.down", action: action)+ .labelStyle(.iconOnly)+ .buttonStyle(IconButtonStyle())+ .frosted(in: Circle())+ .shadow(color: .black.opacity(0.12), radius: 10, y: 3)+ .help("Jump to latest")+ .padding(.bottom, 10)+ .transition(.scale(scale: 0.8).combined(with: .opacity))+ }+ }+ .animation(Motion.reduced(Motion.layout, reduceMotion), value: visible)+ }+}+diff --git a/apps/ios/Kit/Sources/CodyncUI/Thread/RepliesView.swift b/apps/ios/Kit/Sources/CodyncUI/Thread/RepliesView.swiftindex b4a78014..5880b4c2 100644--- a/apps/ios/Kit/Sources/CodyncUI/Thread/RepliesView.swift+++ b/apps/ios/Kit/Sources/CodyncUI/Thread/RepliesView.swift@@ -11,8 +11,7 @@ struct RepliesView: View {let close: () -> Void@Environment(BotStore.self) var model@State var showTrace = false- @State var following = true- @Environment(\.accessibilityReduceMotion) var reduceMotion+ @State var following = truevar chat: Bot? { model.bots[botId] }var root: Entry? { model.allEntries(botId).first { $0.id == rootId } }@@ -62,54 +61,41 @@ struct ThreadTarget: Identifiable, Equatable {extension RepliesView {/// iPhone: the replies follow the newest one until the reader scrolls away.- @ViewBuilder var messages: some View {+ var messages: some View {let replies = model.replies(botId, root: rootId)let working = chat?.isWorking(in: botId, thread: rootId) == true && !model.isOfflinelet items = ChatItem.build(replies, streaming: working, steady: true)- ScrollView {- VStack(alignment: .leading, spacing: 0) {- if let root {- ChatRow(entry: root, groupStart: true, chat: chat) { showTrace = true }- .equatable()- HStack(spacing: 10) {- Text(replies.isEmpty ? "No replies yet" : replies.count == 1 ? "1 reply" : "\(replies.count) replies")- .font(.caption)- .foregroundStyle(Palette.tertiary)- .fixedSize()- Rectangle().fill(Palette.border).frame(height: 1)- }- .padding(.vertical, 12)- }- ForEach(items) { item in- if case let .entry(e, groupStart) = item.kind {- ChatRow(entry: e, groupStart: groupStart, chat: chat) { showTrace = true }- .equatable()- .id(item.id)- .transition(item.id == items.last?.id- ? .asymmetric(insertion: .move(edge: .bottom).combined(with: .opacity), removal: .opacity)- : .identity)- }+ var rows: [ConversationRow] = []+ if let root {+ rows.append(ConversationRow("root") {+ ChatRow(entry: root, groupStart: true, chat: chat) { showTrace = true }+ .equatable()+ })+ rows.append(ConversationRow("count") {+ HStack(spacing: 10) {+ Text(replies.isEmpty ? "No replies yet" : replies.count == 1 ? "1 reply" : "\(replies.count) replies")+ .font(.caption)+ .foregroundStyle(Palette.tertiary)+ .fixedSize()+ Rectangle().fill(Palette.border).frame(height: 1)}- if let chat, working {- WorkingIndicator(bot: chat, thinking: model.currentThinking(botId, thread: rootId))- .padding(.top, 6)- .transition(.opacity)- }- Color.clear.frame(height: 8).id("bottom")- }- .padding(.horizontal, 16)- .padding(.top, 8)- .animation(Motion.reduced(Motion.conversation, reduceMotion), value: items.last?.id)- .animation(Motion.reduced(Motion.layout, reduceMotion), value: working)+ .padding(.vertical, 12)+ })}- .scrollIndicators(.never)- .followsConversation($following)- .scrollDismissesKeyboard(.interactively)- .onChange(of: items.last?.id) { _, _ in- if items.last?.isUserMessage == true { following = true }+ for item in items {+ if case let .entry(e, groupStart) = item.kind {+ rows.append(ConversationRow(item.id, isUserMessage: item.isUserMessage) {+ ChatRow(entry: e, groupStart: groupStart, chat: chat) { showTrace = true }+ .equatable()+ })+ }}- .overlay(alignment: .bottom) {- JumpToLatest(visible: !following && !items.isEmpty) { following = true }+ if let chat, working {+ rows.append(ConversationRow("working") {+ WorkingIndicator(bot: chat, thinking: model.currentThinking(botId, thread: rootId))+ .padding(.top, 6)+ })}+ return ConversationList(rows: rows, following: $following)}}diff --git a/apps/ios/Kit/Sources/CodyncUI/Thread/ThreadView.swift b/apps/ios/Kit/Sources/CodyncUI/Thread/ThreadView.swiftindex f0e8f312..2695c037 100644--- a/apps/ios/Kit/Sources/CodyncUI/Thread/ThreadView.swift+++ b/apps/ios/Kit/Sources/CodyncUI/Thread/ThreadView.swift@@ -24,15 +24,9 @@ public struct ThreadView: View {@State var showRoutines = false@State var routineId: String?@State var routineRequest = UUID()- /// iPhone: the chat stays on the newest message until the reader scrolls away.- @State var following = true- /// The oldest message rendered (nil: the latest page).- @State var firstShown: String?- @State var loadingEarlier = false- /// Earlier messages are going in above: this one keeps its place on screen.- @State var keepingPlace: String?- /// The top of the rendered messages is within reach.- @State var topVisible = false+ /// The chat stays on the newest message until the reader scrolls away.+ @State var following = true+ @State var loadingEarlier = false@Environment(\.accessibilityReduceMotion) var reduceMotionvar bot: Bot? { model.bots[botId] }@@ -357,17 +351,6 @@ struct IntroCard: View {}}-extension View {-- @ViewBuilder func conversationScrollEdges() -> some View {- if #available(iOS 26, *) {- scrollEdgeEffectStyle(.soft, for: .top)- } else {- self- }- }-}-extension ThreadView {public var body: some View {conversation@@ -376,104 +359,50 @@ extension ThreadView {}}- /// Messages rendered per page, newest first.- static let page = 40- /// Paging needs to know when the reader nears the top (scroll geometry); before that, all render.- static var paged: Bool {- if #available(iOS 18, *) { true } else { false }- }-private var streaming: Bool { bot?.isWorking(in: botId, thread: nil) == true && !model.isOffline }- /// iPhone's messages: the newest page first, earlier ones as the reader scrolls up (from- /// this device, then from the computer); the chat follows the newest message until they- /// scroll away, and a reply is revealed steadily as it's written.- @ViewBuilder var transcript: some View {+ /// iPhone's messages: all this device has, earlier ones from the computer as the reader+ /// scrolls up; the chat follows the newest message until they scroll away, and a reply is+ /// revealed steadily as it's written.+ var transcript: some View {let thread = model.chat(botId)- let all = ChatItem.build(thread, streaming: streaming, steady: true)- let start = Self.paged ? firstShown.flatMap { id in all.firstIndex { $0.id == id } } ?? max(0, all.count - Self.page) : 0- let items = Array(all[start...])- let moreOnComputer = !model.historyComplete.contains(botId) && thread.count >= 50- ScrollView {- // Not lazy: only a page or a few render, and lazy rows of very different heights- // (long replies) mis-estimate on the way to the bottom and can leave it blank.- VStack(alignment: .leading, spacing: 0) {- if start > 0 || moreOnComputer {- Spinner(size: 14)- .frame(maxWidth: .infinity)- .padding(.vertical, 14)- .onChange(of: following) { _, _ in showEarlier() }- .accessibilityLabel("Loading earlier messages")- }- if all.isEmpty, let bot {- if bot.isGroup { GroupIntroCard(group: bot).padding(.top, 40) } else { IntroCard(bot: bot).padding(.top, 40) }- }- ForEach(items) { item in- row(item)- .id(item.id)- .transition(item.id == items.last?.id- ? .asymmetric(insertion: .move(edge: .bottom).combined(with: .opacity), removal: .opacity)- : .identity)- }- // Offline, "working" is only what the computer last said; don't show it as live.- if let bot, bot.isWorking(in: botId, thread: nil), !model.isOffline {- WorkingIndicator(bot: bot, thinking: model.currentThinking(botId, thread: nil))- .padding(.top, 6)- .id("working")- .transition(.opacity)- }- Color.clear.frame(height: 8).id("bottom")- }- .padding(.horizontal, 16)- .padding(.top, 8)- .animation(Motion.reduced(Motion.conversation, reduceMotion), value: items.last?.id)- .animation(Motion.reduced(Motion.layout, reduceMotion), value: bot?.isWorking(in: botId, thread: nil))- }- .scrollIndicators(.never)- .nearTop { near in- topVisible = near- showEarlier()+ let items = ChatItem.build(thread, streaming: streaming, steady: true)+ var rows: [ConversationRow] = []+ if moreOnComputer {+ rows.append(ConversationRow("earlier") {+ Spinner(size: 14)+ .frame(maxWidth: .infinity)+ .padding(.vertical, 14)+ .accessibilityLabel("Loading earlier messages")+ })}- .followsConversation($following, keepingPlace: $keepingPlace)- .scrollDismissesKeyboard(.interactively)- .conversationScrollEdges()- .simultaneousGesture(TapGesture().onEnded { dismissChatKeyboard() })- .onChange(of: items.last?.id) { _, _ in- // Sending brings the chat back down to your message.- if items.last?.isUserMessage == true { following = true }+ if items.isEmpty, let bot {+ rows.append(ConversationRow("intro") {+ if bot.isGroup { GroupIntroCard(group: bot).padding(.top, 40) } else { IntroCard(bot: bot).padding(.top, 40) }+ })}- .overlay(alignment: .bottom) {- JumpToLatest(visible: !following && !items.isEmpty) { following = true }+ rows += items.map { item in ConversationRow(item.id, isUserMessage: item.isUserMessage) { row(item) } }+ // Offline, "working" is only what the computer last said; don't show it as live.+ if let bot, streaming {+ rows.append(ConversationRow("working") {+ WorkingIndicator(bot: bot, thinking: model.currentThinking(botId, thread: nil))+ .padding(.top, 6)+ })}- .onAppear { if firstShown == nil { firstShown = items.first?.id } }+ return ConversationList(rows: rows, following: $following) { showEarlier() }}- /// The reader scrolled up to the top: render the previous page, fetching it from the- /// computer when this device has no more. The message they were on keeps its place.+ private var moreOnComputer: Bool {+ !model.historyComplete.contains(botId) && model.chat(botId).count >= 50+ }++ /// The reader scrolled up to the top: fetch earlier messages from the computer.private func showEarlier() {- guard topVisible, !following, !loadingEarlier else { return }+ guard moreOnComputer, !loadingEarlier else { return }loadingEarlier = trueTask {- var list = ChatItem.build(model.chat(botId), streaming: streaming, steady: true)- var start = firstShown.flatMap { id in list.firstIndex { $0.id == id } } ?? max(0, list.count - Self.page)- if start == 0 {- let anchor = list.first?.id- await model.loadOlder(botId)- list = ChatItem.build(model.chat(botId), streaming: streaming, steady: true)- start = anchor.flatMap { id in list.firstIndex { $0.id == id } } ?? 0- }- guard start > 0 else {- loadingEarlier = false- return- }- keepingPlace = list[start].id- firstShown = list[max(0, start - Self.page)].id- // Rows above settle over a few layout passes.- try? await Task.sleep(for: .milliseconds(400))- keepingPlace = nil+ await model.loadOlder(botId)loadingEarlier = false- // Still at the top with more to show: keep going.- showEarlier()}}@@ -527,10 +456,6 @@ extension ThreadView {.symbolEffect(.pulse, options: .repeating, isActive: operating)}- func dismissChatKeyboard() {- UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)- }-func presentRoutine() {showRoutines = true}diff --git a/docs/design/ui-conventions.md b/docs/design/ui-conventions.mdindex 773d646f..f60d1700 100644--- a/docs/design/ui-conventions.md+++ b/docs/design/ui-conventions.md@@ -35,7 +35,7 @@ The chat window's account menu copies Grok Bot's: Usage, Get Codync for mobile,The iPhone and the desktop no longer share UI code. `CodyncUI` (`apps/ios/Kit/`) is the iPhone app's own package; the desktop app (`apps/desktop/src/renderer/`) is a TypeScript port of the same screens with its own `BotStore`, chat items (`views/thread/chat-items.ts`) and Markdown blocks (`markdown-blocks.ts`).-- The iPhone chat's chrome is in `ThreadView.swift` (`body`, `chrome`, `header`). The iPhone conversation renders the newest page first and earlier ones as the reader scrolls up, follows the newest message until they scroll away (`ConversationFollow.swift`, with a round "Jump to latest" button), and reveals a reply steadily as it's written (`ChatRows.swift`, `MarkdownText.swift`).+- The iPhone chat's chrome is in `ThreadView.swift` (`body`, `chrome`, `header`). The iPhone conversation (chat and thread) is a UIKit collection view of hosted SwiftUI rows (`ConversationList.swift`): it loads earlier messages from the computer as the reader scrolls up, runs under the bars and the composer (the list sits in the safe area and reaches past it, so rows never get a safe area of their own), and follows the newest message until they scroll away (with a round "Jump to latest" button), and reveals a reply steadily as it's written (`ChatRows.swift`, `MarkdownText.swift`).- The desktop UI rules (custom controls, no system menus except the tray, icon-only buttons, fill or border) are implemented in `apps/desktop/src/renderer/components/` (`Controls.tsx`, `Overlay.tsx`, `Icon.tsx`).- A change to one lands in the other and the TUI in the same change; see [native client parity](#native-client-parity).