Skip to content

Commit

Permalink
Minor dismissible tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
micahmo committed Jul 24, 2023
1 parent 89e185d commit 3501aed
Showing 1 changed file with 76 additions and 76 deletions.
152 changes: 76 additions & 76 deletions lib/community/widgets/post_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,83 +103,83 @@ class _PostCardState extends State<PostCard> {
}
},
onPointerCancel: (event) => {},
child: Dismissible(
direction: state.enablePostGestures == false ? DismissDirection.none : determinePostSwipeDirection(isUserLoggedIn, state),
key: ObjectKey(widget.postViewMedia.postView.post.id),
resizeDuration: Duration.zero,
dismissThresholds: const {DismissDirection.endToStart: 1, DismissDirection.startToEnd: 1},
confirmDismiss: (DismissDirection direction) async {
return false;
},
onUpdate: (DismissUpdateDetails details) {
SwipeAction? updatedSwipeAction;
child: Column(
children: [
Divider(
height: 1.0,
thickness: 4.0,
color: ElevationOverlay.applySurfaceTint(
Theme.of(context).colorScheme.surface,
Theme.of(context).colorScheme.surfaceTint,
10,
),
),
Dismissible(
direction: state.enablePostGestures == false ? DismissDirection.none : determinePostSwipeDirection(isUserLoggedIn, state),
key: ObjectKey(widget.postViewMedia.postView.post.id),
resizeDuration: Duration.zero,
dismissThresholds: const {DismissDirection.endToStart: 1, DismissDirection.startToEnd: 1},
confirmDismiss: (DismissDirection direction) async {
return false;
},
onUpdate: (DismissUpdateDetails details) {
SwipeAction? updatedSwipeAction;

if (details.progress > firstActionThreshold && details.progress < secondActionThreshold && details.direction == DismissDirection.startToEnd) {
updatedSwipeAction = state.leftPrimaryPostGesture;
if (updatedSwipeAction != swipeAction) HapticFeedback.mediumImpact();
} else if (details.progress > secondActionThreshold && details.direction == DismissDirection.startToEnd) {
if (state.leftSecondaryPostGesture != SwipeAction.none) {
updatedSwipeAction = state.leftSecondaryPostGesture;
} else {
updatedSwipeAction = state.leftPrimaryPostGesture;
}
if (updatedSwipeAction != swipeAction) HapticFeedback.mediumImpact();
} else if (details.progress > firstActionThreshold && details.progress < secondActionThreshold && details.direction == DismissDirection.endToStart) {
updatedSwipeAction = state.rightPrimaryPostGesture;
if (updatedSwipeAction != swipeAction) HapticFeedback.mediumImpact();
} else if (details.progress > secondActionThreshold && details.direction == DismissDirection.endToStart) {
if (state.rightSecondaryPostGesture != SwipeAction.none) {
updatedSwipeAction = state.rightSecondaryPostGesture;
} else {
updatedSwipeAction = state.rightPrimaryPostGesture;
}
if (details.progress > firstActionThreshold && details.progress < secondActionThreshold && details.direction == DismissDirection.startToEnd) {
updatedSwipeAction = state.leftPrimaryPostGesture;
if (updatedSwipeAction != swipeAction) HapticFeedback.mediumImpact();
} else if (details.progress > secondActionThreshold && details.direction == DismissDirection.startToEnd) {
if (state.leftSecondaryPostGesture != SwipeAction.none) {
updatedSwipeAction = state.leftSecondaryPostGesture;
} else {
updatedSwipeAction = state.leftPrimaryPostGesture;
}
if (updatedSwipeAction != swipeAction) HapticFeedback.mediumImpact();
} else if (details.progress > firstActionThreshold && details.progress < secondActionThreshold && details.direction == DismissDirection.endToStart) {
updatedSwipeAction = state.rightPrimaryPostGesture;
if (updatedSwipeAction != swipeAction) HapticFeedback.mediumImpact();
} else if (details.progress > secondActionThreshold && details.direction == DismissDirection.endToStart) {
if (state.rightSecondaryPostGesture != SwipeAction.none) {
updatedSwipeAction = state.rightSecondaryPostGesture;
} else {
updatedSwipeAction = state.rightPrimaryPostGesture;
}

if (updatedSwipeAction != swipeAction) HapticFeedback.mediumImpact();
} else {
updatedSwipeAction = null;
}
if (updatedSwipeAction != swipeAction) HapticFeedback.mediumImpact();
} else {
updatedSwipeAction = null;
}

setState(() {
dismissThreshold = details.progress;
dismissDirection = details.direction;
swipeAction = updatedSwipeAction;
});
},
background: dismissDirection == DismissDirection.startToEnd
? AnimatedContainer(
alignment: Alignment.centerLeft,
color: swipeAction == null
? getSwipeActionColor(state.leftPrimaryPostGesture).withOpacity(dismissThreshold / firstActionThreshold)
: getSwipeActionColor(swipeAction ?? SwipeAction.none),
duration: const Duration(milliseconds: 200),
child: SizedBox(
width: MediaQuery.of(context).size.width * (state.tabletMode ? 0.5 : 1) * dismissThreshold,
child: swipeAction == null ? Container() : Icon(getSwipeActionIcon(swipeAction ?? SwipeAction.none, read: read)),
),
)
: AnimatedContainer(
alignment: Alignment.centerRight,
color: swipeAction == null
? getSwipeActionColor(state.rightPrimaryPostGesture).withOpacity(dismissThreshold / firstActionThreshold)
: getSwipeActionColor(swipeAction ?? SwipeAction.none),
duration: const Duration(milliseconds: 200),
child: SizedBox(
width: (MediaQuery.of(context).size.width * (state.tabletMode ? 0.5 : 1)) * dismissThreshold,
child: swipeAction == null ? Container() : Icon(getSwipeActionIcon(swipeAction ?? SwipeAction.none, read: read)),
),
),
child: Column(
children: [
Divider(
height: 1.0,
thickness: 4.0,
color: ElevationOverlay.applySurfaceTint(
Theme.of(context).colorScheme.surface,
Theme.of(context).colorScheme.surfaceTint,
10,
),
),
InkWell(
setState(() {
dismissThreshold = details.progress;
dismissDirection = details.direction;
swipeAction = updatedSwipeAction;
});
},
background: dismissDirection == DismissDirection.startToEnd
? AnimatedContainer(
alignment: Alignment.centerLeft,
color: swipeAction == null
? getSwipeActionColor(state.leftPrimaryPostGesture).withOpacity(dismissThreshold / firstActionThreshold)
: getSwipeActionColor(swipeAction ?? SwipeAction.none),
duration: const Duration(milliseconds: 200),
child: SizedBox(
width: MediaQuery.of(context).size.width * (state.tabletMode ? 0.5 : 1) * dismissThreshold,
child: swipeAction == null ? Container() : Icon(getSwipeActionIcon(swipeAction ?? SwipeAction.none, read: read)),
),
)
: AnimatedContainer(
alignment: Alignment.centerRight,
color: swipeAction == null
? getSwipeActionColor(state.rightPrimaryPostGesture).withOpacity(dismissThreshold / firstActionThreshold)
: getSwipeActionColor(swipeAction ?? SwipeAction.none),
duration: const Duration(milliseconds: 200),
child: SizedBox(
width: (MediaQuery.of(context).size.width * (state.tabletMode ? 0.5 : 1)) * dismissThreshold,
child: swipeAction == null ? Container() : Icon(getSwipeActionIcon(swipeAction ?? SwipeAction.none, read: read)),
),
),
child: InkWell(
child: state.useCompactView
? PostCardViewCompact(
postViewMedia: widget.postViewMedia,
Expand Down Expand Up @@ -261,8 +261,8 @@ class _PostCardState extends State<PostCard> {
if (context.mounted) context.read<CommunityBloc>().add(ForceRefreshEvent());
},
),
],
),
),
],
),
),
);
Expand Down

0 comments on commit 3501aed

Please sign in to comment.