Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/combine post fab #648

Merged
merged 5 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Added access to saved comments from account page - contribution from @CTalvio
- Added Polish translation - contribution from @pazdikan
- Show default avatar for users without an avatar - contribution from @coslu
- Added the ability to combine the post FAB with the comment navigation buttons - contribution from @micahmo

### Changed
- Prioritize and label the default accent color - contribution from @micahmo
Expand Down
1 change: 1 addition & 0 deletions lib/core/enums/local_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ enum LocalSettings {
postFabSinglePressAction(name: 'settings_post_fab_single_press_action', label: ''),
postFabLongPressAction(name: 'settings_post_fab_long_press_action', label: ''),
enableCommentNavigation(name: 'setting_enable_comment_navigation', label: 'Enable Comment Navigation Buttons'),
combineNavAndFab(name: 'setting_combine_nav_and_fab', label: 'Combine FAB and Navigation Buttons'),
;

const LocalSettings({
Expand Down
35 changes: 22 additions & 13 deletions lib/post/pages/post_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class _PostPageState extends State<PostPage> {
bool isFabSummoned = true;
bool enableFab = false;
bool enableCommentNavigation = true;
bool combineNavAndFab = true;

CommentSortType? sortType;
IconData? sortTypeIcon;
Expand Down Expand Up @@ -95,6 +96,7 @@ class _PostPageState extends State<PostPage> {
PostFabAction longPressAction = thunderState.postFabLongPressAction;

enableCommentNavigation = thunderState.enableCommentNavigation;
combineNavAndFab = enableCommentNavigation && thunderState.combineNavAndFab;

if (thunderState.isFabOpen != _previousIsFabOpen) {
isFabOpen = thunderState.isFabOpen;
Expand Down Expand Up @@ -165,13 +167,29 @@ class _PostPageState extends State<PostPage> {
floatingActionButton: Stack(
alignment: Alignment.center,
children: [
if (enableCommentNavigation)
Positioned.fill(
child: Padding(
padding: const EdgeInsets.only(bottom: 5),
child: Align(
alignment: Alignment.bottomCenter,
child: CommentNavigatorFab(
itemPositionsListener: _itemPositionsListener,
),
),
),
),
if (enableFab)
Padding(
padding: const EdgeInsets.only(right: 16),
padding: EdgeInsets.only(
right: combineNavAndFab ? 0 : 16,
bottom: combineNavAndFab ? 5 : 0,
),
child: AnimatedSwitcher(
duration: const Duration(milliseconds: 250),
child: isFabSummoned
? GestureFab(
centered: combineNavAndFab,
distance: 60,
icon: Icon(
singlePressAction.getIcon(override: singlePressAction == PostFabAction.changeSort ? sortTypeIcon : null),
Expand Down Expand Up @@ -211,6 +229,7 @@ class _PostPageState extends State<PostPage> {
children: [
if (enableReplyToPost)
ActionButton(
centered: combineNavAndFab,
onPressed: () {
HapticFeedback.mediumImpact();
PostFabAction.replyToPost.execute(
Expand All @@ -224,6 +243,7 @@ class _PostPageState extends State<PostPage> {
),
if (enableChangeSort)
ActionButton(
centered: combineNavAndFab,
onPressed: () {
HapticFeedback.mediumImpact();
PostFabAction.changeSort.execute(
Expand All @@ -237,6 +257,7 @@ class _PostPageState extends State<PostPage> {
),
if (enableBackToTop)
ActionButton(
centered: combineNavAndFab,
onPressed: () {
PostFabAction.backToTop.execute(
override: () => {
Expand All @@ -257,18 +278,6 @@ class _PostPageState extends State<PostPage> {
: null,
),
),
if (enableCommentNavigation)
Positioned.fill(
child: Padding(
padding: const EdgeInsets.only(bottom: 5),
child: Align(
alignment: Alignment.bottomCenter,
child: CommentNavigatorFab(
itemPositionsListener: _itemPositionsListener,
),
),
),
),
],
),
body: Stack(
Expand Down
31 changes: 31 additions & 0 deletions lib/settings/pages/general_settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class _GeneralSettingsPageState extends State<GeneralSettingsPage> with SingleTi
NestedCommentIndicatorStyle nestedIndicatorStyle = DEFAULT_NESTED_COMMENT_INDICATOR_STYLE;
NestedCommentIndicatorColor nestedIndicatorColor = DEFAULT_NESTED_COMMENT_INDICATOR_COLOR;
bool enableCommentNavigation = true;
bool combineNavAndFab = true;

// Page State
bool isLoading = true;
Expand Down Expand Up @@ -206,6 +207,10 @@ class _GeneralSettingsPageState extends State<GeneralSettingsPage> with SingleTi
await prefs.setBool(LocalSettings.enableCommentNavigation.name, value);
setState(() => enableCommentNavigation = value);
break;
case LocalSettings.combineNavAndFab:
await prefs.setBool(LocalSettings.combineNavAndFab.name, value);
setState(() => combineNavAndFab = value);
break;
}

if (context.mounted) {
Expand Down Expand Up @@ -258,6 +263,7 @@ class _GeneralSettingsPageState extends State<GeneralSettingsPage> with SingleTi
nestedIndicatorColor = NestedCommentIndicatorColor.values.byName(prefs.getString(LocalSettings.nestedCommentIndicatorColor.name) ?? DEFAULT_NESTED_COMMENT_INDICATOR_COLOR.name);

enableCommentNavigation = prefs.getBool(LocalSettings.enableCommentNavigation.name) ?? true;
combineNavAndFab = prefs.getBool(LocalSettings.combineNavAndFab.name) ?? true;

// Links
openInExternalBrowser = prefs.getBool(LocalSettings.openLinksInExternalBrowser.name) ?? false;
Expand Down Expand Up @@ -608,6 +614,31 @@ class _GeneralSettingsPageState extends State<GeneralSettingsPage> with SingleTi
iconDisabled: Icons.unfold_less_rounded,
onToggle: (bool value) => setPreferences(LocalSettings.enableCommentNavigation, value),
),
AnimatedSwitcher(
duration: const Duration(milliseconds: 250),
switchInCurve: Curves.easeInOut,
switchOutCurve: Curves.easeInOut,
transitionBuilder: (Widget child, Animation<double> animation) {
return SizeTransition(
sizeFactor: animation,
child: SlideTransition(position: _offsetAnimation, child: child),
);
},
child: enableCommentNavigation
? Padding(
padding: const EdgeInsets.only(left: 16.0),
key: ValueKey(enableCommentNavigation),
child: ToggleOption(
description: LocalSettings.combineNavAndFab.label,
subtitle: 'Floating Action Button will be shown between navigation buttons',
value: combineNavAndFab,
iconEnabled: Icons.join_full_rounded,
iconDisabled: Icons.join_inner_rounded,
onToggle: (bool value) => setPreferences(LocalSettings.combineNavAndFab, value),
),
)
: Container(),
),
],
),
),
Expand Down
Loading