Skip to content

armgit / ente

Public Imported from GitHub
0

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

Refactor FileCaptionWidget to simplify UI and improve text input handling

aman-pilot4360601204a3
diff --git a/mobile/apps/photos/lib/ui/components/info_item_widget.dart b/mobile/apps/photos/lib/ui/components/info_item_widget.dart
deleted file mode 100644
index a821833673..0000000000
--- a/mobile/apps/photos/lib/ui/components/info_item_widget.dart
+++ /dev/null
@@ -1,123 +0,0 @@
-import "package:flutter/material.dart";
-import "package:photos/theme/ente_theme.dart";
-import "package:photos/ui/common/loading_widget.dart";
-import 'package:photos/ui/components/buttons/icon_button_widget.dart';
-
-///https://www.figma.com/file/SYtMyLBs5SAOkTbfMMzhqt/ente-Visual-Design?node-id=8113-59605&t=OMX5f5KdDJYWSQQN-4
-class InfoItemWidget extends StatelessWidget {
- final IconData? leadingIcon;
- final Widget? leadingIconWidget;
- final VoidCallback? editOnTap;
- final String? title;
- final Widget? endSection;
- final Future<List<Widget>> subtitleSection;
- final bool hasChipButtons;
- final bool biggerSpinner;
- final VoidCallback? onTap;
- const InfoItemWidget({
- this.leadingIcon,
- this.leadingIconWidget,
- this.editOnTap,
- this.title,
- this.endSection,
- required this.subtitleSection,
- this.hasChipButtons = false,
- this.biggerSpinner = false,
- this.onTap,
- super.key,
- }) : assert(leadingIcon != null || leadingIconWidget != null);
-
- @override
- Widget build(BuildContext context) {
- final children = <Widget>[];
- if (title != null) {
- children.addAll([
- Text(
- title!,
- style: hasChipButtons
- ? getEnteTextTheme(context).miniMuted
- : getEnteTextTheme(context).small,
- ),
- SizedBox(height: hasChipButtons ? 8 : 4),
- ]);
- }
-
- children.addAll([
- Flexible(
- child: FutureBuilder(
- future: subtitleSection,
- builder: (context, snapshot) {
- Widget child;
- if (snapshot.hasData) {
- final subtitle = snapshot.data as List<Widget>;
- if (subtitle.isNotEmpty) {
- child = Wrap(runSpacing: 8, spacing: 8, children: subtitle);
- } else {
- child = const SizedBox.shrink();
- }
- } else {
- child = EnteLoadingWidget(
- padding: biggerSpinner ? 6 : 3,
- size: biggerSpinner ? 20 : 11,
- color: getEnteColorScheme(context).strokeMuted,
- alignment: biggerSpinner
- ? Alignment.center
- : Alignment.centerLeft,
- );
- }
- return AnimatedSwitcher(
- duration: const Duration(milliseconds: 200),
- switchInCurve: Curves.easeInOutExpo,
- child: child,
- );
- },
- ),
- ),
- ]);
-
- endSection != null ? children.add(endSection!) : null;
-
- return Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Flexible(
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- IconButtonWidget(
- icon: leadingIcon,
- iconWidget: leadingIconWidget,
- iconButtonType: IconButtonType.secondary,
- ),
- Flexible(
- child: Padding(
- padding: const EdgeInsets.fromLTRB(12, 3.5, 16, 3.5),
- child: GestureDetector(
- behavior: HitTestBehavior.translucent,
- onTap: onTap,
- child: SizedBox(
- width: double.infinity,
- child: Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: children,
- ),
- ),
- ),
- ),
- ),
- ],
- ),
- ),
- editOnTap != null
- ? IconButtonWidget(
- icon: Icons.edit,
- iconButtonType: IconButtonType.secondary,
- onTap: editOnTap,
- )
- : const SizedBox.shrink(),
- ],
- );
- }
-}
diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_caption_widget.dart b/mobile/apps/photos/lib/ui/viewer/file/file_caption_widget.dart
index ba60bd7be6..c5bfeb6feb 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/file_caption_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/file_caption_widget.dart
@@ -1,9 +1,9 @@
+import "package:ente_components/ente_components.dart";
import 'package:flutter/material.dart';
import "package:photos/core/event_bus.dart";
import "package:photos/events/file_caption_updated_event.dart";
import "package:photos/generated/l10n.dart";
import 'package:photos/models/file/file.dart';
-import 'package:photos/theme/ente_theme.dart';
import 'package:photos/ui/components/keyboard/keyboard_oveylay.dart';
import 'package:photos/ui/components/keyboard/keyboard_top_button.dart';
import "package:photos/ui/notification/toast.dart";
@@ -16,31 +16,9 @@ class FileCaptionReadyOnly extends StatelessWidget {
@override
Widget build(BuildContext context) {
- final colorScheme = getEnteColorScheme(context);
- final textTheme = getEnteTextTheme(context);
- return Padding(
- padding: const EdgeInsets.all(4.0),
- child: ConstrainedBox(
- constraints: const BoxConstraints(
- minHeight: 32.0,
- minWidth: double.infinity,
- maxHeight: 200.0,
- maxWidth: double.infinity,
- ),
- child: DecoratedBox(
- decoration: BoxDecoration(
- color: colorScheme.fillFaint,
- borderRadius: BorderRadius.circular(4),
- ),
- child: SingleChildScrollView(
- scrollDirection: Axis.vertical,
- child: Padding(
- padding: const EdgeInsets.all(12.0),
- child: Text(caption, style: textTheme.small),
- ),
- ),
- ),
- ),
+ return Text(
+ caption,
+ style: TextStyles.body.copyWith(color: context.componentColors.textLight),
);
}
}
@@ -57,18 +35,12 @@ class FileCaptionWidget extends StatefulWidget {
class _FileCaptionWidgetState extends State<FileCaptionWidget> {
static const int maxLength = 5000;
- // counterThreshold represents the nun of char after which
- // currentLength/maxLength will show up
- static const int counterThreshold = 1000;
- int currentLength = 0;
-
final _textController = TextEditingController();
final _focusNode = FocusNode();
String? editedCaption;
late String defaultHintText = AppLocalizations.of(
context,
).fileInfoAddDescHint;
- String hintText = '';
Widget? keyboardTopButtons;
@override
@@ -77,7 +49,7 @@ class _FileCaptionWidgetState extends State<FileCaptionWidget> {
_focusNode.addListener(_focusNodeListener);
editedCaption = widget.file.caption;
if (editedCaption != null && editedCaption!.isNotEmpty) {
- hintText = editedCaption!;
+ _textController.text = editedCaption!;
}
}
@@ -97,51 +69,18 @@ class _FileCaptionWidgetState extends State<FileCaptionWidget> {
@override
Widget build(BuildContext context) {
- if (hintText.isEmpty) {
- hintText = defaultHintText;
- }
- final colorScheme = getEnteColorScheme(context);
- final textTheme = getEnteTextTheme(context);
- return TextField(
- onSubmitted: (value) async {
- await _onDoneClick(context);
- },
+ return TextInputComponent(
controller: _textController,
focusNode: _focusNode,
- decoration: InputDecoration(
- counterStyle: textTheme.mini.copyWith(color: colorScheme.textMuted),
- counterText: currentLength >= counterThreshold
- ? currentLength.toString() + " / " + maxLength.toString()
- : "",
- contentPadding: const EdgeInsets.all(16),
- border: OutlineInputBorder(
- borderRadius: BorderRadius.circular(2),
- borderSide: const BorderSide(width: 0, style: BorderStyle.none),
- ),
- focusedBorder: OutlineInputBorder(
- borderRadius: BorderRadius.circular(2),
- borderSide: const BorderSide(width: 0, style: BorderStyle.none),
- ),
- filled: true,
- fillColor: colorScheme.fillFaint,
- hintText: hintText,
- hintStyle: hintText == defaultHintText
- ? textTheme.miniMuted
- : textTheme.mini,
- ),
- style: textTheme.mini,
- cursorWidth: 1.5,
+ hintText: defaultHintText,
maxLength: maxLength,
minLines: 1,
maxLines: 10,
textCapitalization: TextCapitalization.sentences,
keyboardType: TextInputType.multiline,
+ onSubmit: (value) => _onDoneClick(context),
onChanged: (value) {
- setState(() {
- hintText = defaultHintText;
- currentLength = value.length;
- editedCaption = value;
- });
+ editedCaption = value;
},
);
}
@@ -173,17 +112,11 @@ class _FileCaptionWidgetState extends State<FileCaptionWidget> {
}
void _focusNodeListener() {
- final caption = widget.file.caption;
- if (_focusNode.hasFocus && caption != null) {
- _textController.text = caption;
- editedCaption = caption;
- }
- final bool hasFocus = _focusNode.hasFocus;
keyboardTopButtons ??= KeyboardTopButton(
onDoneTap: onDoneTap,
onCancelTap: onCancelTap,
);
- if (hasFocus) {
+ if (_focusNode.hasFocus) {
KeyboardOverlay.showOverlay(context, keyboardTopButtons!);
} else {
KeyboardOverlay.removeOverlay();