Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Improve cast sheet session handling

Priyanshu Dangaref661fb256f87
diff --git a/mobile/apps/photos/lib/ui/cast/cast.dart b/mobile/apps/photos/lib/ui/cast/cast.dart
index e08d6c59f3..257233264d 100644
--- a/mobile/apps/photos/lib/ui/cast/cast.dart
+++ b/mobile/apps/photos/lib/ui/cast/cast.dart
@@ -1,6 +1,8 @@
import "package:ente_components/ente_components.dart";
import "package:flutter/widgets.dart";
import "package:hugeicons/hugeicons.dart";
+import "package:photos/core/network/network.dart";
+import "package:photos/gateways/cast/cast_gateway.dart";
import "package:photos/generated/l10n.dart";
import "package:photos/models/collection/collection.dart";
import "package:photos/service_locator.dart";
@@ -13,9 +15,15 @@ Future<void> showCastSheet(BuildContext context, Collection collection) async {
final l10n = AppLocalizations.of(context);
final textStyle = getEnteTextTheme(context);
await castService.closeActiveCasts();
+ final gw = CastGateway(NetworkClient.instance.enteDio);
+ final sessions = await gw.getAllCastSessions();
return showBottomSheetComponent(
context: context,
builder: (_) => BottomSheetComponent(
+ isScrollable: sessions.isNotEmpty,
+ initialChildSize: 0.6,
+ snapSizes: const [0.6, 1.0],
+ snap: true,
title: l10n.castAlbum,
actions: [
Text(l10n.pairWithAutoDesc, style: textStyle.smallMuted),
@@ -40,7 +48,11 @@ Future<void> showCastSheet(BuildContext context, Collection collection) async {
await showPairWithCodeSheet(context, collection);
},
),
- const CastSessionsList(showTitle: true, fallback: SizedBox.shrink()),
+ CastSessionsList(
+ showTitle: true,
+ fallback: const SizedBox.shrink(),
+ initialSessions: sessions,
+ ),
],
),
);
diff --git a/mobile/apps/photos/lib/ui/cast/pair_with_code.dart b/mobile/apps/photos/lib/ui/cast/pair_with_code.dart
index ce87b6f4f4..b2ca24abc6 100644
--- a/mobile/apps/photos/lib/ui/cast/pair_with_code.dart
+++ b/mobile/apps/photos/lib/ui/cast/pair_with_code.dart
@@ -84,12 +84,17 @@ class _PairWithCodeSheetState extends State<_PairWithCodeSheet> {
variant: .primary,
onTap: () async {
try {
- if (!await _pairWithCode(
+ final paired = await _pairWithCode(
context,
widget.collection,
_controller.text,
- )) {
+ );
+ if (!paired) {
showToast(context, l10n.deviceNotFound);
+ return;
+ }
+ if (mounted) {
+ await Navigator.maybePop(context);
}
} catch (e, s) {
if (e is CastIPMismatchException) {
diff --git a/mobile/apps/photos/lib/ui/settings/cast/cast_settings_page.dart b/mobile/apps/photos/lib/ui/settings/cast/cast_settings_page.dart
index 099abe790b..9069352740 100644
--- a/mobile/apps/photos/lib/ui/settings/cast/cast_settings_page.dart
+++ b/mobile/apps/photos/lib/ui/settings/cast/cast_settings_page.dart
@@ -6,6 +6,7 @@ import "package:photos/gateways/cast/cast_gateway.dart";
import "package:photos/generated/l10n.dart";
import "package:photos/services/collections_service.dart";
import "package:photos/theme/ente_theme.dart";
+import "package:photos/ui/common/loading_widget.dart";
import "package:photos/ui/settings/components/settings_item.dart";
import "package:photos/ui/settings/components/settings_page_scaffold.dart";
import 'package:timeago/timeago.dart' as timeago;
@@ -44,6 +45,7 @@ class CastSessionsList extends StatefulWidget {
const CastSessionsList({
required this.showTitle,
required this.fallback,
+ this.initialSessions,
super.key,
});
@@ -53,6 +55,8 @@ class CastSessionsList extends StatefulWidget {
/// Widget shown when there are no cast sessions.
final Widget fallback;
+ final List<CastInfo>? initialSessions;
+
@override
State<CastSessionsList> createState() => _CastSessionsListState();
}
@@ -63,20 +67,21 @@ class _CastSessionsListState extends State<CastSessionsList> {
@override
void initState() {
super.initState();
- _sessionsFuture = CastGateway(
- NetworkClient.instance.enteDio,
- ).getAllCastSessions();
+ final gw = CastGateway(NetworkClient.instance.enteDio);
+ _sessionsFuture = widget.initialSessions == null
+ ? gw.getAllCastSessions()
+ : Future.value(widget.initialSessions!);
}
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context);
- final textTheme = getEnteTextTheme(context);
+ final colors = context.componentColors;
return FutureBuilder(
future: _sessionsFuture,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
- return const Center(child: CircularProgressIndicator());
+ return const Center(child: EnteLoadingWidget());
}
if (snapshot.hasError) {
throw snapshot.error!;
@@ -88,17 +93,22 @@ class _CastSessionsListState extends State<CastSessionsList> {
return widget.fallback;
}
return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (widget.showTitle) ...[
- Text(l10n.activeSessions, style: textTheme.h4Bold),
- const SizedBox(height: 16),
+ const SizedBox(height: Spacing.xxl),
+ Text(
+ l10n.activeSessions,
+ style: TextStyles.h2.copyWith(color: colors.textBase),
+ ),
+ const SizedBox(height: Spacing.lg),
],
for (final session in snapshot.data!) ...[
_CastSessionItem(
session: session,
onRevokeSession: _revokeSession,
),
- const SizedBox(height: 16),
+ const SizedBox(height: Spacing.sm),
],
],
);
@@ -158,7 +168,9 @@ class _CastSessionItem extends StatelessWidget {
title: "$title on ${session.deviceName ?? session.deviceIP}",
subtitle: timeago.format(session.lastUsedAt),
icon: HugeIcons.strokeRoundedTvSmart,
+ showChevron: false,
showOnlyLoadingState: true,
+ shouldSurfaceExecutionStates: false,
trailing: IconButtonComponent(
icon: const HugeIcon(
icon: HugeIcons.strokeRoundedCancel01,
@@ -168,6 +180,7 @@ class _CastSessionItem extends StatelessWidget {
onTap: () async {
await onRevokeSession(session);
},
+ shouldSurfaceExecutionStates: false,
shouldShowSuccessConfirmation: false,
),
);
diff --git a/mobile/packages/ente_components/lib/components/bottom_sheet/bottom_sheet_component.dart b/mobile/packages/ente_components/lib/components/bottom_sheet/bottom_sheet_component.dart
index 96018bef17..ed107d58cc 100644
--- a/mobile/packages/ente_components/lib/components/bottom_sheet/bottom_sheet_component.dart
+++ b/mobile/packages/ente_components/lib/components/bottom_sheet/bottom_sheet_component.dart
@@ -66,6 +66,7 @@ class _BottomSheetHeaderComponent extends StatelessWidget {
}
final colors = context.componentColors;
+
return SizedBox(
height: _headerHeight,
child: Row(
@@ -117,6 +118,10 @@ class BottomSheetComponent extends StatelessWidget {
this.actionsTopSpacing,
this.backgroundColor,
this.isKeyboardAware = false,
+ this.isScrollable = false,
+ this.initialChildSize = 0.5,
+ this.snap = false,
+ this.snapSizes,
});
final String? title;
@@ -140,6 +145,16 @@ class BottomSheetComponent extends StatelessWidget {
final double? actionsTopSpacing;
final Color? backgroundColor;
final bool isKeyboardAware;
+ final bool isScrollable;
+
+ /// Initial sheet height fraction when [isScrollable] is true.
+ final double initialChildSize;
+
+ /// Whether the sheet snaps to [snapSizes] when [isScrollable] is true.
+ final bool snap;
+
+ /// Sheet height fractions to snap to when [isScrollable] and [snap] are true.
+ final List<double>? snapSizes;
@override
Widget build(BuildContext context) {
@@ -147,8 +162,10 @@ class BottomSheetComponent extends StatelessWidget {
final bottomInset = isKeyboardAware
? MediaQuery.viewInsetsOf(context).bottom
: 0.0;
+
final usesCenteredLayout =
illustration != null || (message != null && content == null);
+
final effectiveHeader =
header ??
((title != null || showCloseButton || usesCenteredLayout)
@@ -163,6 +180,7 @@ class BottomSheetComponent extends StatelessWidget {
isCentered: usesCenteredLayout,
)
: null);
+
final effectiveContent =
content ??
(message == null
@@ -172,15 +190,54 @@ class BottomSheetComponent extends StatelessWidget {
textAlign: usesCenteredLayout ? TextAlign.center : textAlign,
style: TextStyles.body.copyWith(color: colors.textLight),
));
+
final effectiveCrossAxisAlignment = usesCenteredLayout
? CrossAxisAlignment.stretch
: crossAxisAlignment;
+
final effectiveContentSpacing = usesCenteredLayout
? Spacing.lg
: contentSpacing;
+
final effectiveActionsTopSpacing =
actionsTopSpacing ?? (usesCenteredLayout ? Spacing.xxl : Spacing.lg);
+ final children = <Widget>[
+ ?effectiveHeader,
+ if (effectiveContent != null) ...[
+ if (effectiveHeader != null) SizedBox(height: effectiveContentSpacing),
+ effectiveContent,
+ ],
+ if (actions.isNotEmpty) ...[
+ SizedBox(height: effectiveActionsTopSpacing),
+ _BottomSheetActions(actions: actions),
+ ],
+ ];
+
+ final sheetBody = isScrollable
+ ? DraggableScrollableSheet(
+ expand: false,
+ initialChildSize: initialChildSize,
+ snap: snap,
+ snapSizes: snapSizes,
+ builder: (context, scrollController) {
+ return ListView(
+ controller: scrollController,
+ padding: padding,
+ shrinkWrap: true,
+ children: children,
+ );
+ },
+ )
+ : Padding(
+ padding: padding,
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: effectiveCrossAxisAlignment,
+ children: children,
+ ),
+ );
+
return AnimatedPadding(
duration: const Duration(milliseconds: 200),
curve: Curves.easeOutCubic,
@@ -194,28 +251,7 @@ class BottomSheetComponent extends StatelessWidget {
topRight: Radius.circular(Radii.bottomSheet),
),
),
- child: SafeArea(
- top: false,
- child: Padding(
- padding: padding,
- child: Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: effectiveCrossAxisAlignment,
- children: [
- ?effectiveHeader,
- if (effectiveContent != null) ...[
- if (effectiveHeader != null)
- SizedBox(height: effectiveContentSpacing),
- effectiveContent,
- ],
- if (actions.isNotEmpty) ...[
- SizedBox(height: effectiveActionsTopSpacing),
- _BottomSheetActions(actions: actions),
- ],
- ],
- ),
- ),
- ),
+ child: SafeArea(top: false, child: sheetBody),
),
);
}
@@ -232,6 +268,7 @@ Future<T?> showBottomSheetComponent<T>({
Color? barrierColor,
}) {
final colors = context.componentColors;
+
return showModalBottomSheet<T>(
context: context,
useRootNavigator: useRootNavigator,
@@ -240,6 +277,7 @@ Future<T?> showBottomSheetComponent<T>({
enableDrag: enableDrag,
backgroundColor: Colors.transparent,
barrierColor: barrierColor ?? colors.specialScrim.withValues(alpha: 0.55),
+ useSafeArea: true,
builder: (context) {
return PopScope(canPop: isDismissible, child: builder(context));
},
diff --git a/mobile/packages/ente_components/test/components/bottom_sheet_component_test.dart b/mobile/packages/ente_components/test/components/bottom_sheet_component_test.dart
index 9aee2a57cd..51d41f88fb 100644
--- a/mobile/packages/ente_components/test/components/bottom_sheet_component_test.dart
+++ b/mobile/packages/ente_components/test/components/bottom_sheet_component_test.dart
@@ -287,6 +287,40 @@ void main() {
);
expect(animatedPadding.padding, const EdgeInsets.only(bottom: 120));
});
+
+ testWidgets('BottomSheetComponent passes initial scrollable size', (
+ tester,
+ ) async {
+ await tester.pumpWidget(
+ _wrap(
+ const BottomSheetComponent(
+ content: SizedBox(key: ValueKey('scrollable-content')),
+ isScrollable: true,
+ initialChildSize: 0.7,
+ ),
+ ),
+ );
+ final sheet = tester.widget<DraggableScrollableSheet>(
+ find.byType(DraggableScrollableSheet),
+ );
+ expect(sheet.initialChildSize, 0.7);
+ });
+
+ testWidgets('BottomSheetComponent keeps default layout non-scrollable', (
+ tester,
+ ) async {
+ await tester.pumpWidget(
+ _wrap(
+ const BottomSheetComponent(
+ content: SizedBox(key: ValueKey('plain-content')),
+ initialChildSize: 0.7,
+ ),
+ ),
+ );
+ expect(find.byType(DraggableScrollableSheet), findsNothing);
+ expect(find.byType(Padding), findsWidgets);
+ expect(find.byKey(const ValueKey('plain-content')), findsOneWidget);
+ });
}
Widget _wrap(Widget child) {