From 368bb7f6b8965d59fc1863e1a0e71e35a6c6dfef Mon Sep 17 00:00:00 2001 From: Hamlet Jiang Su <30667958+hjiangsu@users.noreply.github.com> Date: Wed, 13 Mar 2024 17:02:10 -0700 Subject: [PATCH] Hide unsupported FAB actions based on feed (general, community, user) (#1194) --- lib/feed/widgets/feed_fab.dart | 38 +++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/lib/feed/widgets/feed_fab.dart b/lib/feed/widgets/feed_fab.dart index 99ff7ec24..bc195450a 100644 --- a/lib/feed/widgets/feed_fab.dart +++ b/lib/feed/widgets/feed_fab.dart @@ -42,12 +42,20 @@ class FeedFAB extends StatelessWidget { FeedFabAction.subscriptions, ]; + // A list of actions that are not supported through the navigated user feed + List unsupportedNavigatedUserFeedFabActions = [ + FeedFabAction.subscriptions, + FeedFabAction.newPost, + FeedFabAction.dismissRead, + ]; + FeedFabAction singlePressAction = state.feedFabSinglePressAction; FeedFabAction longPressAction = state.feedFabLongPressAction; // Check to see if we are in the general feeds bool isGeneralFeed = feedState.status != FeedStatus.initial && feedState.feedType == FeedType.general; bool isCommunityFeed = feedState.status != FeedStatus.initial && feedState.feedType == FeedType.community; + bool isUserFeed = feedState.status != FeedStatus.initial && feedState.feedType == FeedType.user; bool isNavigatedFeed = Navigator.canPop(context); bool isPostLocked = false; @@ -60,11 +68,23 @@ class FeedFAB extends StatelessWidget { } } + List disabledActions = []; + + if (isGeneralFeed) { + disabledActions = unsupportedGeneralFeedFabActions; + } else if (isCommunityFeed && isNavigatedFeed) { + disabledActions = unsupportedNavigatedCommunityFeedFabActions; + } else if (isUserFeed && isNavigatedFeed) { + disabledActions = unsupportedNavigatedUserFeedFabActions; + } + // Check single-press action if (isGeneralFeed && unsupportedGeneralFeedFabActions.contains(singlePressAction)) { singlePressAction = FeedFabAction.openFab; // Default to open fab on unsupported actions } else if (isCommunityFeed && isNavigatedFeed && unsupportedNavigatedCommunityFeedFabActions.contains(singlePressAction)) { singlePressAction = FeedFabAction.openFab; // Default to open fab on unsupported actions + } else if (isUserFeed && unsupportedNavigatedUserFeedFabActions.contains(singlePressAction)) { + singlePressAction = FeedFabAction.openFab; // Default to open fab on unsupported actions } // Check long-press action @@ -72,6 +92,8 @@ class FeedFAB extends StatelessWidget { longPressAction = FeedFabAction.openFab; // Default to open fab on unsupported actions } else if (isCommunityFeed && isNavigatedFeed && unsupportedNavigatedCommunityFeedFabActions.contains(longPressAction)) { longPressAction = FeedFabAction.openFab; // Default to open fab on unsupported actions + } else if (isUserFeed && unsupportedNavigatedUserFeedFabActions.contains(longPressAction)) { + longPressAction = FeedFabAction.openFab; // Default to open fab on unsupported actions } return AnimatedSwitcher( @@ -152,7 +174,7 @@ class FeedFAB extends StatelessWidget { break; } }, - children: getEnabledActions(context, isPostingLocked: isPostLocked), + children: getEnabledActions(context, isPostingLocked: isPostLocked, disabledActions: disabledActions), ) : Stack( // This creates an invisible touch target to summon the FAB @@ -174,16 +196,16 @@ class FeedFAB extends StatelessWidget { ); } - List getEnabledActions(BuildContext context, {bool isPostingLocked = false}) { + List getEnabledActions(BuildContext context, {bool isPostingLocked = false, List disabledActions = const []}) { final theme = Theme.of(context); final ThunderState state = context.watch().state; - bool enableBackToTop = state.enableBackToTop; - bool enableSubscriptions = state.enableSubscriptions; - bool enableChangeSort = state.enableChangeSort; - bool enableRefresh = state.enableRefresh; - bool enableDismissRead = state.enableDismissRead; - bool enableNewPost = state.enableNewPost; + bool enableBackToTop = state.enableBackToTop && !disabledActions.contains(FeedFabAction.backToTop); + bool enableSubscriptions = state.enableSubscriptions && !disabledActions.contains(FeedFabAction.subscriptions); + bool enableChangeSort = state.enableChangeSort && !disabledActions.contains(FeedFabAction.changeSort); + bool enableRefresh = state.enableRefresh && !disabledActions.contains(FeedFabAction.refresh); + bool enableDismissRead = state.enableDismissRead && !disabledActions.contains(FeedFabAction.dismissRead); + bool enableNewPost = state.enableNewPost && !disabledActions.contains(FeedFabAction.newPost); List actions = [ if (enableDismissRead)