[mob][photos] Improve swipe to select accuracy

This commit is contained in:
ashilkn
2024-06-29 16:45:47 +05:30
parent a58e9030a0
commit e0b2fa5a1b
6 changed files with 65 additions and 41 deletions

View File

@@ -48,7 +48,6 @@ import 'package:photos/services/trash_sync_service.dart';
import 'package:photos/services/update_service.dart';
import 'package:photos/services/user_remote_flag_service.dart';
import 'package:photos/services/user_service.dart';
import "package:photos/states/pointer_position_provider.dart";
import 'package:photos/ui/tools/app_lock.dart';
import 'package:photos/ui/tools/lock_screen.dart';
import 'package:photos/utils/crypto_util.dart';
@@ -93,13 +92,11 @@ Future<void> _runInForeground(AdaptiveThemeMode? savedThemeMode) async {
runApp(
AppLock(
builder: (args) => PointerPositionProvider(
child: EnteApp(
_runBackgroundTask,
_killBGTask,
locale,
savedThemeMode,
),
builder: (args) => EnteApp(
_runBackgroundTask,
_killBGTask,
locale,
savedThemeMode,
),
lockScreen: const LockScreen(),
enabled: Configuration.instance.shouldShowLockScreen(),

View File

@@ -13,6 +13,7 @@ import "package:photos/states/pointer_position_provider.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/viewer/file/detail_page.dart";
import "package:photos/ui/viewer/file/thumbnail_widget.dart";
import "package:photos/ui/viewer/gallery/component/group/lazy_group_gallery.dart";
import "package:photos/ui/viewer/gallery/gallery.dart";
import "package:photos/ui/viewer/gallery/state/gallery_context_state.dart";
import "package:photos/utils/file_util.dart";
@@ -57,11 +58,17 @@ class _GalleryFileWidgetState extends State<GalleryFileWidget> {
if (mounted) {
Future.delayed(const Duration(seconds: 1), () {
try {
final scrollController =
GalleryContextState.of(context)!.scrollController;
final RenderBox renderBox =
_globalKey.currentContext?.findRenderObject() as RenderBox;
final position = renderBox.localToGlobal(Offset.zero);
final groupGalleryGlobalKey =
GroupGalleryGlobalKey.of(context).globalKey;
final RenderBox groupGalleryRenderBox =
groupGalleryGlobalKey.currentContext?.findRenderObject()
as RenderBox;
final position = renderBox.localToGlobal(
Offset.zero,
ancestor: groupGalleryRenderBox,
);
final size = renderBox.size;
final bbox = Rect.fromLTWH(
position.dx,
@@ -76,14 +83,7 @@ class _GalleryFileWidgetState extends State<GalleryFileWidget> {
if (widget.selectedFiles?.files.isEmpty ?? true) return;
_insideBboxPrevValue = _insideBbox;
final bboxAccountingToScrollPos = Rect.fromLTWH(
bbox.left,
bbox.top - scrollController.offset,
bbox.width,
bbox.height,
);
if (bboxAccountingToScrollPos.contains(event)) {
if (bbox.contains(event)) {
_insideBbox = true;
} else {
_insideBbox = false;

View File

@@ -4,7 +4,6 @@ import 'package:photos/models/file/file.dart';
import "package:photos/models/selected_files.dart";
import "package:photos/ui/viewer/gallery/component/gallery_file_widget.dart";
import "package:photos/ui/viewer/gallery/gallery.dart";
import "package:photos/ui/viewer/gallery/state/gallery_context_state.dart";
class GalleryGridViewWidget extends StatelessWidget {
final List<EnteFile> filesInGroup;
@@ -30,7 +29,6 @@ class GalleryGridViewWidget extends StatelessWidget {
return GridView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
controller: GalleryContextState.of(context)!.scrollController,
// to disable GridView's scrolling
itemBuilder: (context, index) {
return GalleryFileWidget(

View File

@@ -7,6 +7,7 @@ import 'package:photos/core/constants.dart';
import 'package:photos/events/files_updated_event.dart';
import 'package:photos/models/file/file.dart';
import 'package:photos/models/selected_files.dart';
import "package:photos/states/pointer_position_provider.dart";
import 'package:photos/theme/ente_theme.dart';
import "package:photos/ui/viewer/gallery/component/grid/place_holder_grid_view_widget.dart";
import "package:photos/ui/viewer/gallery/component/group/group_gallery.dart";
@@ -61,6 +62,7 @@ class _LazyGroupGalleryState extends State<LazyGroupGallery> {
late StreamSubscription<FilesUpdatedEvent>? _reloadEventSubscription;
late StreamSubscription<int> _currentIndexSubscription;
bool? _shouldRender;
final _groupGalleryGlobalKey = GlobalKey();
@override
void initState() {
@@ -233,21 +235,29 @@ class _LazyGroupGalleryState extends State<LazyGroupGallery> {
),
],
),
_shouldRender!
? GroupGallery(
photoGridSize: widget.photoGridSize,
files: _filesInGroup,
tag: widget.tag,
asyncLoader: widget.asyncLoader,
selectedFiles: widget.selectedFiles,
limitSelectionToOne: widget.limitSelectionToOne,
)
// todo: perf eval should we have separate PlaceHolder for Groups
// instead of creating a large cached view
: PlaceHolderGridViewWidget(
_filesInGroup.length,
widget.photoGridSize,
),
PointerPositionProvider(
child: GroupGalleryGlobalKey(
globalKey: _groupGalleryGlobalKey,
child: SizedBox(
key: _groupGalleryGlobalKey,
child: _shouldRender!
? GroupGallery(
photoGridSize: widget.photoGridSize,
files: _filesInGroup,
tag: widget.tag,
asyncLoader: widget.asyncLoader,
selectedFiles: widget.selectedFiles,
limitSelectionToOne: widget.limitSelectionToOne,
)
// todo: perf eval should we have separate PlaceHolder for Groups
// instead of creating a large cached view
: PlaceHolderGridViewWidget(
_filesInGroup.length,
widget.photoGridSize,
),
),
),
),
],
);
}
@@ -265,3 +275,27 @@ class _LazyGroupGalleryState extends State<LazyGroupGallery> {
}
}
}
class GroupGalleryGlobalKey extends InheritedWidget {
const GroupGalleryGlobalKey({
super.key,
required this.globalKey,
required super.child,
});
final GlobalKey globalKey;
static GroupGalleryGlobalKey? maybeOf(BuildContext context) {
return context.dependOnInheritedWidgetOfExactType<GroupGalleryGlobalKey>();
}
static GroupGalleryGlobalKey of(BuildContext context) {
final GroupGalleryGlobalKey? result = maybeOf(context);
assert(result != null, 'No GroupGalleryGlobalKey found in context');
return result!;
}
@override
bool updateShouldNotify(GroupGalleryGlobalKey oldWidget) =>
globalKey != oldWidget.globalKey;
}

View File

@@ -108,7 +108,6 @@ class GalleryState extends State<Gallery> {
final _forceReloadEventSubscriptions = <StreamSubscription<Event>>[];
late String _logTag;
bool _sortOrderAsc = false;
final _scrollController = ScrollController();
List<EnteFile> _allFiles = [];
@override
@@ -245,7 +244,6 @@ class GalleryState extends State<Gallery> {
subscription.cancel();
}
_debouncer.cancelDebounce();
_scrollController.dispose();
super.dispose();
}
@@ -260,7 +258,6 @@ class GalleryState extends State<Gallery> {
sortOrderAsc: _sortOrderAsc,
inSelectionMode: widget.inSelectionMode,
type: widget.groupType,
scrollController: _scrollController,
child: MultipleGroupsGalleryView(
itemScroller: _itemScroller,
groupedFiles: currentGroupedFiles,

View File

@@ -6,13 +6,11 @@ class GalleryContextState extends InheritedWidget {
final bool sortOrderAsc;
final bool inSelectionMode;
final GroupType type;
final ScrollController scrollController;
const GalleryContextState({
this.inSelectionMode = false,
this.type = GroupType.day,
required this.sortOrderAsc,
required this.scrollController,
required Widget child,
Key? key,
}) : super(key: key, child: child);