Files
buzz/mobile/lib/features/channels/typing_motion_preview.dart
klopez4212 8260b6ef4c feat(mobile): group typing avatars into one animated indicator (#8543)
## Summary
Replace stacked mobile typing rows with one animated avatar cluster and
one typing bubble. People and agents share diagonal, triangle, and
four-corner layouts, with a circular +N badge for overflow and
reduced-motion support.

Includes an opt-in local demo (`BUZZ_TYPING_PREVIEW=true`) with mixed
human/agent avatars and count controls; it never publishes typing
events.

### Related issue
Follow-up to #8505. No duplicate found in the typing-avatar PR search.

### Testing
- 3,736 mobile tests plus four unconfigured-push tests passed; analysis
and file-size checks passed.
- Installed and iterated on a physical iPhone with the existing
profile/community preserved; owner reviewed the motion and badge sizing.

Signed-off-by: kenny lopez <klopez4212@gmail.com>
Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
2026-10-22 10:20:23 -07:00

120 lines
4.3 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import '../../shared/profile/user_cache_provider.dart';
import '../../shared/mentions/agent_identity_provider.dart';
import '../../shared/theme/theme.dart';
import '../../shared/widgets/avatar_image.dart';
import 'channel_typing_provider.dart';
import 'inline_agent_typing.dart';
/// Install-only motion playground. Never publishes typing events.
class TypingMotionPreview extends HookConsumerWidget {
const TypingMotionPreview({super.key, required this.channelId});
final String channelId;
static const enabled = bool.fromEnvironment('BUZZ_TYPING_PREVIEW');
@override
Widget build(BuildContext context, WidgetRef ref) {
final count = useState(1);
final playing = useState(true);
final reduced = MediaQuery.disableAnimationsOf(context);
final profiles = ref.watch(userCacheProvider);
final bots = ref.watch(agentMentionPubkeysProvider(channelId));
final agentKeys = {
for (final profile in profiles.values)
if (profile.isAgent || bots.contains(profile.pubkey)) profile.pubkey,
...bots,
}.take(8).toList();
const demoKeys = ['typing-preview-agent-1', 'typing-preview-agent-2'];
agentKeys.insertAll(0, demoKeys);
final people = profiles.keys
.where(
(key) => !bots.contains(key) && !(profiles[key]?.isAgent ?? false),
)
.take(8)
.toList();
// Deliberately alternate shapes, rather than letting cache insertion order
// fill every demo slot with people before an agent can appear.
final keys = <String>[];
for (
var i = 0;
keys.length < 8 && (i < people.length || i < agentKeys.length);
i++
) {
if (i < people.length) keys.add(people[i]);
if (keys.length < 8 && i < agentKeys.length) keys.add(agentKeys[i]);
}
useEffect(() {
if (!playing.value || reduced || keys.isEmpty) return null;
final timer = Timer.periodic(const Duration(seconds: 2), (_) {
count.value = count.value >= keys.length ? 1 : count.value + 1;
});
return timer.cancel;
}, [playing.value, reduced, keys.length]);
final shown = count.value.clamp(1, keys.isEmpty ? 1 : keys.length);
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Flexible(
child: Text(
'Typing preview · $shown · demo agents',
style: context.textTheme.labelSmall,
),
),
IconButton(
tooltip: playing.value ? 'Pause preview' : 'Play preview',
onPressed: () => playing.value = !playing.value,
icon: Icon(playing.value ? Icons.pause : Icons.play_arrow),
),
IconButton(
tooltip: 'Fewer people',
onPressed: () {
playing.value = false;
count.value = shown > 1 ? shown - 1 : 1;
},
icon: const Icon(Icons.remove),
),
IconButton(
tooltip: 'More people',
onPressed: () {
playing.value = false;
count.value = shown < keys.length ? shown + 1 : shown;
},
icon: const Icon(Icons.add),
),
],
),
if (keys.isNotEmpty)
InlineAgentTyping(
channelId: channelId,
previewAvatars: {
for (final key in demoKeys)
key: AvatarImage(
imageUrl: null,
radius: messageAvatarSize / 2,
isAgent: true,
backgroundColor: context.colors.primaryContainer,
fallback: Icon(
Icons.smart_toy_rounded,
color: context.colors.onPrimaryContainer,
size: 24,
),
),
},
entries: [
for (final key in keys.take(shown))
TypingEntry(pubkey: key, expiresAtMs: 0),
],
)
else
const Text('Waiting for community profiles…'),
],
);
}
}