Skip to content

Commit 79beb12

Browse files
klopez4212Terp
andauthored
feat(mobile): browse and stage GIFs from the iOS composer (#10017)
## Summary Add Emoji and GIFs segments to the iOS message composer. Both use the same search text. Emoji categories sit in a floating tray, and the selected category has a sheet-colored fill and a neutral outline. The GIF segment loads trending and search results from the community’s KLIPY integration. Tapping a result queues its image in the current draft through the existing attachment flow. The author can add text, remove the attachment, or press Send. ## iPhone Air snapshots | Emoji | GIFs | | --- | --- | | ![Emoji category tray](https://github.com/user-attachments/assets/0a74c938-45f6-41aa-92be-8c600a018a8f) | ![Trending GIFs](https://github.com/user-attachments/assets/07f5e218-da4b-4264-938f-23eed87eae2b) | ![GIF staged in the composer with Send enabled](https://github.com/user-attachments/assets/0a6d0b4e-6518-4143-9e02-643127a22755) ## Testing - Tapped a GIF on an iPhone Air, verified the picker dismissed and Send became enabled, then removed the staged attachment. - Flutter analysis and all 33 emoji-picker tests passed. - On an iPhone Air, switched from Emoji to GIFs with “wave”, then back to Emoji with “cat”. Verified that clearing the search carries across. ## Related issue No duplicate found. --------- Signed-off-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz> Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
1 parent 5cea13d commit 79beb12

25 files changed

Lines changed: 861 additions & 71 deletions

‎docs/gif-search.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ endpoint returns no provider body.
3333

3434
## Message and rendering boundary
3535

36-
Selecting a GIF sends a normal Buzz message containing a KLIPY CDN image URL.
36+
A sent GIF is a normal Buzz message containing an inline Markdown image,
37+
`![title](url)`, pointing to the full KLIPY CDN GIF. Clients replace brackets in
38+
the title with spaces, collapse whitespace, and percent-encode URL parentheses.
3739
Because Buzz's imeta validator permits only hash-verified local `/media/` paths,
3840
external GIFs are deliberately content-only and carry no imeta tag. Buzz does
3941
not download, cache, or store the GIF bytes. Existing image URL rendering

‎mobile/ios/Runner/NativeEmojiPicker.swift‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,32 @@ final class NativeEmojiPickerCoordinator: NSObject,
6262
}
6363
}
6464

65+
@MainActor
66+
static func searchGifs(_ query: String) async throws -> [[String: String]] {
67+
guard let channel = activeCoordinator?.channel else { throw NativeEmojiMediaBytesError() }
68+
nextMediaRequestID += 1
69+
let id = nextMediaRequestID
70+
return try await withTaskCancellationHandler {
71+
try Task.checkCancellation()
72+
return try await withCheckedThrowingContinuation { continuation in
73+
channel.invokeMethod("gifSearch", arguments: ["id": id, "query": query]) { result in
74+
if let rows = result as? [[String: String]] { continuation.resume(returning: rows) }
75+
else { continuation.resume(throwing: NativeEmojiMediaBytesError()) }
76+
}
77+
}
78+
} onCancel: {
79+
Task { @MainActor in channel.invokeMethod("cancelGifSearch", arguments: id) }
80+
}
81+
}
82+
83+
@MainActor
84+
static func stageGif(_ slug: String) async -> Bool {
85+
guard let channel = activeCoordinator?.channel else { return false }
86+
return await withCheckedContinuation { continuation in
87+
channel.invokeMethod("selectGif", arguments: slug) { continuation.resume(returning: $0 as? Bool == true) }
88+
}
89+
}
90+
6591
private func handle(
6692
_ call: FlutterMethodCall,
6793
result: @escaping FlutterResult
@@ -106,6 +132,7 @@ final class NativeEmojiPickerCoordinator: NSObject,
106132
let content = NativeEmojiPickerView(
107133
data: data,
108134
appearance: appearance,
135+
showGifs: arguments["showGifs"] as? Bool ?? false,
109136
largeEmoji: arguments["largeEmoji"] as? Bool ?? false,
110137
initialSkinTone: (arguments["skinTone"] as? NSNumber)?.intValue ?? 0,
111138
onSelect: { [weak self] emoji in self?.select(emoji) },

‎mobile/ios/Runner/NativeEmojiPickerModel.swift‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ struct NativeEmojiPickerAppearance {
1111
let divider: UIColor
1212
let isDark: Bool
1313

14+
var neutral4: UIColor {
15+
UIColor(white: isDark ? 35.0 / 255 : 218.0 / 255, alpha: 1)
16+
}
17+
1418
init(arguments: [String: Any]) {
1519
surface = Self.color(arguments["surfaceColor"], fallback: .systemBackground)
1620
control = Self.color(
@@ -259,8 +263,8 @@ enum NativeEmojiPickerDataLoader {
259263
switch id {
260264
case "people": return "face.smiling"
261265
case "nature": return "leaf"
262-
case "foods": return "fork.knife"
263-
case "activity": return "figure.run"
266+
case "foods": return "cup.and.saucer"
267+
case "activity": return "volleyball"
264268
case "places": return "airplane"
265269
case "objects": return "lightbulb"
266270
case "symbols": return "heart"

‎mobile/ios/Runner/NativeEmojiPickerView.swift‎

Lines changed: 156 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
import Flutter
12
import ImageIO
23
import SwiftUI
34
import UIKit
45

56
struct NativeEmojiPickerView: View {
67
let data: NativeEmojiPickerData
78
let appearance: NativeEmojiPickerAppearance
9+
let showGifs: Bool
10+
@State private var stagingGif = false
11+
@State private var gifsSelected = false
812
let largeEmoji: Bool
913
let onSelect: (String) -> Void
1014
let onSkinToneChanged: (Int) -> Void
@@ -26,12 +30,14 @@ struct NativeEmojiPickerView: View {
2630
init(
2731
data: NativeEmojiPickerData,
2832
appearance: NativeEmojiPickerAppearance,
33+
showGifs: Bool = false,
2934
largeEmoji: Bool = false,
3035
initialSkinTone: Int,
3136
onSelect: @escaping (String) -> Void,
3237
onSkinToneChanged: @escaping (Int) -> Void,
3338
onClose: @escaping () -> Void
3439
) {
40+
self.showGifs = showGifs
3541
self.data = data
3642
self.appearance = appearance
3743
self.largeEmoji = largeEmoji
@@ -51,29 +57,67 @@ struct NativeEmojiPickerView: View {
5157
var body: some View {
5258
ScrollViewReader { proxy in
5359
VStack(spacing: 0) {
60+
if showGifs {
61+
ContentSegments(selection: $gifsSelected)
62+
.disabled(stagingGif)
63+
.frame(height: 32)
64+
.padding(.horizontal, 16)
65+
.padding(.top, 20)
66+
}
5467
header
55-
if query.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
68+
if !showGifs && query.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
5669
categoryRail(proxy)
5770
}
5871
Divider().overlay(Color(uiColor: appearance.divider))
59-
pickerContent
72+
if gifsSelected {
73+
LiveGIFGrid(query: query.trimmingCharacters(in: .whitespacesAndNewlines), fallbackColor: appearance.secondaryText) { slug in
74+
guard gifsSelected, !stagingGif else { return }
75+
stagingGif = true
76+
Task { @MainActor in
77+
guard stagingGif, gifsSelected else { return }
78+
let staged = await NativeEmojiPickerCoordinator.stageGif(slug)
79+
if staged && stagingGif && gifsSelected { onClose() }
80+
stagingGif = false
81+
}
82+
}
83+
.disabled(stagingGif)
84+
} else {
85+
pickerContent.overlay(alignment: .bottom) {
86+
if showGifs && query.isEmpty {
87+
if #available(iOS 26, *) {
88+
categoryRail(proxy).glassEffect(.regular, in: Capsule())
89+
.padding(.horizontal, 24)
90+
.padding(.bottom, 16)
91+
} else {
92+
categoryRail(proxy).background(.regularMaterial, in: Capsule())
93+
.padding(.horizontal, 24)
94+
.padding(.bottom, 16)
95+
}
96+
}
97+
}
98+
}
6099
}
100+
.ignoresSafeArea(.container, edges: showGifs ? .bottom : [])
61101
.background(Color(uiColor: appearance.surface))
62102
}
103+
.interactiveDismissDisabled(stagingGif)
104+
.onDisappear { stagingGif = false }
63105
}
64106

107+
@Environment(\.accessibilityReduceMotion) private var reduceMotion
108+
65109
private var header: some View {
66110
HStack(spacing: 8) {
67111
HStack(spacing: 10) {
68112
TablerNativeIcon(symbol: "magnifyingglass")
69113
.font(.system(size: 17, weight: .medium))
70114
.foregroundStyle(Color(uiColor: appearance.secondaryText))
71-
TextField("Search emoji", text: $query)
115+
TextField(gifsSelected ? "Search GIFs" : "Search emoji", text: $query)
72116
.textInputAutocapitalization(.never)
73117
.autocorrectionDisabled(true)
74118
.submitLabel(.search)
75119
.foregroundStyle(Color(uiColor: appearance.text))
76-
if !query.isEmpty {
120+
if !showGifs && !query.isEmpty {
77121
Button {
78122
query = ""
79123
} label: {
@@ -92,16 +136,21 @@ struct NativeEmojiPickerView: View {
92136
.stroke(Color(uiColor: appearance.divider), lineWidth: 1)
93137
}
94138

95-
Button(action: onClose) {
139+
if !showGifs || !query.isEmpty {
140+
Button(action: { if showGifs { query = "" } else { onClose() } }) {
96141
TablerNativeIcon(symbol: "xmark")
97142
.font(.system(size: 17, weight: .semibold))
98143
.foregroundStyle(Color(uiColor: appearance.text))
99144
.frame(width: 44, height: 44)
100145
.background(Color(uiColor: appearance.control), in: Circle())
146+
.overlay { Circle().strokeBorder(Color(uiColor: appearance.divider), lineWidth: 1) }
101147
}
102148
.buttonStyle(.plain)
103-
.accessibilityLabel("Close sheet")
149+
.accessibilityLabel(showGifs ? "Clear search" : "Close sheet")
150+
.transition(.scale(scale: 0.75).combined(with: .opacity))
151+
}
104152
}
153+
.animation(showGifs && !reduceMotion ? .easeOut(duration: 0.16) : nil, value: query.isEmpty)
105154
.padding(.horizontal, 16)
106155
.padding(.top, 16)
107156
.padding(.bottom, 8)
@@ -113,6 +162,9 @@ struct NativeEmojiPickerView: View {
113162
NativeEmojiCategoryButton(
114163
section: section,
115164
appearance: appearance,
165+
highlightColor: showGifs ? appearance.surface : appearance.control,
166+
outlineColor: showGifs ? appearance.neutral4 : nil,
167+
selectedIconColor: showGifs ? appearance.text : appearance.accent,
116168
selection: categorySelection
117169
) {
118170
categorySelection.select(section.id)
@@ -128,8 +180,9 @@ struct NativeEmojiPickerView: View {
128180
skinToneSelector
129181
.frame(maxWidth: .infinity)
130182
}
131-
.padding(.horizontal, 16)
132-
.frame(height: 44)
183+
.frame(height: 36)
184+
.padding(.vertical, 4)
185+
.padding(.horizontal, showGifs ? 4 : 16)
133186
}
134187

135188
private var skinToneSelector: some View {
@@ -284,7 +337,7 @@ struct NativeEmojiPickerView: View {
284337
}
285338
}
286339
}
287-
.padding(.bottom, 8)
340+
.padding(.bottom, showGifs && query.isEmpty ? 68 : 8)
288341
.background(contentBoundaryReporter())
289342
}
290343
.coordinateSpace(name: sectionListSpace)
@@ -379,6 +432,9 @@ struct NativeEmojiPickerView: View {
379432
private struct NativeEmojiCategoryButton: View {
380433
let section: NativeEmojiSection
381434
let appearance: NativeEmojiPickerAppearance
435+
let highlightColor: UIColor
436+
let outlineColor: UIColor?
437+
let selectedIconColor: UIColor
382438
@ObservedObject var selection: NativeEmojiCategorySelection
383439
let onSelect: () -> Void
384440

@@ -390,15 +446,20 @@ private struct NativeEmojiCategoryButton: View {
390446
.foregroundStyle(
391447
Color(
392448
uiColor: isSelected
393-
? appearance.accent : appearance.secondaryText
449+
? selectedIconColor : appearance.secondaryText
394450
)
395451
)
396452
.frame(maxWidth: .infinity)
397453
.frame(height: 36)
398454
.background(
399-
isSelected ? Color(uiColor: appearance.control) : Color.clear,
455+
isSelected ? Color(uiColor: highlightColor) : Color.clear,
400456
in: Circle()
401457
)
458+
.overlay {
459+
if isSelected, let outlineColor {
460+
Circle().strokeBorder(Color(uiColor: outlineColor), lineWidth: 1)
461+
}
462+
}
402463
}
403464
.buttonStyle(.plain)
404465
.accessibilityLabel(section.title)
@@ -409,6 +470,7 @@ private struct NativeEmojiCategoryButton: View {
409470
struct NativeEmojiRemoteImage: View {
410471
let url: URL
411472
let fallbackColor: UIColor
473+
var maximumPixelSize = 84
412474

413475
@State private var phase: Phase = .loading
414476

@@ -432,7 +494,7 @@ struct NativeEmojiRemoteImage: View {
432494
}
433495
.task(id: url) {
434496
do {
435-
phase = .success(try await NativeEmojiRemoteImageLoader.image(for: url))
497+
phase = .success(try await NativeEmojiRemoteImageLoader.image(for: url, maximumPixelSize: maximumPixelSize))
436498
} catch {
437499
if !Task.isCancelled { phase = .failure }
438500
}
@@ -475,7 +537,7 @@ enum NativeEmojiRemoteImageLoader {
475537
private static let maximumPixelSize = 84
476538

477539
@MainActor
478-
static func image(for url: URL) async throws -> UIImage {
540+
static func image(for url: URL, maximumPixelSize: Int = 84) async throws -> UIImage {
479541
let bytes = try await NativeEmojiPickerCoordinator.mediaBytes(for: url)
480542
// Bytes can arrive after the cell left; don't decode for a dead view
481543
// while visible cells wait for the decode threads.
@@ -548,3 +610,84 @@ private struct TablerNativeIcon: View {
548610
}
549611
}
550612
}
613+
614+
private struct ContentSegments: UIViewRepresentable {
615+
@Binding var selection: Bool
616+
617+
func makeUIView(context: Context) -> UISegmentedControl {
618+
let control = UISegmentedControl(items: ["Emoji", "GIFs"])
619+
control.addAction(UIAction { [weak control] _ in
620+
selection = control?.selectedSegmentIndex == 1
621+
}, for: .valueChanged)
622+
return control
623+
}
624+
625+
func updateUIView(_ control: UISegmentedControl, context: Context) {
626+
let index = selection ? 1 : 0
627+
if control.selectedSegmentIndex != index { control.selectedSegmentIndex = index }
628+
}
629+
}
630+
631+
private struct LiveGIFGrid: View {
632+
let query: String
633+
let fallbackColor: UIColor
634+
let onSelect: (String) -> Void
635+
@State private var rows: [[String: String]] = []
636+
@State private var loading = true
637+
@State private var failed = false
638+
639+
640+
var body: some View {
641+
VStack {
642+
ScrollView {
643+
if loading {
644+
ProgressView().padding()
645+
} else if failed {
646+
Text("GIF search unavailable").padding()
647+
} else if rows.isEmpty {
648+
Text("No GIFs found").padding()
649+
} else {
650+
LazyVGrid(columns: [GridItem(.flexible()), GridItem(.flexible())]) {
651+
ForEach(rows.indices, id: \.self) { index in
652+
if let raw = rows[index]["url"], let url = URL(string: raw) {
653+
Button {
654+
if let slug = rows[index]["slug"] { onSelect(slug) }
655+
} label: {
656+
NativeEmojiRemoteImage(url: url, fallbackColor: fallbackColor, maximumPixelSize: 300)
657+
.id(url)
658+
.allowsHitTesting(false)
659+
.frame(maxWidth: .infinity)
660+
.frame(height: 136)
661+
.clipShape(RoundedRectangle(cornerRadius: 10))
662+
.contentShape(Rectangle())
663+
}
664+
.buttonStyle(.plain)
665+
.accessibilityLabel(rows[index]["title"] ?? "GIF")
666+
.accessibilityIdentifier("gif-result")
667+
}
668+
}
669+
}
670+
.padding(16)
671+
}
672+
}
673+
Text("Powered by KLIPY")
674+
.font(.footnote)
675+
.foregroundStyle(.secondary)
676+
.padding(.bottom, 16)
677+
}
678+
.task(id: query) {
679+
loading = true
680+
do {
681+
if !query.isEmpty { try await Task.sleep(nanoseconds: 400_000_000) }
682+
let result = try await NativeEmojiPickerCoordinator.searchGifs(query)
683+
try Task.checkCancellation()
684+
rows = result
685+
failed = false
686+
} catch {
687+
guard !Task.isCancelled else { return }
688+
failed = true
689+
}
690+
loading = false
691+
}
692+
}
693+
}

‎mobile/ios/Runner/NativeTabler.swift‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ enum NativeTabler {
9595
"sparkles": 0xf6d7, // sparkles
9696
"clock": 0xea70, // clock
9797
"leaf": 0xed4f, // leaf
98-
"fork.knife": 0xeeff, // tools-kitchen-2
99-
"figure.run": 0xec82, // run
98+
"cup.and.saucer": 0xef0e, // coffee
99+
"volleyball": 0xec2b, // ball-volleyball
100100
"airplane": 0xeb6f, // plane
101101
"lightbulb": 0xea51, // bulb
102102
"heart": 0xeabe, // heart

0 commit comments

Comments
 (0)