mirror of
https://github.com/block/buzz.git
synced 2026-12-01 21:51:51 +00:00
Match the iOS Set Status layout to Rename Section (#9970)
The iOS Set Status sheet now puts the emoji picker beside the status text using the same input row as Rename Section. Tap the circle to choose an emoji, or hold it to type, paste, or remove one. Typed statuses default to 💬. The field grows with Dynamic Type and keeps both ends fully rounded. ## Snapshots The native editor on an iPhone 17 Pro simulator, presented in a standalone host showing the “In a meeting” preset before the change and the typed status “Focusing” with its default emoji afterward. | Before | After | | --- | --- | |  |  | ## Verification Exercised the preset in both simulator builds and verified it populates the text field and enables Set. Updated the native editor regression test to check that the emoji button and status field share one row. --------- Signed-off-by: kenny lopez <klopez4212@gmail.com> Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
This commit is contained in:
@@ -103,10 +103,14 @@ final class NativeProfileTextEditorCoordinator: NSObject,
|
||||
return
|
||||
}
|
||||
let editor = NativeStatusEditorViewController(
|
||||
configuration: arguments,
|
||||
configuration: arguments, initialThumbnail: emojiThumbnail(arguments),
|
||||
onChooseEmoji: { [weak self] completion in
|
||||
self?.channel.invokeMethod("chooseStatusEmoji", arguments: nil) { value in
|
||||
completion(value as? String)
|
||||
guard let selection = value as? [String: Any], let emoji = selection["emoji"] as? String else {
|
||||
completion(nil)
|
||||
return
|
||||
}
|
||||
completion((emoji, emojiThumbnail(selection)))
|
||||
}
|
||||
},
|
||||
onCancel: { [weak self] in self?.finish(value: nil) },
|
||||
@@ -345,11 +349,7 @@ final class NativeProfileTextEditorViewController:
|
||||
sectionIcon = selection["icon"] as? String ?? ""
|
||||
emojiButton.accessibilityValue = sectionIcon.isEmpty ? nil : sectionIcon
|
||||
let custom = sectionIcon.hasPrefix(":") && sectionIcon.hasSuffix(":")
|
||||
var image: UIImage?
|
||||
if let bytes = selection["iconBytes"] as? FlutterStandardTypedData,
|
||||
let source = UIImage(data: bytes.data) {
|
||||
image = source.preparingThumbnail(of: CGSize(width: 26, height: 26))?.withRenderingMode(.alwaysOriginal)
|
||||
}
|
||||
var image = emojiThumbnail(selection)
|
||||
if image == nil && (sectionIcon.isEmpty || custom) {
|
||||
image = UIImage(systemName: custom ? "sparkles" : "face.smiling")
|
||||
}
|
||||
@@ -677,28 +677,8 @@ final class NativeProfileTextEditorViewController:
|
||||
])
|
||||
placeholderLabel.isHidden = !textView.text.isEmpty
|
||||
} else if originalSectionIcon != nil {
|
||||
cell.backgroundColor = .clear
|
||||
cell.clipsToBounds = false
|
||||
let fieldContainer = UIView()
|
||||
fieldContainer.layer.cornerRadius = containerCornerRadius
|
||||
fieldContainer.layer.cornerCurve = .continuous
|
||||
fieldContainer.backgroundColor = containerBackgroundColor
|
||||
fieldContainer.addSubview(textField)
|
||||
let row = UIStackView(arrangedSubviews: [emojiButton, fieldContainer])
|
||||
row.spacing = 8
|
||||
row.translatesAutoresizingMaskIntoConstraints = false
|
||||
cell.contentView.addSubview(row)
|
||||
NSLayoutConstraint.activate([
|
||||
row.leadingAnchor.constraint(equalTo: cell.contentView.leadingAnchor),
|
||||
row.trailingAnchor.constraint(equalTo: cell.contentView.trailingAnchor),
|
||||
row.topAnchor.constraint(equalTo: cell.contentView.topAnchor),
|
||||
row.bottomAnchor.constraint(equalTo: cell.contentView.bottomAnchor),
|
||||
emojiButton.widthAnchor.constraint(equalTo: row.heightAnchor),
|
||||
textField.leadingAnchor.constraint(equalTo: fieldContainer.leadingAnchor, constant: 16),
|
||||
textField.trailingAnchor.constraint(equalTo: fieldContainer.trailingAnchor, constant: -16),
|
||||
textField.topAnchor.constraint(equalTo: fieldContainer.topAnchor),
|
||||
textField.bottomAnchor.constraint(equalTo: fieldContainer.bottomAnchor),
|
||||
])
|
||||
installEmojiEditorRow(in: cell, button: emojiButton, field: textField,
|
||||
background: containerBackgroundColor, radius: containerCornerRadius)
|
||||
} else {
|
||||
cell.contentView.addSubview(textField)
|
||||
NSLayoutConstraint.activate([
|
||||
@@ -722,3 +702,53 @@ private extension UIColor {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private func emojiThumbnail(_ selection: [String: Any]) -> UIImage? {
|
||||
guard let bytes = selection["iconBytes"] as? FlutterStandardTypedData,
|
||||
let source = UIImage(data: bytes.data) else { return nil }
|
||||
return source.preparingThumbnail(of: CGSize(width: 26, height: 26))?.withRenderingMode(.alwaysOriginal)
|
||||
}
|
||||
|
||||
/// Lay out the emoji control and text input used by the section and status editors.
|
||||
@MainActor
|
||||
func installEmojiEditorRow(in cell: UITableViewCell, button: UIButton, field: UITextField,
|
||||
background: UIColor, radius: CGFloat? = nil) {
|
||||
cell.backgroundColor = .clear
|
||||
cell.clipsToBounds = false
|
||||
let fieldContainer: UIView
|
||||
if let radius {
|
||||
fieldContainer = UIView()
|
||||
fieldContainer.layer.cornerRadius = radius
|
||||
fieldContainer.layer.cornerCurve = .continuous
|
||||
} else {
|
||||
fieldContainer = CapsuleFieldContainer()
|
||||
}
|
||||
fieldContainer.backgroundColor = background
|
||||
field.translatesAutoresizingMaskIntoConstraints = false
|
||||
fieldContainer.addSubview(field)
|
||||
let row = UIStackView(arrangedSubviews: [button, fieldContainer])
|
||||
row.spacing = 8
|
||||
row.alignment = .center
|
||||
row.translatesAutoresizingMaskIntoConstraints = false
|
||||
cell.contentView.addSubview(row)
|
||||
NSLayoutConstraint.activate([
|
||||
row.leadingAnchor.constraint(equalTo: cell.contentView.leadingAnchor),
|
||||
row.trailingAnchor.constraint(equalTo: cell.contentView.trailingAnchor),
|
||||
row.topAnchor.constraint(equalTo: cell.contentView.topAnchor),
|
||||
row.bottomAnchor.constraint(equalTo: cell.contentView.bottomAnchor),
|
||||
button.widthAnchor.constraint(equalToConstant: 52),
|
||||
button.heightAnchor.constraint(equalToConstant: 52),
|
||||
fieldContainer.heightAnchor.constraint(equalTo: row.heightAnchor),
|
||||
field.leadingAnchor.constraint(equalTo: fieldContainer.leadingAnchor, constant: 16),
|
||||
field.trailingAnchor.constraint(equalTo: fieldContainer.trailingAnchor, constant: -16),
|
||||
field.topAnchor.constraint(equalTo: fieldContainer.topAnchor),
|
||||
field.bottomAnchor.constraint(equalTo: fieldContainer.bottomAnchor),
|
||||
])
|
||||
}
|
||||
|
||||
private final class CapsuleFieldContainer: UIView {
|
||||
override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
layer.cornerRadius = bounds.height / 2
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,13 @@ import UIKit
|
||||
/// Status uses the same navigation-controller sheet as the profile text forms.
|
||||
final class NativeStatusEditorViewController: UITableViewController, UITextFieldDelegate {
|
||||
let statusField = UITextField()
|
||||
let emojiField = StatusEmojiTextField()
|
||||
private let emojiButton = UIButton(type: .system)
|
||||
private var emoji = ""
|
||||
private var thumbnail: UIImage?
|
||||
private let spinner = UIActivityIndicatorView(style: .medium)
|
||||
let datePicker = UIDatePicker()
|
||||
private let configuration: [String: Any]
|
||||
private let onChooseEmoji: (@escaping (String?) -> Void) -> Void
|
||||
private let onChooseEmoji: (@escaping ((String, UIImage?)?) -> Void) -> Void
|
||||
private let onCancel: () -> Void
|
||||
private let onSet: ([String: Any]) -> Void
|
||||
private var duration: Int
|
||||
@@ -18,8 +21,9 @@ final class NativeStatusEditorViewController: UITableViewController, UITextField
|
||||
private let presets = [("🗣️", "In a meeting"), ("🚌", "Commuting"),
|
||||
("🤒", "Out sick"), ("🏖️", "Vacationing"), ("🏠", "Working remotely")]
|
||||
|
||||
init(configuration: [String: Any], onChooseEmoji: @escaping (@escaping (String?) -> Void) -> Void = { $0(nil) }, onCancel: @escaping () -> Void,
|
||||
init(configuration: [String: Any], initialThumbnail: UIImage? = nil, onChooseEmoji: @escaping (@escaping ((String, UIImage?)?) -> Void) -> Void = { $0(nil) }, onCancel: @escaping () -> Void,
|
||||
onSet: @escaping ([String: Any]) -> Void) {
|
||||
thumbnail = initialThumbnail
|
||||
self.configuration = configuration
|
||||
self.onChooseEmoji = onChooseEmoji
|
||||
self.onCancel = onCancel
|
||||
@@ -57,17 +61,22 @@ final class NativeStatusEditorViewController: UITableViewController, UITextField
|
||||
statusField.accessibilityLabel = "Status"
|
||||
statusField.returnKeyType = .done
|
||||
statusField.delegate = self
|
||||
emojiField.text = configuration["emoji"] as? String ?? ""
|
||||
emojiField.placeholder = "Emoji"
|
||||
emojiField.accessibilityLabel = "Status emoji"
|
||||
emojiField.autocorrectionType = .no
|
||||
emojiField.autocapitalizationType = .none
|
||||
emojiField.clearButtonMode = .whileEditing
|
||||
for field in [statusField, emojiField] {
|
||||
field.font = .preferredFont(forTextStyle: .body)
|
||||
field.adjustsFontForContentSizeCategory = true
|
||||
field.addTarget(self, action: #selector(changed), for: .editingChanged)
|
||||
}
|
||||
emoji = configuration["emoji"] as? String ?? ""
|
||||
emojiButton.backgroundColor = color("containerBackgroundArgb", fallback: .secondarySystemGroupedBackground)
|
||||
emojiButton.layer.cornerRadius = 26
|
||||
spinner.translatesAutoresizingMaskIntoConstraints = false
|
||||
emojiButton.addSubview(spinner)
|
||||
NSLayoutConstraint.activate([
|
||||
spinner.centerXAnchor.constraint(equalTo: emojiButton.centerXAnchor),
|
||||
spinner.centerYAnchor.constraint(equalTo: emojiButton.centerYAnchor),
|
||||
])
|
||||
emojiButton.titleLabel?.font = .systemFont(ofSize: 24)
|
||||
emojiButton.titleLabel?.adjustsFontSizeToFitWidth = true
|
||||
emojiButton.accessibilityLabel = "Choose status emoji"
|
||||
emojiButton.addTarget(self, action: #selector(chooseEmoji), for: .touchUpInside)
|
||||
statusField.font = .preferredFont(forTextStyle: .body)
|
||||
statusField.adjustsFontForContentSizeCategory = true
|
||||
statusField.addTarget(self, action: #selector(changed), for: .editingChanged)
|
||||
datePicker.tintColor = .label
|
||||
datePicker.datePickerMode = .dateAndTime
|
||||
datePicker.preferredDatePickerStyle = .compact
|
||||
@@ -98,7 +107,7 @@ final class NativeStatusEditorViewController: UITableViewController, UITextField
|
||||
|
||||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
switch section {
|
||||
case 0: return 2
|
||||
case 0: return 1
|
||||
case 1: return duration == 0 ? 2 : 1
|
||||
case 2: return presets.count
|
||||
default: return 1
|
||||
@@ -135,29 +144,8 @@ final class NativeStatusEditorViewController: UITableViewController, UITextField
|
||||
cell.selectionStyle = .none
|
||||
switch indexPath.section {
|
||||
case 0:
|
||||
if indexPath.row == 0 {
|
||||
embed(statusField, in: cell)
|
||||
} else {
|
||||
let choose = UIButton(type: .system)
|
||||
choose.setTitle("Choose emoji", for: .normal)
|
||||
choose.addAction(UIAction { [weak self, weak choose] _ in
|
||||
guard let self else { return }
|
||||
self.view.endEditing(true)
|
||||
choose?.isEnabled = false
|
||||
choose?.setTitle("Loading…", for: .normal)
|
||||
self.onChooseEmoji { [weak self, weak choose] value in
|
||||
choose?.isEnabled = true
|
||||
choose?.setTitle("Choose emoji", for: .normal)
|
||||
guard let self, let value else { return }
|
||||
self.emojiField.text = value
|
||||
self.changed()
|
||||
}
|
||||
}, for: .touchUpInside)
|
||||
let row = UIStackView(arrangedSubviews: [emojiField, choose])
|
||||
row.spacing = 12
|
||||
choose.setContentHuggingPriority(.required, for: .horizontal)
|
||||
embed(row, in: cell)
|
||||
}
|
||||
installEmojiEditorRow(in: cell, button: emojiButton, field: statusField,
|
||||
background: color("containerBackgroundArgb", fallback: .secondarySystemGroupedBackground))
|
||||
case 1:
|
||||
if indexPath.row == 1 {
|
||||
embed(datePicker, in: cell)
|
||||
@@ -194,7 +182,8 @@ final class NativeStatusEditorViewController: UITableViewController, UITextField
|
||||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
tableView.deselectRow(at: indexPath, animated: true)
|
||||
if indexPath.section == 2 {
|
||||
emojiField.text = presets[indexPath.row].0
|
||||
thumbnail = nil
|
||||
emoji = presets[indexPath.row].0
|
||||
statusField.text = presets[indexPath.row].1
|
||||
changed()
|
||||
} else if indexPath.section == 3 {
|
||||
@@ -202,10 +191,80 @@ final class NativeStatusEditorViewController: UITableViewController, UITextField
|
||||
}
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
||||
indexPath.section == 0 ? max(52, ceil(statusField.intrinsicContentSize.height) + 16) : UITableView.automaticDimension
|
||||
}
|
||||
|
||||
@objc private func chooseEmoji() {
|
||||
view.endEditing(true)
|
||||
emojiButton.isEnabled = false
|
||||
spinner.startAnimating()
|
||||
emojiButton.setImage(nil, for: .normal)
|
||||
emojiButton.setTitle(nil, for: .normal)
|
||||
onChooseEmoji { [weak self] value in
|
||||
guard let self else { return }
|
||||
self.emojiButton.isEnabled = true
|
||||
self.spinner.stopAnimating()
|
||||
if let (emoji, thumbnail) = value {
|
||||
self.emoji = emoji
|
||||
self.thumbnail = thumbnail
|
||||
}
|
||||
self.changed()
|
||||
}
|
||||
}
|
||||
|
||||
private var effectiveEmoji: String {
|
||||
let hasText = !(statusField.text ?? "").trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
|
||||
return emoji.isEmpty && hasText ? "💬" : emoji
|
||||
}
|
||||
|
||||
@objc private func changed() {
|
||||
navigationItem.rightBarButtonItem?.isEnabled =
|
||||
!(statusField.text ?? "").trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
|
||||
|| !(emojiField.text ?? "").isEmpty
|
||||
let displayEmoji = effectiveEmoji
|
||||
// The color emoji font draws below the center of UIKit’s title line.
|
||||
emojiButton.titleLabel?.transform = CGAffineTransform(
|
||||
translationX: 0, y: displayEmoji.count == 1 ? -3 : 0)
|
||||
let custom = displayEmoji.hasPrefix(":") && displayEmoji.hasSuffix(":")
|
||||
let image = custom ? thumbnail ?? UIImage(systemName: "sparkles")
|
||||
: displayEmoji.isEmpty ? UIImage(systemName: "face.smiling") : nil
|
||||
emojiButton.setImage(image, for: .normal)
|
||||
emojiButton.setTitle(image == nil ? displayEmoji : nil, for: .normal)
|
||||
emojiButton.accessibilityValue = displayEmoji.isEmpty ? nil : displayEmoji
|
||||
var actions = [UIAction(title: "Type or paste emoji") { [weak self] _ in self?.enterEmoji() }]
|
||||
if !emoji.isEmpty {
|
||||
actions.append(UIAction(title: "Remove emoji") { [weak self] _ in self?.removeEmoji() })
|
||||
}
|
||||
emojiButton.menu = UIMenu(children: actions)
|
||||
emojiButton.accessibilityCustomActions = emoji.isEmpty ? [] : [
|
||||
UIAccessibilityCustomAction(name: "Remove emoji") { [weak self] _ in
|
||||
self?.removeEmoji()
|
||||
return true
|
||||
}
|
||||
]
|
||||
navigationItem.rightBarButtonItem?.isEnabled = !displayEmoji.isEmpty
|
||||
}
|
||||
|
||||
private func removeEmoji() {
|
||||
emoji = ""
|
||||
thumbnail = nil
|
||||
changed()
|
||||
}
|
||||
|
||||
private func enterEmoji() {
|
||||
let alert = UIAlertController(title: "Type or paste emoji", message: nil, preferredStyle: .alert)
|
||||
alert.addTextField { field in
|
||||
field.placeholder = "Emoji"
|
||||
field.autocorrectionType = .no
|
||||
field.autocapitalizationType = .none
|
||||
}
|
||||
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel))
|
||||
alert.addAction(UIAlertAction(title: "Set", style: .default) { [weak self, weak alert] _ in
|
||||
guard let self, let text = alert?.textFields?.first?.text,
|
||||
let character = text.trimmingCharacters(in: .whitespacesAndNewlines).first else { return }
|
||||
self.emoji = String(character)
|
||||
self.thumbnail = nil
|
||||
self.changed()
|
||||
})
|
||||
present(alert, animated: true)
|
||||
}
|
||||
|
||||
@objc private func cancel() { onCancel() }
|
||||
@@ -216,7 +275,7 @@ final class NativeStatusEditorViewController: UITableViewController, UITextField
|
||||
|
||||
private func submit(clear: Bool) {
|
||||
onSet([
|
||||
"text": statusField.text ?? "", "emoji": emojiField.text ?? "",
|
||||
"text": statusField.text ?? "", "emoji": effectiveEmoji,
|
||||
"duration": duration, "clear": clear,
|
||||
"expiresAt": duration == 0 ? datePicker.date.timeIntervalSince1970
|
||||
: Date().addingTimeInterval(TimeInterval(duration)).timeIntervalSince1970,
|
||||
@@ -228,11 +287,3 @@ final class NativeStatusEditorViewController: UITableViewController, UITextField
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
/// Open the system's complete emoji keyboard when it is enabled.
|
||||
final class StatusEmojiTextField: UITextField {
|
||||
override var textInputContextIdentifier: String? { "buzz.status.emoji" }
|
||||
override var textInputMode: UITextInputMode? {
|
||||
UITextInputMode.activeInputModes.first { $0.primaryLanguage == "emoji" } ?? super.textInputMode
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,13 +39,14 @@ final class ProfileSetupRecoveryTests: XCTestCase {
|
||||
@MainActor
|
||||
func testStatusFormPresetsCustomExpirationClearAndRailActions() throws {
|
||||
var values: [[String: Any]] = []
|
||||
var finishChoice: (((String, UIImage?)?) -> Void)?
|
||||
var cancelled = false
|
||||
let expiration = Date().addingTimeInterval(172800)
|
||||
let editor = NativeStatusEditorViewController(
|
||||
configuration: ["text": "", "emoji": "", "duration": 0,
|
||||
"expiresAt": expiration.timeIntervalSince1970,
|
||||
"hasExistingStatus": true],
|
||||
onChooseEmoji: { $0(":buzz:") },
|
||||
onChooseEmoji: { finishChoice = $0 },
|
||||
onCancel: { cancelled = true }, onSet: { values.append($0) })
|
||||
let navigation = UINavigationController(rootViewController: editor)
|
||||
navigation.loadViewIfNeeded()
|
||||
@@ -70,10 +71,24 @@ final class ProfileSetupRecoveryTests: XCTestCase {
|
||||
editor.tableView(editor.tableView, didSelectRowAt: IndexPath(row: 0, section: 2))
|
||||
XCTAssertTrue(submit.isEnabled)
|
||||
XCTAssertEqual(editor.statusField.text, "In a meeting")
|
||||
let emojiCell = editor.tableView(editor.tableView, cellForRowAt: IndexPath(row: 1, section: 0))
|
||||
let chooseEmoji = try XCTUnwrap(descendants(emojiCell).compactMap { $0 as? UIButton }.first { $0.title(for: .normal) == "Choose emoji" })
|
||||
XCTAssertEqual(editor.tableView(editor.tableView, numberOfRowsInSection: 0), 1)
|
||||
let emojiCell = editor.tableView(editor.tableView, cellForRowAt: IndexPath(row: 0, section: 0))
|
||||
XCTAssertTrue(editor.statusField.isDescendant(of: emojiCell))
|
||||
let chooseEmoji = try XCTUnwrap(descendants(emojiCell).compactMap { $0 as? UIButton }.first { $0.accessibilityLabel == "Choose status emoji" })
|
||||
chooseEmoji.sendActions(for: .touchUpInside)
|
||||
XCTAssertEqual(editor.emojiField.text, ":buzz:")
|
||||
let spinner = try XCTUnwrap(descendants(chooseEmoji).compactMap { $0 as? UIActivityIndicatorView }.first)
|
||||
XCTAssertTrue(spinner.isAnimating)
|
||||
finishChoice?((":buzz:", nil))
|
||||
XCTAssertFalse(spinner.isAnimating)
|
||||
XCTAssertNotNil(chooseEmoji.image(for: .normal))
|
||||
XCTAssertNil(chooseEmoji.title(for: .normal))
|
||||
XCTAssertTrue(chooseEmoji.menu?.children.contains { $0.title == "Type or paste emoji" } == true)
|
||||
editor.statusField.font = .preferredFont(forTextStyle: .body, compatibleWith:
|
||||
UITraitCollection(preferredContentSizeCategory: .accessibilityExtraExtraExtraLarge))
|
||||
let rowHeight = editor.tableView(editor.tableView, heightForRowAt: IndexPath(row: 0, section: 0))
|
||||
XCTAssertGreaterThan(rowHeight, 52)
|
||||
XCTAssertGreaterThanOrEqual(rowHeight, editor.statusField.intrinsicContentSize.height)
|
||||
XCTAssertEqual(chooseEmoji.accessibilityValue, ":buzz:")
|
||||
UIApplication.shared.sendAction(try XCTUnwrap(submit.action), to: submit.target, from: submit, for: nil)
|
||||
XCTAssertEqual(values.last?["text"] as? String, "In a meeting")
|
||||
XCTAssertEqual(values.last?["emoji"] as? String, ":buzz:")
|
||||
|
||||
@@ -86,6 +86,20 @@ Future<void> _showNativeStatusEditor(
|
||||
final notifier = container.read(userStatusProvider.notifier);
|
||||
final sheetTheme = utilitySheetThemeData(Theme.of(context));
|
||||
final currentExpiration = currentStatus?.expirationDateTime;
|
||||
Map<String, Object?> selection(String emoji) {
|
||||
if (!emoji.startsWith(':')) return {'emoji': emoji};
|
||||
final url = container
|
||||
.read(customEmojiListProvider)
|
||||
.where((entry) => ':${entry.shortcode}:' == emoji)
|
||||
.firstOrNull
|
||||
?.url;
|
||||
return {
|
||||
'emoji': emoji,
|
||||
if (url != null)
|
||||
'iconBytes': container.read(customEmojiBytesCacheProvider).lookup(url),
|
||||
};
|
||||
}
|
||||
|
||||
var draft = <String, dynamic>{
|
||||
'text': currentStatus?.text ?? '',
|
||||
'emoji': currentStatus?.emoji ?? '',
|
||||
@@ -103,25 +117,31 @@ Future<void> _showNativeStatusEditor(
|
||||
if (call.method != 'chooseStatusEmoji' || !context.mounted) return null;
|
||||
// Resolve the palette before opening the picker: its Flutter loading
|
||||
// surface would otherwise sit underneath this native presentation.
|
||||
await container.read(customEmojiPaletteProvider.future);
|
||||
var unicodeOnly = false;
|
||||
try {
|
||||
await container.read(customEmojiPaletteProvider.future);
|
||||
} catch (_) {
|
||||
unicodeOnly = true;
|
||||
}
|
||||
if (!context.mounted) return null;
|
||||
final selection = Completer<String?>();
|
||||
final result = Completer<Map<String, Object?>?>();
|
||||
showEmojiPicker(
|
||||
context: context,
|
||||
nativeEmojiOnly: unicodeOnly,
|
||||
onSelect: (emoji) {
|
||||
if (!selection.isCompleted) selection.complete(emoji);
|
||||
if (!result.isCompleted) result.complete(selection(emoji));
|
||||
},
|
||||
onDismiss: () {
|
||||
if (!selection.isCompleted) selection.complete(null);
|
||||
if (!result.isCompleted) result.complete(null);
|
||||
},
|
||||
);
|
||||
return selection.future;
|
||||
return result.future;
|
||||
});
|
||||
try {
|
||||
while (context.mounted) {
|
||||
final value = await channel.invokeMapMethod<String, dynamic>(
|
||||
'presentStatus',
|
||||
draft,
|
||||
{...draft, ...selection(draft['emoji'] as String)},
|
||||
);
|
||||
if (value == null) return;
|
||||
final expiration = _nativeStatusExpiration(value['expiresAt']);
|
||||
@@ -199,7 +219,10 @@ class _SetStatusSheet extends HookConsumerWidget {
|
||||
return () => textController.removeListener(listener);
|
||||
}, [textController]);
|
||||
|
||||
final hasContent = text.value.trim().isNotEmpty || emoji.value.isNotEmpty;
|
||||
final effectiveEmoji = emoji.value.isEmpty && text.value.trim().isNotEmpty
|
||||
? '💬'
|
||||
: emoji.value;
|
||||
final hasContent = effectiveEmoji.isNotEmpty;
|
||||
final hasExistingStatus = currentStatus != null && !currentStatus!.isEmpty;
|
||||
|
||||
DateTime expiresAt() => switch (duration.value) {
|
||||
@@ -213,7 +236,7 @@ class _SetStatusSheet extends HookConsumerWidget {
|
||||
try {
|
||||
await ref
|
||||
.read(userStatusProvider.notifier)
|
||||
.setStatus(text.value, emoji.value, expiresAt: expiresAt());
|
||||
.setStatus(text.value, effectiveEmoji, expiresAt: expiresAt());
|
||||
if (context.mounted) Navigator.of(context).pop();
|
||||
} finally {
|
||||
isSaving.value = false;
|
||||
@@ -301,13 +324,15 @@ class _SetStatusSheet extends HookConsumerWidget {
|
||||
),
|
||||
child: _StatusInput(
|
||||
controller: textController,
|
||||
emoji: emoji.value,
|
||||
emoji: effectiveEmoji,
|
||||
enabled: !isSaving.value,
|
||||
onChooseEmoji: () => showEmojiPicker(
|
||||
context: context,
|
||||
onSelect: (value) => emoji.value = value,
|
||||
),
|
||||
onRemoveEmoji: () => emoji.value = '',
|
||||
onRemoveEmoji: emoji.value.isEmpty
|
||||
? null
|
||||
: () => emoji.value = '',
|
||||
onSubmitted: handleSave,
|
||||
),
|
||||
),
|
||||
@@ -388,7 +413,7 @@ class _StatusInput extends ConsumerWidget {
|
||||
final String emoji;
|
||||
final bool enabled;
|
||||
final VoidCallback onChooseEmoji;
|
||||
final VoidCallback onRemoveEmoji;
|
||||
final VoidCallback? onRemoveEmoji;
|
||||
final VoidCallback onSubmitted;
|
||||
|
||||
@override
|
||||
@@ -417,7 +442,7 @@ class _StatusInput extends ConsumerWidget {
|
||||
child: Center(child: _StatusEmojiPreview(emoji: emoji)),
|
||||
),
|
||||
),
|
||||
if (emoji.isNotEmpty)
|
||||
if (onRemoveEmoji != null)
|
||||
Positioned(
|
||||
top: -Grid.half,
|
||||
right: -Grid.half,
|
||||
|
||||
@@ -7,7 +7,6 @@ import 'package:flutter/services.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:buzz/shared/theme/buzz_icons.dart';
|
||||
|
||||
import '../../helpers/widget_helpers.dart';
|
||||
|
||||
@@ -250,7 +249,8 @@ void main() {
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('\u{1F3AF}'), findsNothing);
|
||||
expect(find.byIcon(BuzzIcons.smilePlus), findsOneWidget);
|
||||
expect(find.text('💬'), findsOneWidget);
|
||||
expect(find.byTooltip('Remove status emoji'), findsNothing);
|
||||
expect(
|
||||
tester.widget<TextField>(find.byType(TextField)).controller?.text,
|
||||
'Focusing',
|
||||
@@ -261,7 +261,7 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(statusNotifier.savedText, 'Focusing');
|
||||
expect(statusNotifier.savedEmoji, isEmpty);
|
||||
expect(statusNotifier.savedEmoji, '💬');
|
||||
expect(statusNotifier.savedExpiresAt, isNotNull);
|
||||
expect(
|
||||
statusNotifier.savedExpiresAt!.difference(beforeSave).inSeconds,
|
||||
|
||||
Reference in New Issue
Block a user