Skip to content

Commit 46e6020

Browse files
authored
fix(mobile): fill and stabilize content-aware loading placeholders (#8083)
Fill mobile loading views across the screen and use known image, video, voice-note, and file shapes in message placeholders. Freeze each loading cycle’s layout so arriving metadata cannot reshuffle the shimmer just before content appears; preserve cached Home and forum content during reconnects. Validation: mobile analysis and full test suite passed (2,752 passed, 4 skipped), plus 3 unconfigured-push tests and file-size checks. Installed and launched the loading changes on Pixel 10 before the latest main merge. Full `just ci` was stopped during desktop checks due to low disk space. --------- Signed-off-by: kenny lopez <[email protected]>
1 parent f0eb557 commit 46e6020

24 files changed

Lines changed: 1683 additions & 546 deletions

‎mobile/lib/features/channels/channel_detail_page.dart‎

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import '../profile/profile_provider.dart';
3434
import '../../shared/profile/user_cache_provider.dart';
3535
import '../../shared/profile/user_profile.dart';
3636
import '../forum/forum_posts_view.dart';
37+
import '../forum/forum_provider.dart';
3738
import 'android_ime_lift.dart';
3839
import 'channel.dart';
3940
import 'channel_actions_sheet.dart';
@@ -64,6 +65,7 @@ import 'message_actions.dart';
6465
import 'message_action_backdrop_state.dart';
6566
import 'message_long_press_region.dart';
6667
import 'message_content.dart';
68+
import 'message_skeleton_body.dart';
6769
import '../../shared/read_state/deferred_read_state_update.dart';
6870
import '../../shared/read_state/read_state_format.dart';
6971
import '../../shared/read_state/read_state_provider.dart';
@@ -595,6 +597,19 @@ class ChannelDetailPage extends HookConsumerWidget {
595597
}
596598
}
597599

600+
final timelineMessages = resolvedChannel.isForum
601+
? <TimelineMessage>[]
602+
: formatTimeline(
603+
messagesState.value ?? const [],
604+
currentPubkey: currentPubkey,
605+
);
606+
final timelineEntries = buildMainTimelineEntries(
607+
timelineMessages,
608+
relaySummaries: ref
609+
.read(channelMessagesProvider(channel.id).notifier)
610+
.threadSummaries,
611+
);
612+
598613
return FrostedScaffold(
599614
resizeToAvoidBottomInset:
600615
!usesFixedAndroidImeViewport || resolvedChannel.isForum,
@@ -662,7 +677,9 @@ class ChannelDetailPage extends HookConsumerWidget {
662677
channel: resolvedChannel,
663678
currentPubkey: currentPubkey,
664679
),
665-
if (showConnectionSkeleton.value)
680+
if (showConnectionSkeleton.value &&
681+
ref.watch(forumPostsProvider(channel.id)).value ==
682+
null)
666683
Positioned(
667684
top:
668685
frostedAppBarHeight(
@@ -673,24 +690,42 @@ class ChannelDetailPage extends HookConsumerWidget {
673690
Grid.xs,
674691
left: Grid.gutter,
675692
right: Grid.gutter,
693+
bottom: 0,
676694
child: _ForumConnectionSkeleton(
677695
status: sessionStatus,
678696
),
679697
),
680698
],
681699
)
682700
: SkeletonReveal(
701+
key: ValueKey('message-loading:${channel.id}'),
683702
loading:
684703
showInitialConnectionSkeleton ||
685704
showConnectionSkeleton.value ||
686705
messagesState.isLoading,
687706
shimmerEnabled:
688707
sessionStatus != SessionStatus.disconnected,
689708
skeleton: _MessageTimelineSkeleton(
709+
messages: timelineEntries
710+
.map((entry) => entry.message)
711+
.toList(),
690712
appBarTitleContentHeight: appBarTitleContentHeight,
691-
status: sessionStatus,
713+
),
714+
loadingSemanticsKey: const Key(
715+
'channel-detail-connection-skeleton',
716+
),
717+
loadingLabel: switch (sessionStatus) {
718+
SessionStatus.connecting => 'Connecting',
719+
SessionStatus.reconnecting => 'Reconnecting',
720+
_ => 'Loading',
721+
},
722+
skeletonPadding: EdgeInsets.only(
723+
bottom: showsComposer ? composerDockHeight.value : 0,
692724
),
693725
content: messagesState.when(
726+
skipLoadingOnReload:
727+
messagesState.hasValue && !messagesState.hasError,
728+
skipLoadingOnRefresh: !messagesState.hasError,
694729
loading: SizedBox.shrink,
695730
error: (e, _) => Padding(
696731
padding: EdgeInsets.only(
@@ -707,22 +742,9 @@ class ChannelDetailPage extends HookConsumerWidget {
707742
),
708743
),
709744
data: (events) {
710-
final messages = formatTimeline(
711-
events,
712-
currentPubkey: currentPubkey,
713-
);
714-
final summaries = ref
715-
.read(
716-
channelMessagesProvider(channel.id).notifier,
717-
)
718-
.threadSummaries;
719-
final entries = buildMainTimelineEntries(
720-
messages,
721-
relaySummaries: summaries,
722-
);
723745
return _MessageList(
724-
entries: entries,
725-
allMessages: messages,
746+
entries: timelineEntries,
747+
allMessages: timelineMessages,
726748
initialMessageId: initialMessageId,
727749
initialThreadRootId: initialThreadRootId,
728750
initialThreadRouteBehavior:

‎mobile/lib/features/channels/channel_detail_page/banners.dart‎

Lines changed: 84 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -55,41 +55,37 @@ class _HeaderEphemeralBadge extends StatelessWidget {
5555
}
5656

5757
class _MessageTimelineSkeleton extends StatelessWidget {
58+
final List<TimelineMessage> messages;
5859
final double appBarTitleContentHeight;
59-
final SessionStatus status;
6060

6161
const _MessageTimelineSkeleton({
62+
required this.messages,
6263
required this.appBarTitleContentHeight,
63-
required this.status,
6464
});
6565

6666
@override
6767
Widget build(BuildContext context) {
68-
final semanticsLabel = switch (status) {
69-
SessionStatus.connecting => 'Connecting',
70-
SessionStatus.reconnecting => 'Reconnecting',
71-
SessionStatus.connected || SessionStatus.disconnected => 'Loading',
72-
};
73-
return Semantics(
74-
key: const Key('channel-detail-connection-skeleton'),
75-
liveRegion: true,
76-
label: semanticsLabel,
77-
child: ExcludeSemantics(
78-
child: ListView.separated(
79-
physics: const NeverScrollableScrollPhysics(),
80-
padding: EdgeInsets.fromLTRB(
81-
Grid.gutter,
82-
frostedAppBarHeight(
83-
context,
84-
titleContentHeight: appBarTitleContentHeight,
85-
) +
86-
Grid.xs,
87-
Grid.gutter,
68+
return ListView.builder(
69+
cacheExtent: 0,
70+
reverse: true,
71+
physics: const NeverScrollableScrollPhysics(),
72+
padding: EdgeInsets.fromLTRB(
73+
Grid.gutter,
74+
frostedAppBarHeight(
75+
context,
76+
titleContentHeight: appBarTitleContentHeight,
77+
) +
8878
Grid.xs,
89-
),
90-
itemCount: 4,
91-
separatorBuilder: (_, _) => const SizedBox(height: Grid.xs),
92-
itemBuilder: (_, index) => _MessageSkeletonRow(index: index),
79+
Grid.gutter,
80+
Grid.xs,
81+
),
82+
itemBuilder: (_, index) => Padding(
83+
padding: const EdgeInsets.only(bottom: Grid.xs),
84+
child: _MessageSkeletonRow(
85+
index: index % 4,
86+
message: index < messages.length
87+
? messages[messages.length - 1 - index]
88+
: null,
9389
),
9490
),
9591
);
@@ -98,8 +94,9 @@ class _MessageTimelineSkeleton extends StatelessWidget {
9894

9995
class _MessageSkeletonRow extends StatelessWidget {
10096
final int index;
97+
final TimelineMessage? message;
10198

102-
const _MessageSkeletonRow({required this.index});
99+
const _MessageSkeletonRow({required this.index, this.message});
103100

104101
@override
105102
Widget build(BuildContext context) {
@@ -133,10 +130,16 @@ class _MessageSkeletonRow extends StatelessWidget {
133130
],
134131
),
135132
const SizedBox(height: Grid.half),
136-
for (final width in lineWidths[index]) ...[
137-
SkeletonBar(width: min(width, availableWidth), height: 16),
138-
const SizedBox(height: Grid.half),
139-
],
133+
if (message != null)
134+
MessageSkeletonBody(
135+
content: message!.content,
136+
tags: message!.tags,
137+
)
138+
else
139+
for (final width in lineWidths[index]) ...[
140+
SkeletonBar(width: min(width, availableWidth), height: 16),
141+
const SizedBox(height: Grid.half),
142+
],
140143
const Row(
141144
children: [
142145
SkeletonBar(width: 32, height: 16),
@@ -173,36 +176,14 @@ class _ForumConnectionSkeleton extends StatelessWidget {
173176
child: ExcludeSemantics(
174177
child: IgnorePointer(
175178
child: ExcludeFocus(
176-
child: DecoratedBox(
177-
decoration: BoxDecoration(
178-
color: context.colors.surface,
179-
borderRadius: BorderRadius.circular(Radii.lg),
180-
border: Border.all(color: context.colors.outlineVariant),
181-
),
182-
child: Padding(
183-
padding: const EdgeInsets.all(Grid.twelve),
184-
child: SkeletonShimmer(
185-
child: const Column(
186-
crossAxisAlignment: CrossAxisAlignment.start,
187-
mainAxisSize: MainAxisSize.min,
188-
children: [
189-
Row(
190-
children: [
191-
SkeletonBar(
192-
width: 28,
193-
height: 28,
194-
borderRadius: BorderRadius.all(
195-
Radius.circular(Radii.full),
196-
),
197-
),
198-
SizedBox(width: Grid.xxs),
199-
SkeletonBar(width: 112, height: 14),
200-
],
201-
),
202-
SizedBox(height: Grid.xxs),
203-
SkeletonBar(width: 240, height: 14),
204-
],
205-
),
179+
child: ListView.builder(
180+
cacheExtent: 0,
181+
padding: EdgeInsets.zero,
182+
physics: const NeverScrollableScrollPhysics(),
183+
itemBuilder: (_, _) => Padding(
184+
padding: const EdgeInsets.only(bottom: Grid.xs),
185+
child: _ForumSkeletonCard(
186+
shimmerEnabled: status != SessionStatus.disconnected,
206187
),
207188
),
208189
),
@@ -212,3 +193,45 @@ class _ForumConnectionSkeleton extends StatelessWidget {
212193
);
213194
}
214195
}
196+
197+
class _ForumSkeletonCard extends StatelessWidget {
198+
final bool shimmerEnabled;
199+
200+
const _ForumSkeletonCard({required this.shimmerEnabled});
201+
202+
@override
203+
Widget build(BuildContext context) {
204+
return DecoratedBox(
205+
decoration: BoxDecoration(
206+
color: context.colors.surface,
207+
borderRadius: BorderRadius.circular(Radii.lg),
208+
border: Border.all(color: context.colors.outlineVariant),
209+
),
210+
child: Padding(
211+
padding: const EdgeInsets.all(Grid.twelve),
212+
child: SkeletonShimmer(
213+
enabled: shimmerEnabled,
214+
child: const Column(
215+
crossAxisAlignment: CrossAxisAlignment.start,
216+
mainAxisSize: MainAxisSize.min,
217+
children: [
218+
Row(
219+
children: [
220+
SkeletonBar(
221+
width: 28,
222+
height: 28,
223+
borderRadius: BorderRadius.all(Radius.circular(Radii.full)),
224+
),
225+
SizedBox(width: Grid.xxs),
226+
SkeletonBar(width: 112, height: 14),
227+
],
228+
),
229+
SizedBox(height: Grid.xxs),
230+
SkeletonBar(width: 240, height: 14),
231+
],
232+
),
233+
),
234+
),
235+
);
236+
}
237+
}

‎mobile/lib/features/channels/channels_page.dart‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -312,24 +312,6 @@ class ChannelsPage extends HookConsumerWidget {
312312
return timer.cancel;
313313
}, [canSurfaceError]);
314314

315-
// Keep cached content steady through brief socket flaps. A sustained
316-
// reconnect swaps to element-shaped skeletons that match desktop.
317-
final showConnectionSkeleton = useState(false);
318-
final isReconnectingWithContent =
319-
channels != null &&
320-
(sessionState.status == SessionStatus.connecting ||
321-
sessionState.status == SessionStatus.reconnecting);
322-
useEffect(() {
323-
if (!isReconnectingWithContent) {
324-
showConnectionSkeleton.value = false;
325-
return null;
326-
}
327-
final timer = Timer(const Duration(seconds: 2), () {
328-
showConnectionSkeleton.value = true;
329-
});
330-
return timer.cancel;
331-
}, [isReconnectingWithContent]);
332-
333315
Rect? measureCommunityAvatar() {
334316
if (defaultTargetPlatform == TargetPlatform.iOS) {
335317
final header = headerKey.currentContext?.findRenderObject();
@@ -538,7 +520,6 @@ class ChannelsPage extends HookConsumerWidget {
538520
channelsAsync: channelsAsync,
539521
showError: showError.value,
540522
sessionStatus: sessionState.status,
541-
showConnectionSkeleton: showConnectionSkeleton.value,
542523
currentPubkey: currentPubkey,
543524
topSectionHeight: topSectionHeight,
544525
usesPinnedGradient: usesPinnedGradient,

‎mobile/lib/features/channels/channels_page/body.dart‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ class _ChannelsBody extends StatelessWidget {
55
final AsyncValue<List<Channel>> channelsAsync;
66
final bool showError;
77
final SessionStatus sessionStatus;
8-
final bool showConnectionSkeleton;
98
final ValueChanged<bool> onReadyChanged;
109
final String? currentPubkey;
1110
final double topSectionHeight;
@@ -19,7 +18,6 @@ class _ChannelsBody extends StatelessWidget {
1918
required this.channelsAsync,
2019
required this.showError,
2120
required this.sessionStatus,
22-
required this.showConnectionSkeleton,
2321
required this.onReadyChanged,
2422
required this.currentPubkey,
2523
required this.topSectionHeight,
@@ -33,8 +31,7 @@ class _ChannelsBody extends StatelessWidget {
3331
Widget build(BuildContext context) {
3432
final barHeight = topSectionHeight;
3533
final loadedChannels = channels;
36-
final loading =
37-
showConnectionSkeleton || (loadedChannels == null && !showError);
34+
final loading = loadedChannels == null && !showError;
3835
final content = showError && channelsAsync.hasError
3936
? Padding(
4037
padding: EdgeInsets.only(top: barHeight),
@@ -80,11 +77,16 @@ class _ChannelsBody extends StatelessWidget {
8077
return SkeletonReveal(
8178
onReadyChanged: onReadyChanged,
8279
loading: loading,
80+
loadingSemanticsKey: const Key('channels-connection-skeleton'),
81+
loadingLabel: switch (sessionStatus) {
82+
SessionStatus.connecting => 'Connecting',
83+
SessionStatus.reconnecting => 'Reconnecting',
84+
_ => 'Loading',
85+
},
8386
shimmerEnabled: sessionStatus != SessionStatus.disconnected,
8487
skeleton: _ChannelsSkeleton(
8588
channels: loadedChannels,
8689
topInset: barHeight,
87-
status: sessionStatus,
8890
),
8991
content: content,
9092
);

0 commit comments

Comments
 (0)