Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ fire/
- iOS / Android 宿主壳已打通登录、会话恢复、bootstrap 刷新与首个 topic list / detail 读取路径
- Android 现已在构建时生成 Kotlin UniFFI bindings 并打包真实 Rust `.so`
- iOS 现已在构建时生成 Swift UniFFI bindings、FFI headers/modulemap,并链接真实 Rust `staticlib`
- iOS 部署目标是 15.0。`apps/ios-app/project.yml` 里 Fire 与 FireTests 的 `deploymentTarget` 都是 `"15.0"`,没有其他 iOS target

## 本地验证

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ extension FireComposerViewController {
guard didLoadDraft else { return }
autosaveTask?.cancel()
autosaveTask = Task {
try? await Task.sleep(for: .seconds(1.2))
try? await fireSleep(nanoseconds: fireNanoseconds(seconds: 1.2))
guard !Task.isCancelled else { return }
await persistDraftIfNeeded()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extension FireComposerViewController {

mentionSearchTask = Task {
do {
try await Task.sleep(for: .milliseconds(200))
try await fireSleep(nanoseconds: fireNanoseconds(milliseconds: 200))
guard !Task.isCancelled else { return }
let result = try await viewModel.searchService.searchUsers(
term: mentionContext.term,
Expand Down Expand Up @@ -80,7 +80,7 @@ extension FireComposerViewController {

recipientSearchTask = Task {
do {
try await Task.sleep(for: .milliseconds(200))
try await fireSleep(nanoseconds: fireNanoseconds(milliseconds: 200))
guard !Task.isCancelled else { return }
let result = try await viewModel.searchService.searchUsers(
term: trimmed,
Expand Down Expand Up @@ -115,7 +115,7 @@ extension FireComposerViewController {

tagSearchTask = Task {
do {
try await Task.sleep(for: .milliseconds(250))
try await fireSleep(nanoseconds: fireNanoseconds(milliseconds: 250))
guard !Task.isCancelled else { return }
let result = try await viewModel.searchService.searchTags(
query: trimmed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,5 @@ struct FireFeedKindSelector: View {
.fill(FireTheme.track)
)
}
.scrollIndicators(.hidden)
}
}
59 changes: 59 additions & 0 deletions apps/ios-app/App/Core/Components/FireListChrome.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import SwiftUI
import UIKit

extension View {
func fireHiddenListBackground() -> some View {
background(FireListBackgroundClearer())
}
}

private struct FireListBackgroundClearer: UIViewRepresentable {
func makeUIView(context: Context) -> FireListBackgroundClearerView {
FireListBackgroundClearerView()
}

func updateUIView(_ view: FireListBackgroundClearerView, context: Context) {
view.clearEnclosingListBackground()
}
}

final class FireListBackgroundClearerView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
isUserInteractionEnabled = false
isHidden = true
backgroundColor = .clear
}

@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) is not supported")
}

override func didMoveToWindow() {
super.didMoveToWindow()
clearEnclosingListBackground()
}

override func layoutSubviews() {
super.layoutSubviews()
clearEnclosingListBackground()
}

func clearEnclosingListBackground() {
var current: UIView? = superview
while let view = current {
if let table = view as? UITableView {
table.backgroundColor = .clear
if table.backgroundView == nil {
table.backgroundView = UIView()
}
table.backgroundView?.backgroundColor = .clear
}
if let collection = view as? UICollectionView {
collection.backgroundColor = .clear
}
current = view.superview
}
}
}
48 changes: 48 additions & 0 deletions apps/ios-app/App/Core/Components/FireSheetDetentAnchor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import SwiftUI
import UIKit

struct FireSheetDetentAnchor: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> FireSheetDetentAnchorController {
FireSheetDetentAnchorController()
}

func updateUIViewController(_ controller: FireSheetDetentAnchorController, context: Context) {
controller.applyDetents()
}
}

final class FireSheetDetentAnchorController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.isHidden = true
view.isUserInteractionEnabled = false
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
applyDetents()
}

func applyDetents() {
DispatchQueue.main.async { [weak self] in
guard let self, let sheet = self.nearestSheet() else { return }
let medium = UISheetPresentationController.Detent.Identifier.medium
let large = UISheetPresentationController.Detent.Identifier.large
if sheet.detents.map(\.identifier) != [medium, large] {
sheet.detents = [.medium(), .large()]
}
sheet.prefersGrabberVisible = true
}
}

private func nearestSheet() -> UISheetPresentationController? {
var current: UIViewController? = self
while let controller = current {
if let sheet = controller.sheetPresentationController {
return sheet
}
current = controller.parent ?? controller.navigationController ?? controller.presentingViewController
}
return nil
}
}
2 changes: 1 addition & 1 deletion apps/ios-app/App/Core/Components/FireToast.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private struct FireToastModifier: ViewModifier {
let toastID = toast.id
dismissTask = Task { @MainActor in
do {
try await Task.sleep(for: .seconds(2.5))
try await fireSleep(nanoseconds: fireNanoseconds(seconds: 2.5))
} catch {
return
}
Expand Down
142 changes: 86 additions & 56 deletions apps/ios-app/App/Core/Components/FlowLayout.swift
Original file line number Diff line number Diff line change
@@ -1,80 +1,110 @@
import SwiftUI
import UIKit

// MARK: - Flow Layout

struct FlowLayout: Layout {
struct FlowLayout<Data: RandomAccessCollection, Content: View>: View where Data.Element: Hashable {
var spacing: CGFloat = 6
var fallbackWidth: CGFloat? = nil
var data: Data
@ViewBuilder var content: (Data.Element) -> Content

func sizeThatFits(
proposal: ProposedViewSize,
subviews: Subviews,
cache: inout ()
) -> CGSize {
let maxWidth = resolvedMaxWidth(for: proposal)
let hasExplicitWidth = proposal.width.map { $0.isFinite && $0 > 0 } ?? false
var lineWidth: CGFloat = 0
var lineHeight: CGFloat = 0
var totalHeight: CGFloat = 0
var maxLineWidth: CGFloat = 0
@State private var sizes: [Data.Element: CGSize] = [:]
@State private var containerWidth: CGFloat = 0

for subview in subviews {
let size = subview.sizeThatFits(.unspecified)
if lineWidth > 0, lineWidth + spacing + size.width > maxWidth {
totalHeight += lineHeight + spacing
maxLineWidth = max(maxLineWidth, lineWidth)
lineWidth = size.width
lineHeight = size.height
} else {
lineWidth += (lineWidth > 0 ? spacing : 0) + size.width
lineHeight = max(lineHeight, size.height)
var body: some View {
let maxWidth = resolvedMaxWidth(containerWidth > 0 ? containerWidth : nil)
let placed = placement(maxWidth: maxWidth)
ZStack(alignment: .topLeading) {
ForEach(Array(data), id: \.self) { element in
content(element)
.fixedSize()
.background(childSizeReader(for: element))
.offset(
x: placed.frames[element]?.minX ?? 0,
y: placed.frames[element]?.minY ?? 0
)
}
}
.frame(maxWidth: .infinity, minHeight: placed.height, alignment: .topLeading)
.background(widthReader)
.onPreferenceChange(FlowWidthKey.self) { newWidth in
guard newWidth > 0, abs(containerWidth - newWidth) > 0.5 else { return }
containerWidth = newWidth
}
}

totalHeight += lineHeight
maxLineWidth = max(maxLineWidth, lineWidth)
private var widthReader: some View {
GeometryReader { proxy in
Color.clear.preference(key: FlowWidthKey.self, value: proxy.size.width)
}
}

let reportedWidth = hasExplicitWidth ? maxWidth : maxLineWidth
return CGSize(width: reportedWidth, height: totalHeight)
private func childSizeReader(for element: Data.Element) -> some View {
GeometryReader { proxy in
Color.clear
.preference(key: FlowChildSizeKey<Data.Element>.self, value: [element: proxy.size])
}
.onPreferenceChange(FlowChildSizeKey<Data.Element>.self) { update in
let measured = update.filter { $0.value.width > 0 || $0.value.height > 0 }
guard !measured.isEmpty else { return }
var next = sizes
for (key, size) in measured where next[key] != size {
next[key] = size
}
if next != sizes {
sizes = next
}
}
}

func placeSubviews(
in bounds: CGRect,
proposal: ProposedViewSize,
subviews: Subviews,
cache: inout ()
) {
var cursor = CGPoint(x: bounds.minX, y: bounds.minY)
private func resolvedMaxWidth(_ proposal: CGFloat?) -> CGFloat {
if let proposal, proposal.isFinite, proposal > 0 {
return proposal
}
if let fallbackWidth, fallbackWidth.isFinite, fallbackWidth > 0 {
return fallbackWidth
}
return max(UIScreen.main.bounds.width - 120, 180)
}

private func placement(maxWidth: CGFloat) -> FlowPlacement<Data.Element> {
var frames: [Data.Element: CGRect] = [:]
var cursorX: CGFloat = 0
var cursorY: CGFloat = 0
var lineHeight: CGFloat = 0

for subview in subviews {
let size = subview.sizeThatFits(.unspecified)
if cursor.x > bounds.minX, cursor.x + size.width > bounds.maxX {
cursor.x = bounds.minX
cursor.y += lineHeight + spacing
for element in data {
let size = sizes[element] ?? .zero
if cursorX > 0, cursorX + size.width > maxWidth {
cursorX = 0
cursorY += lineHeight + spacing
lineHeight = 0
}

subview.place(
at: cursor,
proposal: ProposedViewSize(width: size.width, height: size.height)
)

cursor.x += size.width + spacing
frames[element] = CGRect(origin: CGPoint(x: cursorX, y: cursorY), size: size)
cursorX += size.width + spacing
lineHeight = max(lineHeight, size.height)
}

let height = cursorY + lineHeight
return FlowPlacement(frames: frames, height: height)
}
}

private func resolvedMaxWidth(for proposal: ProposedViewSize) -> CGFloat {
if let proposalWidth = proposal.width, proposalWidth.isFinite, proposalWidth > 0 {
return proposalWidth
}
private struct FlowWidthKey: PreferenceKey {
static var defaultValue: CGFloat = 0

if let fallbackWidth, fallbackWidth.isFinite, fallbackWidth > 0 {
return fallbackWidth
}
static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
value = max(value, nextValue())
}
}

return max(UIScreen.main.bounds.width - 120, 180)
private struct FlowPlacement<Element: Hashable> {
var frames: [Element: CGRect]
var height: CGFloat
}

private struct FlowChildSizeKey<Element: Hashable>: PreferenceKey {
static var defaultValue: [Element: CGSize] { [:] }

static func reduce(value: inout [Element: CGSize], nextValue: () -> [Element: CGSize]) {
value.merge(nextValue(), uniquingKeysWith: { $1 })
}
}
8 changes: 6 additions & 2 deletions apps/ios-app/App/Core/FireContextMenus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ struct FireTopicContextMenu: View {
}
}

ShareLink(item: shareURL) {
Button {
FireSharePresenter.present(shareURL)
} label: {
Label("分享话题", systemImage: "square.and.arrow.up")
}

Expand Down Expand Up @@ -69,7 +71,9 @@ struct FireNotificationContextMenu: View {
}

if let shareURL {
ShareLink(item: shareURL) {
Button {
FireSharePresenter.present(shareURL)
} label: {
Label("分享链接", systemImage: "square.and.arrow.up")
}

Expand Down
35 changes: 35 additions & 0 deletions apps/ios-app/App/Core/FireMonotonicClock.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Foundation

struct FireMonotonicInstant: Equatable, Comparable {
var nanoseconds: UInt64

func advanced(byNanoseconds interval: UInt64) -> FireMonotonicInstant {
FireMonotonicInstant(nanoseconds: nanoseconds &+ interval)
}

func durationNanoseconds(to other: FireMonotonicInstant) -> UInt64 {
other.nanoseconds &- nanoseconds
}

static func < (lhs: FireMonotonicInstant, rhs: FireMonotonicInstant) -> Bool {
lhs.nanoseconds < rhs.nanoseconds
}
}

enum FireMonotonicClock {
static func now() -> FireMonotonicInstant {
FireMonotonicInstant(nanoseconds: clock_gettime_nsec_np(CLOCK_UPTIME_RAW))
}
}

func fireNanoseconds(seconds: Double) -> UInt64 {
UInt64((seconds * 1_000_000_000).rounded())
}

func fireNanoseconds(milliseconds: Double) -> UInt64 {
UInt64((milliseconds * 1_000_000).rounded())
}

func fireSleep(nanoseconds: UInt64) async throws {
try await Task.sleep(nanoseconds: nanoseconds)
}
Loading
Loading