diff --git a/mobile/lib/features/channels/channels_page/community.dart b/mobile/lib/features/channels/channels_page/community.dart index 08a199035..a4795fd9b 100644 --- a/mobile/lib/features/channels/channels_page/community.dart +++ b/mobile/lib/features/channels/channels_page/community.dart @@ -143,13 +143,29 @@ class _CommunitySwitcherSheet extends HookConsumerWidget { Navigator.of(context).pop(); } }, - onRemove: () => _confirmRemoveCommunity( - context, - ref, - communities[index], - closeSheetAfterRemoval: - communities[index].id == activeId, - ), + onRemove: () { + final community = communities[index]; + final nextCommunity = community.id == activeId + ? communities + .where( + (candidate) => + candidate.id != community.id, + ) + .firstOrNull + : null; + unawaited( + _confirmRemoveCommunity( + context, + ref, + community, + closeSheetAfterRemoval: + community.id == activeId, + nextCommunityId: nextCommunity?.id, + onCommunitySwitchStart: + onCommunitySwitchStart, + ), + ); + }, ), ], if (communities.isNotEmpty) @@ -447,6 +463,8 @@ Future _confirmRemoveCommunity( WidgetRef ref, Community community, { required bool closeSheetAfterRemoval, + required String? nextCommunityId, + ValueChanged? onCommunitySwitchStart, }) async { final confirmed = await showDialog( context: context, @@ -473,6 +491,7 @@ Future _confirmRemoveCommunity( if (confirmed != true || !context.mounted) return; final messenger = ScaffoldMessenger.of(context); + onCommunitySwitchStart?.call(nextCommunityId); try { await ref .read(communityListProvider.notifier) @@ -481,6 +500,7 @@ Future _confirmRemoveCommunity( Navigator.of(context).pop(); } } catch (e) { + onCommunitySwitchStart?.call(null); messenger.showSnackBar( SnackBar(content: Text('Failed to remove community: $e')), ); diff --git a/mobile/lib/shared/widgets/frosted_app_bar.dart b/mobile/lib/shared/widgets/frosted_app_bar.dart index 9cef7ed51..8872f6faf 100644 --- a/mobile/lib/shared/widgets/frosted_app_bar.dart +++ b/mobile/lib/shared/widgets/frosted_app_bar.dart @@ -4,30 +4,12 @@ import 'package:flutter/material.dart'; import 'package:lucide_icons_flutter/lucide_icons.dart'; import '../theme/theme.dart'; +import 'frosted_header_scroll_state.dart'; /// Minimum height of the frosted app bar content area below the safe area. const _kBarContentMinHeight = Grid.xxs + 32 + Grid.xxs; // 48 const _kBottomBorderWidth = 1.0; -/// Shares the scroll elevation state from [FrostedScaffold] with its header. -/// Keeping this separate lets all of the existing page bodies continue to own -/// their scroll views. -class FrostedHeaderScrollState extends InheritedNotifier> { - const FrostedHeaderScrollState({ - required super.notifier, - required super.child, - super.key, - }); - - static bool isScrolledOf(BuildContext context) { - return context - .dependOnInheritedWidgetOfExactType() - ?.notifier - ?.value ?? - false; - } -} - TextStyle _effectiveTitleStyle(BuildContext context, TextStyle? titleStyle) { final baseStyle = context.textTheme.titleMedium ?? diff --git a/mobile/lib/shared/widgets/frosted_header_scroll_state.dart b/mobile/lib/shared/widgets/frosted_header_scroll_state.dart new file mode 100644 index 000000000..6b6ec00e7 --- /dev/null +++ b/mobile/lib/shared/widgets/frosted_header_scroll_state.dart @@ -0,0 +1,20 @@ +import 'package:flutter/material.dart'; + +/// Shares the scroll elevation state from [FrostedScaffold] with its header. +/// Keeping this separate lets all of the existing page bodies continue to own +/// their scroll views. +class FrostedHeaderScrollState extends InheritedNotifier> { + const FrostedHeaderScrollState({ + required super.notifier, + required super.child, + super.key, + }); + + static bool isScrolledOf(BuildContext context) { + return context + .dependOnInheritedWidgetOfExactType() + ?.notifier + ?.value ?? + false; + } +} diff --git a/mobile/lib/shared/widgets/frosted_scaffold.dart b/mobile/lib/shared/widgets/frosted_scaffold.dart index 13256354a..0fd218916 100644 --- a/mobile/lib/shared/widgets/frosted_scaffold.dart +++ b/mobile/lib/shared/widgets/frosted_scaffold.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'frosted_app_bar.dart'; +import 'frosted_header_scroll_state.dart'; /// A convenience [Scaffold] that overlays a [FrostedAppBar] on top of its body. ///