Skip to content

Commit f3b78d5

Browse files
klopez4212Terp
andcommitted
fix(mobile): handle avatar loading and return transitions
Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz> Signed-off-by: kenny lopez <[email protected]>
1 parent 6f52377 commit f3b78d5

6 files changed

Lines changed: 111 additions & 11 deletions

File tree

‎mobile/lib/features/agents/agent_avatar_hero.dart‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,17 @@ class AgentAvatarHero extends HookWidget {
7979
),
8080
flightShuttleBuilder: (_, animation, direction, from, to) {
8181
final source = (from.widget as Hero).child as _AvatarEndpoint;
82-
final target = (to.widget as Hero).child as _AvatarEndpoint;
8382
return AnimatedBuilder(
8483
animation: animation,
8584
builder: (_, _) {
85+
// The destination rebuilds with the saved selection after pop.
86+
// Cancel retains its original selection throughout the flight.
87+
final target = (to.widget as Hero).child as _AvatarEndpoint;
8688
final t = direction == HeroFlightDirection.push
8789
? animation.value
8890
: 1 - animation.value;
8991
return _poster(
90-
direction == HeroFlightDirection.push
91-
? target.selection
92-
: source.selection,
92+
target.selection,
9393
source.verticalOffset +
9494
(target.verticalOffset - source.verticalOffset) * t,
9595
);

‎mobile/lib/features/agents/create_agent_page.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ class CreateAgentPage extends HookConsumerWidget {
248248
await precacheImage(
249249
NetworkImage(avatar.value.url!),
250250
context,
251+
onError: (_, _) {},
251252
);
252253
if (!context.mounted) return;
253254
}

‎mobile/lib/shared/widgets/android_transparent_avatar.dart‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,16 @@ class AndroidTransparentAvatar extends HookWidget {
2424
final ready = useState(false);
2525
useEffect(() {
2626
final current = channel.value;
27-
if (current == null) return null;
27+
if (current == null || !playing || ready.value) return null;
2828
var active = true;
2929
Timer? retry;
30-
var attempts = 0;
3130
Future<void> waitForFrame() async {
3231
try {
3332
final available = await current.invokeMethod<bool>('isReady');
3433
if (!active) return;
3534
if (available == true) {
3635
ready.value = true;
37-
} else if (++attempts < 200) {
36+
} else {
3837
retry = Timer(const Duration(milliseconds: 50), waitForFrame);
3938
}
4039
} on PlatformException {
@@ -49,7 +48,7 @@ class AndroidTransparentAvatar extends HookWidget {
4948
active = false;
5049
retry?.cancel();
5150
};
52-
}, [channel.value]);
51+
}, [channel.value, playing]);
5352
useEffect(() {
5453
final current = channel.value;
5554
var active = true;
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import 'dart:convert';
2+
3+
import 'package:buzz/features/agents/agent_avatar_hero.dart';
4+
import 'package:buzz/features/agents/agent_avatar_picker.dart';
5+
import 'package:flutter/foundation.dart';
6+
import 'package:flutter/material.dart';
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
void main() {
10+
testWidgets('return flight shows the retained selection on Cancel and Save', (
11+
tester,
12+
) async {
13+
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
14+
addTearDown(() => debugDefaultTargetPlatformOverride = null);
15+
final original = base64Decode(
16+
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=',
17+
);
18+
final draft = Uint8List.fromList(original);
19+
for (final save in [false, true]) {
20+
final selection = ValueNotifier(AgentAvatarSelection.image(original));
21+
await tester.pumpWidget(
22+
MaterialApp(
23+
home: ValueListenableBuilder<AgentAvatarSelection>(
24+
valueListenable: selection,
25+
builder: (context, value, _) => Scaffold(
26+
body: Column(
27+
children: [
28+
AgentAvatarHero(
29+
tag: 'avatar',
30+
selection: value,
31+
child: const SizedBox.square(dimension: 100),
32+
),
33+
TextButton(
34+
onPressed: () async {
35+
final result = await Navigator.of(context)
36+
.push<AgentAvatarSelection>(
37+
PageRouteBuilder(
38+
transitionDuration: const Duration(
39+
milliseconds: 300,
40+
),
41+
reverseTransitionDuration: const Duration(
42+
milliseconds: 300,
43+
),
44+
pageBuilder: (context, _, _) => Scaffold(
45+
body: Column(
46+
children: [
47+
AgentAvatarHero(
48+
tag: 'avatar',
49+
selection: AgentAvatarSelection.image(
50+
draft,
51+
),
52+
child: const SizedBox.square(
53+
dimension: 200,
54+
),
55+
),
56+
TextButton(
57+
onPressed: () =>
58+
Navigator.of(context).pop(
59+
save
60+
? AgentAvatarSelection.image(
61+
draft,
62+
)
63+
: null,
64+
),
65+
child: const Text('Return'),
66+
),
67+
],
68+
),
69+
),
70+
),
71+
);
72+
if (result != null) selection.value = result;
73+
},
74+
child: const Text('Edit'),
75+
),
76+
],
77+
),
78+
),
79+
),
80+
),
81+
);
82+
await tester.tap(find.text('Edit'));
83+
await tester.pumpAndSettle();
84+
await tester.tap(find.text('Return'));
85+
await tester.pump();
86+
await tester.pump(const Duration(milliseconds: 100));
87+
final image = tester.widget<Image>(find.byType(Image));
88+
expect((image.image as MemoryImage).bytes, same(save ? draft : original));
89+
await tester.pumpAndSettle();
90+
expect(selection.value.bytes, same(save ? draft : original));
91+
await tester.pumpWidget(const SizedBox.shrink());
92+
selection.dispose();
93+
}
94+
debugDefaultTargetPlatformOverride = null;
95+
});
96+
}

‎mobile/test/features/agents/create_agent_page_test.dart‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,8 @@ void main() {
124124
expect(find.text('Instructions'), findsNothing);
125125
await tester.tap(find.byKey(ValueKey('agent-avatar-$targetIndex')));
126126
await tester.pumpAndSettle();
127-
await tester.tap(find.byTooltip('Cancel'));
128-
await tester.pump();
129-
// The source control remains disabled until the reverse Hero finishes.
127+
// This harness disables motion, so the return transition completes
128+
// immediately. Check suppression while editing, then restoration on exit.
130129
final chooseButton = find.widgetWithText(
131130
FilledButton,
132131
'Choose avatar',
@@ -147,6 +146,7 @@ void main() {
147146
tester.widget<FrostedAppBar>(sourceBar).nativeViewSuppressed?.value,
148147
isTrue,
149148
);
149+
await tester.tap(find.byTooltip('Cancel'));
150150
await tester.pumpAndSettle();
151151
expect(tester.widget<FilledButton>(chooseButton).onPressed, isNotNull);
152152
expect(tester.widget<TickerMode>(playback).enabled, isTrue);

‎mobile/test/shared/widgets/preset_agent_avatar_test.dart‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ void main() {
210210
expect(find.byType(AndroidView), findsOneWidget);
211211
// The poster stays until Chromium has actually presented a video frame.
212212
expect(find.byType(AvatarImageContent), findsOneWidget);
213+
// A slow download must still become visible after the old ten-second cap.
214+
for (var i = 0; i < 220; i++) {
215+
await tester.pump(const Duration(milliseconds: 50));
216+
}
213217
frameReady = true;
214218
await tester.pump(const Duration(milliseconds: 50));
215219
await tester.pump();

0 commit comments

Comments
 (0)