mirror of
https://github.com/block/buzz.git
synced 2026-10-29 05:21:31 +00:00
## Summary - add inline profile photo capture with smooth avatar-to-viewfinder transitions - add close, flip, shutter, retry, and use-photo states with haptics and front-camera mirroring - polish iOS liquid-glass controls and avatar editor motion ### Related issue Follow-up to #6583. ### Testing - just mobile-check - just mobile-test (1,743 tests) - built, installed, and launched on Pixel 10 and iPhone Air --------- Signed-off-by: kenny lopez <klopez4212@gmail.com> Signed-off-by: Code Reviewer <037593536284cf40e221c96c931e9877d4166d54f6bb84e5341a86d7fd5d05a4@buzz.block.builderlab.xyz> Signed-off-by: Perci <5a968df9a7494b4e019b9ecf739e088ba61097b4312124e9a88ae5b42e3f5f3e@buzz.block.builderlab.xyz> Signed-off-by: Max <d8473ee32b973aa31a21a65adddcc4b69cc2a8a4dee8121ecd51926e0cddbc02@buzz.block.builderlab.xyz> Signed-off-by: Wren <5217c5c2f7bfb4333e46d17c98a9255a52dadee18dcd43a43536b95e6776dfa0@buzz.block.builderlab.xyz> Signed-off-by: Meli <5aaa86bce934fc3445fc254aab560a40923f10252f92107e665073dede0e04d3@buzz.block.builderlab.xyz> Signed-off-by: morgmart <98432065+morgmart@users.noreply.github.com> Co-authored-by: Code Reviewer <037593536284cf40e221c96c931e9877d4166d54f6bb84e5341a86d7fd5d05a4@buzz.block.builderlab.xyz> Co-authored-by: Tyler <109685178+tlongwell-block@users.noreply.github.com> Co-authored-by: Perci <5a968df9a7494b4e019b9ecf739e088ba61097b4312124e9a88ae5b42e3f5f3e@buzz.block.builderlab.xyz> Co-authored-by: Max <d8473ee32b973aa31a21a65adddcc4b69cc2a8a4dee8121ecd51926e0cddbc02@buzz.block.builderlab.xyz> Co-authored-by: Wren <5217c5c2f7bfb4333e46d17c98a9255a52dadee18dcd43a43536b95e6776dfa0@buzz.block.builderlab.xyz> Co-authored-by: Meli <5aaa86bce934fc3445fc254aab560a40923f10252f92107e665073dede0e04d3@buzz.block.builderlab.xyz> Co-authored-by: morgmart <98432065+morgmart@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com>
230 lines
7.3 KiB
Dart
230 lines
7.3 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
import '../../shared/relay/relay.dart';
|
|
import '../../shared/theme/theme.dart';
|
|
import '../../shared/widgets/modal_presentation.dart';
|
|
import 'ios_profile_text_editor.dart';
|
|
import 'profile_provider.dart';
|
|
|
|
/// Opens the current user's display-name editor from a profile action surface.
|
|
Future<void> showProfileDisplayNameEditor(BuildContext context) async {
|
|
final container = ProviderScope.containerOf(context, listen: false);
|
|
try {
|
|
await container.read(profileProvider.future);
|
|
} catch (_) {
|
|
return;
|
|
}
|
|
if (!context.mounted) return;
|
|
final profileState = container.read(profileProvider);
|
|
if (!profileState.hasValue) return;
|
|
final profile = profileState.requireValue;
|
|
final onSave = bindProfileSaveToOpeningContext(
|
|
container,
|
|
container.read(profileProvider.notifier).updateDisplayName,
|
|
);
|
|
await _showProfileTextEditor(
|
|
context: context,
|
|
title: 'Display name',
|
|
initialValue: profile?.displayName ?? '',
|
|
hintText: 'Display name',
|
|
onSave: onSave,
|
|
);
|
|
}
|
|
|
|
/// Opens the current user's profile-description editor.
|
|
Future<void> showProfileDescriptionEditor(BuildContext context) async {
|
|
final container = ProviderScope.containerOf(context, listen: false);
|
|
try {
|
|
await container.read(profileProvider.future);
|
|
} catch (_) {
|
|
return;
|
|
}
|
|
if (!context.mounted) return;
|
|
final profileState = container.read(profileProvider);
|
|
if (!profileState.hasValue) return;
|
|
final profile = profileState.requireValue;
|
|
final onSave = bindProfileSaveToOpeningContext(
|
|
container,
|
|
container.read(profileProvider.notifier).updateAbout,
|
|
);
|
|
await _showProfileTextEditor(
|
|
context: context,
|
|
title: 'Profile description',
|
|
initialValue: profile?.about ?? '',
|
|
hintText: 'Profile description',
|
|
multiline: true,
|
|
onSave: onSave,
|
|
);
|
|
}
|
|
|
|
/// Prevents a profile draft from being published after its community changes.
|
|
Future<void> Function(String) bindProfileSaveToOpeningContext(
|
|
ProviderContainer container,
|
|
Future<void> Function(String value) onSave,
|
|
) {
|
|
final openingConfig = container.read(relayConfigProvider);
|
|
final openingPubkey = container.read(myPubkeyProvider);
|
|
final openingSession = container.read(relaySessionProvider.notifier);
|
|
return (value) {
|
|
final currentConfig = container.read(relayConfigProvider);
|
|
final isCurrent =
|
|
currentConfig.storedOrigin == openingConfig.storedOrigin &&
|
|
currentConfig.nsec == openingConfig.nsec &&
|
|
container.read(myPubkeyProvider) == openingPubkey &&
|
|
identical(
|
|
container.read(relaySessionProvider.notifier),
|
|
openingSession,
|
|
);
|
|
if (!isCurrent) throw ProfileCommunityChangedException();
|
|
return onSave(value);
|
|
};
|
|
}
|
|
|
|
Future<void> _showProfileTextEditor({
|
|
required BuildContext context,
|
|
required String title,
|
|
required String initialValue,
|
|
required String hintText,
|
|
required Future<void> Function(String value) onSave,
|
|
bool multiline = false,
|
|
}) async {
|
|
if (defaultTargetPlatform == TargetPlatform.iOS) {
|
|
try {
|
|
await IosProfileTextEditor.presentUntilSaved(
|
|
title: title,
|
|
initialValue: initialValue,
|
|
placeholder: hintText,
|
|
multiline: multiline,
|
|
brightness: Theme.of(context).brightness,
|
|
onSave: onSave,
|
|
shouldRetryOnError: (error) =>
|
|
error is! ProfileCommunityChangedException,
|
|
canPresent: () =>
|
|
context.mounted && (ModalRoute.of(context)?.isCurrent ?? true),
|
|
onSaveError: () {
|
|
if (context.mounted && (ModalRoute.of(context)?.isCurrent ?? true)) {
|
|
_showSaveError(context);
|
|
}
|
|
},
|
|
);
|
|
return;
|
|
} on MissingPluginException {
|
|
// Previews and older builds retain the complete Flutter fallback.
|
|
} on PlatformException {
|
|
// A temporary native presentation failure should not block editing.
|
|
}
|
|
}
|
|
|
|
if (!context.mounted) return;
|
|
await showBuzzModalBottomSheet<void>(
|
|
context: context,
|
|
title: title,
|
|
isScrollControlled: true,
|
|
requestFocus: true,
|
|
builder: (_) => _ProfileTextEditSheet(
|
|
initialValue: initialValue,
|
|
hintText: hintText,
|
|
multiline: multiline,
|
|
onSave: onSave,
|
|
),
|
|
);
|
|
}
|
|
|
|
void _showSaveError(BuildContext context) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(content: Text("We couldn't save this change. Try again.")),
|
|
);
|
|
}
|
|
|
|
class _ProfileTextEditSheet extends HookWidget {
|
|
const _ProfileTextEditSheet({
|
|
required this.initialValue,
|
|
required this.hintText,
|
|
required this.multiline,
|
|
required this.onSave,
|
|
});
|
|
|
|
final String initialValue;
|
|
final String hintText;
|
|
final bool multiline;
|
|
final Future<void> Function(String value) onSave;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final controller = useTextEditingController(text: initialValue);
|
|
useListenable(controller);
|
|
final isSaving = useState(false);
|
|
final error = useState<String?>(null);
|
|
final hasChanges = controller.text.trim() != initialValue.trim();
|
|
|
|
Future<void> save() async {
|
|
if (!hasChanges || isSaving.value) return;
|
|
isSaving.value = true;
|
|
error.value = null;
|
|
try {
|
|
await onSave(controller.text);
|
|
if (context.mounted) Navigator.of(context).pop();
|
|
} on ProfileCommunityChangedException {
|
|
if (context.mounted) Navigator.of(context).pop();
|
|
} catch (_) {
|
|
error.value = "We couldn't save this change. Try again.";
|
|
} finally {
|
|
if (context.mounted) isSaving.value = false;
|
|
}
|
|
}
|
|
|
|
return SafeArea(
|
|
top: false,
|
|
child: Padding(
|
|
padding: EdgeInsets.fromLTRB(
|
|
Grid.gutter,
|
|
Grid.xxs,
|
|
Grid.gutter,
|
|
MediaQuery.viewInsetsOf(context).bottom + Grid.xs,
|
|
),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
TextField(
|
|
key: const ValueKey('profile-field-input'),
|
|
controller: controller,
|
|
autofocus: true,
|
|
enabled: !isSaving.value,
|
|
minLines: multiline ? 4 : 1,
|
|
maxLines: multiline ? 6 : 1,
|
|
textCapitalization: TextCapitalization.sentences,
|
|
textInputAction: multiline
|
|
? TextInputAction.newline
|
|
: TextInputAction.done,
|
|
onSubmitted: multiline ? null : (_) => unawaited(save()),
|
|
decoration: InputDecoration(hintText: hintText),
|
|
),
|
|
if (error.value != null) ...[
|
|
const SizedBox(height: Grid.xxs),
|
|
Text(
|
|
error.value!,
|
|
style: context.textTheme.bodySmall?.copyWith(
|
|
color: context.colors.error,
|
|
),
|
|
),
|
|
],
|
|
const SizedBox(height: Grid.xs),
|
|
FilledButton(
|
|
key: const ValueKey('profile-field-save'),
|
|
onPressed: hasChanges && !isSaving.value ? save : null,
|
|
child: Text(isSaving.value ? 'Saving…' : 'Save'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|