Skip to content

Commit

Permalink
Setting to enable/disable full screen navigation swipe gesture (thund…
Browse files Browse the repository at this point in the history
…er-app#831)

* added setting to enable/disable full screen swipe navigation when LTR gestures are turned off

* updated changelog

* added check to new navigate post logic
  • Loading branch information
hjiangsu authored Oct 17, 2023
1 parent ec332ed commit ae47473
Show file tree
Hide file tree
Showing 18 changed files with 74 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Open links to posts in the app instead of browser - contribution from @micahmo
- Added support for lemmy 0.19.x authentication - contribution from @micahmo
- Added support for accessibility profiles in settings - contribution from @micahmo
- Added option to enable/disable full screen navigation swipe gesture to go back (applies when LTR gestures are disabled)

### Changed
- Collapsed comments are easier to expand - contribution from @micahmo
Expand Down
1 change: 1 addition & 0 deletions lib/account/widgets/profile_modal_body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class _ProfileModalBodyState extends State<ProfileModalBody> {
break;
}
return SwipeablePageRoute<dynamic>(
canOnlySwipeFromEdge: !context.read<ThunderBloc>().state.enableFullScreenSwipeNavigationGesture,
builder: (context) {
return page;
},
Expand Down
2 changes: 2 additions & 0 deletions lib/core/enums/local_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ enum LocalSettings {
commentGestureRightPrimary(name: 'setting_gesture_comment_right_primary_gesture', label: 'Right Short Swipe'),
commentGestureRightSecondary(name: 'setting_gesture_comment_right_secondary_gesture', label: 'Right Long Swipe'),

enableFullScreenSwipeNavigationGesture(name: 'setting_gesture_enable_fullscreen_navigation_gesture', label: 'Enable Fullscreen Swipe Navigation'),

/// -------------------------- FAB Related Settings --------------------------
enableFeedsFab(name: 'setting_enable_feed_fab', label: 'Enable Floating Button on Feeds'),
enablePostsFab(name: 'setting_enable_post_fab', label: 'Enable Floating Button on Posts'),
Expand Down
2 changes: 1 addition & 1 deletion lib/feed/utils/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Future<void> navigateToFeedPage(BuildContext context, {required FeedType feedTyp
SwipeablePageRoute(
transitionDuration: reduceAnimations ? const Duration(milliseconds: 100) : null,
backGestureDetectionWidth: 45,
canOnlySwipeFromEdge: disableFullPageSwipe(isUserLoggedIn: authBloc.state.isLoggedIn, state: thunderBloc.state, isFeedPage: true),
canOnlySwipeFromEdge: disableFullPageSwipe(isUserLoggedIn: authBloc.state.isLoggedIn, state: thunderBloc.state, isFeedPage: true) || !thunderState.enableFullScreenSwipeNavigationGesture,
builder: (context) => MultiBlocProvider(
providers: [
BlocProvider.value(value: accountBloc),
Expand Down
2 changes: 1 addition & 1 deletion lib/inbox/widgets/inbox_mentions_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class InboxMentionsView extends StatelessWidget {
transitionDuration: reduceAnimations ? const Duration(milliseconds: 100) : null,
backGestureDetectionStartOffset: Platform.isAndroid ? 45 : 0,
backGestureDetectionWidth: 45,
canOnlySwipeFromEdge: disableFullPageSwipe(isUserLoggedIn: authBloc.state.isLoggedIn, state: thunderBloc.state, isPostPage: true),
canOnlySwipeFromEdge: disableFullPageSwipe(isUserLoggedIn: authBloc.state.isLoggedIn, state: thunderBloc.state, isPostPage: true) || !state.enableFullScreenSwipeNavigationGesture,
builder: (context) => MultiBlocProvider(
providers: [
BlocProvider.value(value: accountBloc),
Expand Down
10 changes: 8 additions & 2 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
"noCommunityBlocks": "It looks like you have not blocked any communities.",
"blockUser": "Block User",
"username": "Username",
"cancel": "Cancel",
"ok": "OK",
"unableToFindUser": "Unable to find user",
"unableToFindCommunity": "Unable to find community",
"blockCommunity": "Block Community",
"community": "Community",
"cantBlockYourself": "You may not block yourself.",
"add": "Add",
"remove": "Remove",
"somethingWentWrong": "Oops, something went wrong!",
"unableToLoadPostsFrominstance": "Unable to load posts from {instance}",
Expand Down Expand Up @@ -196,6 +194,14 @@
"readAll":"Read All",
"emptyInbox":"Empty Inbox",
"showAll":"Show All",
"gestures": "Gestures",
"navigation": "Navigation",
"sidebar": "Sidebar",
"fullScreenNavigationSwipeDescription": "Swipe anywhere to go back when left-to-right gestures are disabled",
"sidebarBottomNavSwipeDescription": "Swipe bottom nav to open sidebar",
"sidebarBottomNavDoubleTapDescription": "Double-tap bottom nav to open sidebar",
"commentSwipeGesturesHint": "Looking to use buttons instead? Enable them in the comments section in general settings.",
"postSwipeGesturesHint": "Looking to use buttons instead? Change what buttons appear on post cards in general settings.",
"loginToSeeInbox":"Log in to see your inbox"

}
2 changes: 0 additions & 2 deletions lib/l10n/app_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
"noCommunityBlocks": "It looks like you have not blocked any communities.",
"blockUser": "Block User",
"username": "Username",
"cancel": "Cancel",
"ok": "OK",
"unableToFindUser": "Unable to find user",
"unableToFindCommunity": "Unable to find community",
"blockCommunity": "Block Community",
"community": "Community",
"cantBlockYourself": "You may not block yourself.",
"add": "Add",
"remove": "Remove",
"somethingWentWrong": "Oops, something went wrong!",
"unableToLoadPostsFrominstance": "Unable to load posts from {instance}",
Expand Down
2 changes: 0 additions & 2 deletions lib/l10n/app_fi.arb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
"noCommunityBlocks": "It looks like you have not blocked any communities.",
"blockUser": "Block User",
"username": "Username",
"cancel": "Cancel",
"ok": "OK",
"unableToFindUser": "Unable to find user",
"unableToFindCommunity": "Unable to find community",
"blockCommunity": "Block Community",
"community": "Community",
"cantBlockYourself": "You may not block yourself.",
"add": "Add",
"remove": "Remove",
"somethingWentWrong": "Oops, something went wrong!",
"unableToLoadPostsFrominstance": "Unable to load posts from {instance}",
Expand Down
4 changes: 1 addition & 3 deletions lib/l10n/app_pl.arb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
"noCommunityBlocks": "It looks like you have not blocked any communities.",
"blockUser": "Block User",
"username": "Username",
"cancel": "Cancel",
"ok": "OK",
"unableToFindUser": "Unable to find user",
"unableToFindCommunity": "Unable to find community",
"blockCommunity": "Block Community",
"community": "Community",
"cantBlockYourself": "You may not block yourself.",
"add": "Add",
"remove": "Remove",
"somethingWentWrong": "Oops, something went wrong!",
"unableToLoadPostsFrominstance": "Unable to load posts from {instance}",
Expand Down Expand Up @@ -136,7 +134,7 @@
"downloadingMedia": "Pobieranie multimediów do udostępnienia...",
"errorDownloadingMedia": "Wystąpił błąd podczas pobierania pliku multimedialnego do udostępnienia: {errorMessage}",
"copiedToClipboard": "Skopiowano do schowka",
"reducesAnimations": "Reduces the animations used within Thunder",
"reducesAnimations": "Reduces the animations used within Thunder",
"accessibilityProfilesDescription": "Accessibility Profiles allow you to apply several settings at once with the goal of accommodating a particular accessibility requirement.",
"screenReaderProfile": "Screen Reader Profile",
"screenReaderProfileDescription": "Optimizes Thunder for Screen Readers by reducing overall elements and removing potentially conflicting gestures.",
Expand Down
2 changes: 0 additions & 2 deletions lib/l10n/app_sv.arb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
"noCommunityBlocks": "It looks like you have not blocked any communities.",
"blockUser": "Block User",
"username": "Username",
"cancel": "Cancel",
"ok": "OK",
"unableToFindUser": "Unable to find user",
"unableToFindCommunity": "Unable to find community",
"blockCommunity": "Block Community",
"community": "Community",
"cantBlockYourself": "You may not block yourself.",
"add": "Add",
"remove": "Remove",
"somethingWentWrong": "Oops, something went wrong!",
"unableToLoadPostsFrominstance": "Unable to load posts from {instance}",
Expand Down
54 changes: 42 additions & 12 deletions lib/settings/pages/gesture_settings_page.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import 'package:flutter/material.dart';

import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flex_color_scheme/flex_color_scheme.dart';
import 'package:thunder/core/enums/local_settings.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

import 'package:thunder/core/enums/local_settings.dart';
import 'package:thunder/core/enums/swipe_action.dart';
import 'package:thunder/core/singletons/preferences.dart';
import 'package:thunder/settings/widgets/list_option.dart';
import 'package:thunder/settings/widgets/swipe_picker.dart';
import 'package:thunder/settings/widgets/toggle_option.dart';
import 'package:thunder/thunder/bloc/thunder_bloc.dart';
import 'package:thunder/utils/bottom_sheet_list_picker.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

class GestureSettingsPage extends StatefulWidget {
const GestureSettingsPage({super.key});
Expand Down Expand Up @@ -40,6 +38,8 @@ class _GestureSettingsPageState extends State<GestureSettingsPage> with TickerPr
SwipeAction rightPrimaryCommentGesture = SwipeAction.reply;
SwipeAction rightSecondaryCommentGesture = SwipeAction.save;

bool enableFullScreenSwipeNavigationGesture = true;

/// Loading
bool isLoading = true;

Expand Down Expand Up @@ -118,6 +118,9 @@ class _GestureSettingsPageState extends State<GestureSettingsPage> with TickerPr
await prefs.setString(LocalSettings.commentGestureRightSecondary.name, (value as SwipeAction).name);
setState(() => rightSecondaryCommentGesture = value);
break;
case LocalSettings.enableFullScreenSwipeNavigationGesture:
await prefs.setBool(LocalSettings.enableFullScreenSwipeNavigationGesture.name, value);
setState(() => enableFullScreenSwipeNavigationGesture = value);
}

if (context.mounted) {
Expand Down Expand Up @@ -148,6 +151,8 @@ class _GestureSettingsPageState extends State<GestureSettingsPage> with TickerPr
rightPrimaryCommentGesture = SwipeAction.values.byName(prefs.getString(LocalSettings.commentGestureRightPrimary.name) ?? SwipeAction.reply.name);
rightSecondaryCommentGesture = SwipeAction.values.byName(prefs.getString(LocalSettings.commentGestureRightSecondary.name) ?? SwipeAction.save.name);

enableFullScreenSwipeNavigationGesture = prefs.getBool(LocalSettings.enableFullScreenSwipeNavigationGesture.name) ?? true;

isLoading = false;
});
}
Expand Down Expand Up @@ -175,9 +180,10 @@ class _GestureSettingsPageState extends State<GestureSettingsPage> with TickerPr
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
final l10n = AppLocalizations.of(context)!;

return Scaffold(
appBar: AppBar(title: const Text('Gestures'), centerTitle: false),
appBar: AppBar(title: Text(l10n.gestures), centerTitle: false),
body: isLoading
? const Center(child: CircularProgressIndicator())
: SingleChildScrollView(
Expand All @@ -192,21 +198,45 @@ class _GestureSettingsPageState extends State<GestureSettingsPage> with TickerPr
Padding(
padding: const EdgeInsets.only(left: 4.0, bottom: 8.0),
child: Text(
'Sidebar',
l10n.navigation,
style: theme.textTheme.titleLarge,
),
),
ToggleOption(
description: LocalSettings.enableFullScreenSwipeNavigationGesture.label,
subtitle: l10n.fullScreenNavigationSwipeDescription,
value: enableFullScreenSwipeNavigationGesture,
iconEnabled: Icons.swipe_left_rounded,
iconDisabled: Icons.swipe_left_outlined,
onToggle: (bool value) => setPreferences(LocalSettings.enableFullScreenSwipeNavigationGesture, value),
),
],
),
),
Container(
padding: const EdgeInsets.fromLTRB(12.0, 8.0, 16.0, 8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(left: 4.0, bottom: 8.0),
child: Text(
l10n.sidebar,
style: theme.textTheme.titleLarge,
),
),
ToggleOption(
description: LocalSettings.sidebarBottomNavBarSwipeGesture.label,
subtitle: 'Swipe bottom nav to open sidebar',
subtitle: l10n.sidebarBottomNavSwipeDescription,
value: bottomNavBarSwipeGestures,
iconEnabled: Icons.swipe_right_rounded,
iconDisabled: Icons.swipe_right_outlined,
onToggle: (bool value) => setPreferences(LocalSettings.sidebarBottomNavBarSwipeGesture, value),
),
ToggleOption(
description: LocalSettings.sidebarBottomNavBarDoubleTapGesture.label,
subtitle: 'Double-tap bottom nav to open sidebar',
subtitle: l10n.sidebarBottomNavDoubleTapDescription,
value: bottomNavBarDoubleTapGestures,
iconEnabled: Icons.touch_app_rounded,
iconDisabled: Icons.touch_app_outlined,
Expand All @@ -224,14 +254,14 @@ class _GestureSettingsPageState extends State<GestureSettingsPage> with TickerPr
Padding(
padding: const EdgeInsets.only(left: 4.0, bottom: 8.0),
child: Text(
'Posts',
l10n.posts,
style: theme.textTheme.titleLarge,
),
),
Padding(
padding: const EdgeInsets.all(6.0),
child: Text(
'Looking to use buttons instead? Change what buttons appear on post cards in general settings.',
l10n.postSwipeGesturesHint,
style: TextStyle(
color: theme.colorScheme.onBackground.withOpacity(0.75),
),
Expand Down Expand Up @@ -322,14 +352,14 @@ class _GestureSettingsPageState extends State<GestureSettingsPage> with TickerPr
Padding(
padding: const EdgeInsets.only(left: 4.0, bottom: 8.0),
child: Text(
'Comments',
l10n.comments,
style: theme.textTheme.titleLarge,
),
),
Padding(
padding: const EdgeInsets.all(6.0),
child: Text(
'Looking to use buttons instead? Enable them in the comments section in general settings.',
l10n.commentSwipeGesturesHint,
style: TextStyle(
color: theme.colorScheme.onBackground.withOpacity(0.75),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/shared/comment_reference.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class _CommentReferenceState extends State<CommentReference> {
SwipeablePageRoute(
transitionDuration: reduceAnimations ? const Duration(milliseconds: 100) : null,
backGestureDetectionWidth: 45,
canOnlySwipeFromEdge: disableFullPageSwipe(isUserLoggedIn: authBloc.state.isLoggedIn, state: thunderBloc.state, isPostPage: true),
canOnlySwipeFromEdge: disableFullPageSwipe(isUserLoggedIn: authBloc.state.isLoggedIn, state: thunderBloc.state, isPostPage: true) || !state.enableFullScreenSwipeNavigationGesture,
builder: (context) => MultiBlocProvider(
providers: [
BlocProvider.value(value: accountBloc),
Expand Down
4 changes: 4 additions & 0 deletions lib/thunder/bloc/thunder_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ class ThunderBloc extends Bloc<ThunderEvent, ThunderState> {
SwipeAction rightPrimaryCommentGesture = SwipeAction.values.byName(prefs.getString(LocalSettings.commentGestureRightPrimary.name) ?? SwipeAction.reply.name);
SwipeAction rightSecondaryCommentGesture = SwipeAction.values.byName(prefs.getString(LocalSettings.commentGestureRightSecondary.name) ?? SwipeAction.save.name);

bool enableFullScreenSwipeNavigationGesture = prefs.getBool(LocalSettings.enableFullScreenSwipeNavigationGesture.name) ?? true;

/// -------------------------- FAB Related Settings --------------------------
bool enableFeedsFab = prefs.getBool(LocalSettings.enableFeedsFab.name) ?? true;
bool enablePostsFab = prefs.getBool(LocalSettings.enablePostsFab.name) ?? true;
Expand Down Expand Up @@ -283,6 +285,8 @@ class ThunderBloc extends Bloc<ThunderEvent, ThunderState> {
rightPrimaryCommentGesture: rightPrimaryCommentGesture,
rightSecondaryCommentGesture: rightSecondaryCommentGesture,

enableFullScreenSwipeNavigationGesture: enableFullScreenSwipeNavigationGesture,

/// -------------------------- FAB Related Settings --------------------------
enablePostsFab: enablePostsFab,
enableFeedsFab: enableFeedsFab,
Expand Down
8 changes: 8 additions & 0 deletions lib/thunder/bloc/thunder_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class ThunderState extends Equatable {
this.leftSecondaryCommentGesture = SwipeAction.downvote,
this.rightPrimaryCommentGesture = SwipeAction.reply,
this.rightSecondaryCommentGesture = SwipeAction.save,
this.enableFullScreenSwipeNavigationGesture = true,

// Theme Settings
this.themeType = ThemeType.system,
Expand Down Expand Up @@ -206,6 +207,8 @@ class ThunderState extends Equatable {
final SwipeAction rightPrimaryCommentGesture;
final SwipeAction rightSecondaryCommentGesture;

final bool enableFullScreenSwipeNavigationGesture;

/// -------------------------- FAB Related Settings --------------------------
final bool enableFeedsFab;
final bool enablePostsFab;
Expand Down Expand Up @@ -325,6 +328,7 @@ class ThunderState extends Equatable {
SwipeAction? leftSecondaryCommentGesture,
SwipeAction? rightPrimaryCommentGesture,
SwipeAction? rightSecondaryCommentGesture,
bool? enableFullScreenSwipeNavigationGesture,

/// -------------------------- FAB Related Settings --------------------------
bool? enableFeedsFab,
Expand Down Expand Up @@ -436,6 +440,8 @@ class ThunderState extends Equatable {
rightPrimaryPostGesture: rightPrimaryPostGesture ?? this.rightPrimaryPostGesture,
rightSecondaryPostGesture: rightSecondaryPostGesture ?? this.rightSecondaryPostGesture,

enableFullScreenSwipeNavigationGesture: enableFullScreenSwipeNavigationGesture ?? this.enableFullScreenSwipeNavigationGesture,

// Comment Gestures
enableCommentGestures: enableCommentGestures ?? this.enableCommentGestures,
leftPrimaryCommentGesture: leftPrimaryCommentGesture ?? this.leftPrimaryCommentGesture,
Expand Down Expand Up @@ -565,6 +571,8 @@ class ThunderState extends Equatable {
rightPrimaryCommentGesture,
rightSecondaryCommentGesture,

enableFullScreenSwipeNavigationGesture,

/// -------------------------- FAB Related Settings --------------------------
enableFeedsFab,
enablePostsFab,
Expand Down
1 change: 1 addition & 0 deletions lib/user/pages/user_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class _UserPageState extends State<UserPage> {
Navigator.of(context).push(
SwipeablePageRoute(
transitionDuration: reduceAnimations ? const Duration(milliseconds: 100) : null,
canOnlySwipeFromEdge: !state.enableFullScreenSwipeNavigationGesture,
builder: (context) => MultiBlocProvider(
providers: [
BlocProvider.value(value: accountBloc),
Expand Down
Loading

0 comments on commit ae47473

Please sign in to comment.