Skip to content

Commit

Permalink
Hide unsupported FAB actions based on feed (general, community, user) (
Browse files Browse the repository at this point in the history
  • Loading branch information
hjiangsu authored Mar 14, 2024
1 parent 048f60f commit 368bb7f
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions lib/feed/widgets/feed_fab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,20 @@ class FeedFAB extends StatelessWidget {
FeedFabAction.subscriptions,
];

// A list of actions that are not supported through the navigated user feed
List<FeedFabAction> 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;
Expand All @@ -60,18 +68,32 @@ class FeedFAB extends StatelessWidget {
}
}

List<FeedFabAction> 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
if (isGeneralFeed && unsupportedGeneralFeedFabActions.contains(longPressAction)) {
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(
Expand Down Expand Up @@ -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
Expand All @@ -174,16 +196,16 @@ class FeedFAB extends StatelessWidget {
);
}

List<ActionButton> getEnabledActions(BuildContext context, {bool isPostingLocked = false}) {
List<ActionButton> getEnabledActions(BuildContext context, {bool isPostingLocked = false, List<FeedFabAction> disabledActions = const []}) {
final theme = Theme.of(context);
final ThunderState state = context.watch<ThunderBloc>().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<ActionButton> actions = [
if (enableDismissRead)
Expand Down

0 comments on commit 368bb7f

Please sign in to comment.