iOS client for Grain grain.social
ios photography atproto
7
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: add compact count formatting for large numbers

Add Int.compactCount extension (1K, 1.2M) and apply to gallery fav
counts, comment counts, and comment fav counts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

+21 -4
+17
Grain/Utilities/StringExtensions.swift
··· 6 6 reduce(into: "") { $0.append(("0" ... "9").contains($1) ? "8" : $1) } 7 7 } 8 8 } 9 + 10 + import Foundation 11 + 12 + extension Int { 13 + /// Compact count formatting: 1K, 1.2M, etc. 14 + var compactCount: String { 15 + if self >= 1_000_000 { 16 + let v = Double(self) / 1_000_000 17 + return v.truncatingRemainder(dividingBy: 1) == 0 ? "\(Int(v))M" : NSString(format: "%.1fM", v) as String 18 + } 19 + if self >= 1000 { 20 + let v = Double(self) / 1000 21 + return v.truncatingRemainder(dividingBy: 1) == 0 ? "\(Int(v))K" : NSString(format: "%.1fK", v) as String 22 + } 23 + return "\(self)" 24 + } 25 + }
+3 -3
Grain/Views/Components/GalleryCardView.swift
··· 463 463 .animation(.spring(response: 0.3, dampingFraction: 0.6), value: isFavorited) 464 464 ZStack { 465 465 let count = gallery.favCount ?? 0 466 - Text("\(count)".digitWidthProxy) 466 + Text(count.compactCount.digitWidthProxy) 467 467 .hidden() 468 - Text("\(count)") 468 + Text(count.compactCount) 469 469 } 470 470 } 471 471 } ··· 491 491 HStack(spacing: 5) { 492 492 Image(systemName: "bubble") 493 493 .font(.system(size: 20)) 494 - Text("\(gallery.commentCount ?? 0)") 494 + Text((gallery.commentCount ?? 0).compactCount) 495 495 } 496 496 } 497 497 .foregroundStyle(.secondary)
+1 -1
Grain/Views/Gallery/GalleryDetailView.swift
··· 283 283 .disabled(isMutating) 284 284 285 285 if displayFavCount > 0 { 286 - Text("\(displayFavCount)") 286 + Text(displayFavCount.compactCount) 287 287 .font(.system(size: 11)) 288 288 .foregroundStyle(.secondary) 289 289 }