Skip to content

Commit

Permalink
Merge pull request #90 from NANI-SORE/master
Browse files Browse the repository at this point in the history
Toggle for drag scroll
  • Loading branch information
NO-ob authored Jan 17, 2022
2 parents 9b62ce1 + 2128a32 commit 664a527
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 21 deletions.
13 changes: 12 additions & 1 deletion lib/SettingsHandler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

////////////////////////////////////////////////////
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -378,6 +379,10 @@ class SettingsHandler extends GetxController {
"type": "bool",
"default": false,
},
"desktopListsDrag": {
"type": "bool",
"default": false,
},


// other
Expand Down Expand Up @@ -825,6 +830,8 @@ class SettingsHandler extends GetxController {
return disableImageScaling;
case 'disableImageIsolates':
return disableImageIsolates;
case 'desktopListsDrag':
return desktopListsDrag;
case 'cacheDuration':
return cacheDuration;
case 'cacheSize':
Expand Down Expand Up @@ -970,6 +977,9 @@ class SettingsHandler extends GetxController {
case 'disableImageIsolates':
disableImageIsolates = validatedValue;
break;
case 'desktopListsDrag':
desktopListsDrag = validatedValue;
break;
case 'cacheDuration':
cacheDuration = validatedValue;
break;
Expand Down Expand Up @@ -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),
Expand Down
9 changes: 9 additions & 0 deletions lib/pages/settings/DebugPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ class _DebugPageState extends State<DebugPage> {
},
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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/settings/FilterTagsPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class _FiltersEditState extends State<FiltersEdit> 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));
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/CommentsDialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class _CommentsDialogState extends State<CommentsDialog> {
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,
Expand Down
18 changes: 17 additions & 1 deletion lib/widgets/DesktopScrollWrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<SettingsHandler>();

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;
Expand All @@ -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(
Expand Down
10 changes: 4 additions & 6 deletions lib/widgets/GridBuilder.dart
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions lib/widgets/HistoryList.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,7 @@ class _HistoryListState extends State<HistoryList> {
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,
Expand Down
6 changes: 2 additions & 4 deletions lib/widgets/StaggeredBuilder.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'dart:io';
import 'dart:math';

import 'package:flutter/material.dart';
Expand All @@ -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;
Expand All @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions lib/widgets/TabBox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,7 @@ class _TabsDialogState extends State<TabsDialog> {
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,
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/TagView.dart
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ class _TagViewState extends State<TagView> {
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(),
Expand Down

0 comments on commit 664a527

Please sign in to comment.