From 2128a32f2e9c55317666525d59badeee86c5ea52 Mon Sep 17 00:00:00 2001 From: Nonon Date: Mon, 17 Jan 2022 22:25:50 +0300 Subject: [PATCH] Toggle for drag scroll --- lib/SettingsHandler.dart | 13 ++++++++++++- lib/pages/settings/DebugPage.dart | 9 +++++++++ lib/pages/settings/FilterTagsPage.dart | 2 +- lib/widgets/CommentsDialog.dart | 2 +- lib/widgets/DesktopScrollWrap.dart | 18 +++++++++++++++++- lib/widgets/GridBuilder.dart | 10 ++++------ lib/widgets/HistoryList.dart | 4 +--- lib/widgets/StaggeredBuilder.dart | 6 ++---- lib/widgets/TabBox.dart | 4 +--- lib/widgets/TagView.dart | 2 +- 10 files changed, 49 insertions(+), 21 deletions(-) diff --git a/lib/SettingsHandler.dart b/lib/SettingsHandler.dart index 70a54683..85939283 100644 --- a/lib/SettingsHandler.dart +++ b/lib/SettingsHandler.dart @@ -59,6 +59,7 @@ class SettingsHandler extends GetxController { bool disableImageScaling = false; // disable isolates on debug builds, because they cause lags in emulator bool disableImageIsolates = kDebugMode || false; + bool desktopListsDrag = false; //////////////////////////////////////////////////// @@ -163,7 +164,7 @@ class SettingsHandler extends GetxController { 'drawerMascotPathOverride', 'allowSelfSignedCerts', 'showStatusBar', 'showFPS', 'showPerf', 'showImageStats', 'isDebug', 'showURLOnThumb', 'disableImageIsolates', - 'mergeEnabled' + 'mergeEnabled', 'desktopListsDrag' ]; // default values and possible options map for validation // TODO build settings widgets from this map, need to add Label/Description/other options required for the input element @@ -378,6 +379,10 @@ class SettingsHandler extends GetxController { "type": "bool", "default": false, }, + "desktopListsDrag": { + "type": "bool", + "default": false, + }, // other @@ -825,6 +830,8 @@ class SettingsHandler extends GetxController { return disableImageScaling; case 'disableImageIsolates': return disableImageIsolates; + case 'desktopListsDrag': + return desktopListsDrag; case 'cacheDuration': return cacheDuration; case 'cacheSize': @@ -970,6 +977,9 @@ class SettingsHandler extends GetxController { case 'disableImageIsolates': disableImageIsolates = validatedValue; break; + case 'desktopListsDrag': + desktopListsDrag = validatedValue; + break; case 'cacheDuration': cacheDuration = validatedValue; break; @@ -1055,6 +1065,7 @@ class SettingsHandler extends GetxController { "changePageButtonsPosition": validateValue("changePageButtonsPosition", null, toJSON: true), "disableImageScaling" : validateValue("disableImageScaling", null, toJSON: true), "disableImageIsolates" : validateValue("disableImageIsolates", null, toJSON: true), + "desktopListsDrag" : validateValue("desktopListsDrag", null, toJSON: true), "cacheDuration" : validateValue("cacheDuration", null, toJSON: true), "cacheSize" : validateValue("cacheSize", null, toJSON: true), "allowSelfSignedCerts": validateValue("allowSelfSignedCerts", null, toJSON: true), diff --git a/lib/pages/settings/DebugPage.dart b/lib/pages/settings/DebugPage.dart index 01665412..8b3b0605 100644 --- a/lib/pages/settings/DebugPage.dart +++ b/lib/pages/settings/DebugPage.dart @@ -120,6 +120,15 @@ class _DebugPageState extends State { }, title: 'Enable Self Signed SSL Certificates' ), + SettingsToggle( + value: settingsHandler.desktopListsDrag, + onChanged: (newValue) { + setState(() { + settingsHandler.desktopListsDrag = newValue; + }); + }, + title: "Enable drag scroll on lists [Desktop only]" + ), // SettingsToggle( // value: settingsHandler.isMemeTheme.value, // onChanged: (newValue) { diff --git a/lib/pages/settings/FilterTagsPage.dart b/lib/pages/settings/FilterTagsPage.dart index ac75274c..94223cca 100644 --- a/lib/pages/settings/FilterTagsPage.dart +++ b/lib/pages/settings/FilterTagsPage.dart @@ -161,7 +161,7 @@ class _FiltersEditState extends State with SingleTickerProviderStat shrinkWrap: false, itemCount: tagsList.length, scrollDirection: Axis.vertical, - physics: (Platform.isWindows || Platform.isLinux || Platform.isMacOS) ? const NeverScrollableScrollPhysics() : null, // const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()), + physics: getListPhysics(), // const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()), itemBuilder: (BuildContext context, int index) { String currentEntry = tagsList[index]; Widget entryRow = getEntryRow(tagsList[index], Icon(CupertinoIcons.tag)); diff --git a/lib/widgets/CommentsDialog.dart b/lib/widgets/CommentsDialog.dart index 9a84e701..e0ac0cf5 100644 --- a/lib/widgets/CommentsDialog.dart +++ b/lib/widgets/CommentsDialog.dart @@ -145,7 +145,7 @@ class _CommentsDialogState extends State { child: ListView.builder( padding: EdgeInsets.all(5), controller: scrollController, - physics: (Platform.isWindows || Platform.isLinux || Platform.isMacOS) ? const NeverScrollableScrollPhysics() : null, // const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()), + physics: getListPhysics(), // const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()), itemCount: comments.length, scrollDirection: Axis.vertical, itemBuilder: listEntryBuild, diff --git a/lib/widgets/DesktopScrollWrap.dart b/lib/widgets/DesktopScrollWrap.dart index cdf12740..f1579ccc 100644 --- a/lib/widgets/DesktopScrollWrap.dart +++ b/lib/widgets/DesktopScrollWrap.dart @@ -2,6 +2,20 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter_improved_scrolling/flutter_improved_scrolling.dart'; +import 'package:get/get.dart'; + +import 'package:LoliSnatcher/SettingsHandler.dart'; + +ScrollPhysics? getListPhysics() { + final SettingsHandler settingsHandler = Get.find(); + + bool isDesktopPlatform = Platform.isWindows || Platform.isLinux || Platform.isMacOS; + if (settingsHandler.desktopListsDrag == false && isDesktopPlatform) { + return const NeverScrollableScrollPhysics(); + } else { + return null; + } +} class DesktopScrollWrap extends StatelessWidget { final Widget child; @@ -15,7 +29,9 @@ class DesktopScrollWrap extends StatelessWidget { // on child element wrapped in this // otherwise, it will not affect how scroll works - if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) { + bool isDesktopPlatform = Platform.isWindows || Platform.isLinux || Platform.isMacOS; + + if (isDesktopPlatform) { return ImprovedScrolling( scrollController: controller, // onScroll: (scrollOffset) => debugPrint( diff --git a/lib/widgets/GridBuilder.dart b/lib/widgets/GridBuilder.dart index e785673c..8828a7e9 100644 --- a/lib/widgets/GridBuilder.dart +++ b/lib/widgets/GridBuilder.dart @@ -1,10 +1,10 @@ -import 'dart:io'; +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; import 'package:LoliSnatcher/SearchGlobals.dart'; import 'package:LoliSnatcher/SettingsHandler.dart'; +import 'package:LoliSnatcher/widgets/DesktopScrollWrap.dart'; import 'package:LoliSnatcher/widgets/ThumbCardBuild.dart'; -import 'package:flutter/material.dart'; -import 'package:get/get.dart'; class GridBuilder extends StatelessWidget { final void Function(int) onTap; @@ -23,9 +23,7 @@ class GridBuilder extends StatelessWidget { return GridView.builder( controller: searchHandler.gridScrollController, - physics: (Platform.isWindows || Platform.isLinux || Platform.isMacOS) - ? const NeverScrollableScrollPhysics() - : null, // const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()), + physics: getListPhysics(), // const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()), addAutomaticKeepAlives: false, cacheExtent: 200, shrinkWrap: false, diff --git a/lib/widgets/HistoryList.dart b/lib/widgets/HistoryList.dart index 92a4257d..717f0ff6 100644 --- a/lib/widgets/HistoryList.dart +++ b/lib/widgets/HistoryList.dart @@ -184,9 +184,7 @@ class _HistoryListState extends State { child: ListView.builder( padding: EdgeInsets.fromLTRB(10, 5, 10, 5), controller: scrollController, - physics: (Platform.isWindows || Platform.isLinux || Platform.isMacOS) - ? const NeverScrollableScrollPhysics() - : null, // const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()), + physics: getListPhysics(), // const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()), shrinkWrap: false, itemCount: filteredHistory.length, scrollDirection: Axis.vertical, diff --git a/lib/widgets/StaggeredBuilder.dart b/lib/widgets/StaggeredBuilder.dart index 4df44c05..05150893 100644 --- a/lib/widgets/StaggeredBuilder.dart +++ b/lib/widgets/StaggeredBuilder.dart @@ -1,4 +1,3 @@ -import 'dart:io'; import 'dart:math'; import 'package:flutter/material.dart'; @@ -8,6 +7,7 @@ import 'package:waterfall_flow/waterfall_flow.dart'; import 'package:LoliSnatcher/SearchGlobals.dart'; import 'package:LoliSnatcher/SettingsHandler.dart'; import 'package:LoliSnatcher/widgets/ThumbCardBuild.dart'; +import 'package:LoliSnatcher/widgets/DesktopScrollWrap.dart'; class StaggeredBuilder extends StatelessWidget { final void Function(int) onTap; @@ -29,9 +29,7 @@ class StaggeredBuilder extends StatelessWidget { return Obx(() { return WaterfallFlow.builder( controller: searchHandler.gridScrollController, - physics: (Platform.isWindows || Platform.isLinux || Platform.isMacOS) - ? const NeverScrollableScrollPhysics() - : null, // const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()), + physics: getListPhysics(), // const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()), shrinkWrap: false, addAutomaticKeepAlives: false, cacheExtent: 200, diff --git a/lib/widgets/TabBox.dart b/lib/widgets/TabBox.dart index 94812fd0..28e5443f 100644 --- a/lib/widgets/TabBox.dart +++ b/lib/widgets/TabBox.dart @@ -315,9 +315,7 @@ class _TabsDialogState extends State { child: ListView.builder( padding: EdgeInsets.fromLTRB(10, 5, 10, 5), controller: scrollController, - physics: (Platform.isWindows || Platform.isLinux || Platform.isMacOS) - ? const NeverScrollableScrollPhysics() - : null, // const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()), + physics: getListPhysics(), // const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()), shrinkWrap: false, itemCount: filteredTabs.length, scrollDirection: Axis.vertical, diff --git a/lib/widgets/TagView.dart b/lib/widgets/TagView.dart index d723a566..016b5990 100644 --- a/lib/widgets/TagView.dart +++ b/lib/widgets/TagView.dart @@ -584,7 +584,7 @@ class _TagViewState extends State { controller: scrollController, child: CustomScrollView( controller: scrollController, - physics: (Platform.isWindows || Platform.isLinux || Platform.isMacOS) ? const NeverScrollableScrollPhysics() : null, // const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()), + physics: getListPhysics(), // const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()), slivers: [ infoBuild(), tagsBuild(),