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

Implement swipe to reply in Chat (#134) #188

Merged
merged 22 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ All user visible changes to this project will be documented in this file. This p
[#134]: /../../issues/134
[#142]: /../../pull/142
[#188]: /../../pull/188
[#190]: /../../issues/190
[#191]: /../../pull/191
[#192]: /../../issues/192
[#193]: /../../pull/193
[#196]: /../../issues/196
Expand Down
4 changes: 3 additions & 1 deletion lib/ui/page/home/page/chat/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ class ChatController extends GetxController {
/// Used to discard any vertical gestures while this is `true`.
final RxBool isHorizontalScroll = RxBool(false);

/// [Timer] for playing end animation of a horizontal scroll on web.
/// [Timer] for discarding any vertical movement in a [FlutterListView] of
/// [ChatItem]s when non-`null`.
final Rx<Timer?> horizontalScrollTimer = Rx(null);

/// [GlobalKey] of the bottom bar.
Expand Down Expand Up @@ -364,6 +365,7 @@ class ChatController extends GetxController {
_typingSubscription?.cancel();
_typingTimer?.cancel();
_durationTimer?.cancel();
horizontalScrollTimer.value?.cancel();
listController.removeListener(_updateFabStates);
listController.dispose();

Expand Down
20 changes: 7 additions & 13 deletions lib/ui/page/home/page/chat/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -269,19 +269,13 @@ class _ChatViewState extends State<ChatView>
body: Listener(
onPointerSignal: (s) {
if (s is PointerScrollEvent) {
if ((s.scrollDelta.dy.abs() < 3 &&
s.scrollDelta.dx.abs() > 3) ||
c.isHorizontalScroll.value) {
if (s.scrollDelta.dy.abs() < 3 &&
(s.scrollDelta.dx.abs() > 3 ||
c.isHorizontalScroll.value)) {
krida2000 marked this conversation as resolved.
Show resolved Hide resolved
double value =
_animation.value + s.scrollDelta.dx / 100;
_animation.value = value.clamp(0, 1);

if (_animation.value == 0 ||
_animation.value == 1) {
_resetHorizontalScroll(c, 100.milliseconds);
} else {
_resetHorizontalScroll(c);
}
_resetHorizontalScroll(c);
}
}
},
Expand Down Expand Up @@ -2004,11 +1998,11 @@ class _ChatViewState extends State<ChatView>
/// Cancels a [_horizontalScrollTimer] and starts it again with the provided
/// [duration].
///
/// Defaults to 150 milliseconds if no [duration] is provided.
/// Defaults to 50 milliseconds if no [duration] is provided.
void _resetHorizontalScroll(ChatController c, [Duration? duration]) {
c.horizontalScrollTimer.value?.cancel();
c.isHorizontalScroll.value = true;
c.horizontalScrollTimer.value = Timer(duration ?? 150.milliseconds, () {
c.horizontalScrollTimer.value?.cancel();
c.horizontalScrollTimer.value = Timer(duration ?? 50.milliseconds, () {
if (_animation.value >= 0.5) {
_animation.forward();
} else {
Expand Down
8 changes: 4 additions & 4 deletions lib/ui/page/home/page/chat/widget/animated_offset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@

import 'package:flutter/material.dart';

/// Animated translation of the provided [child] on every [offset] changes.
/// Animated translation of the provided [child] on the [offset] changes.
class AnimatedOffset extends ImplicitlyAnimatedWidget {
const AnimatedOffset({
Key? key,
required this.offset,
required this.child,
Duration duration = const Duration(milliseconds: 250),
Curve curve = Curves.linear,
void Function()? onEnd,
required this.child,
}) : super(key: key, curve: curve, duration: duration, onEnd: onEnd);

/// Initial [Offset] of the [child].
/// [Offset] to apply to the [child].
final Offset offset;

/// [Widget] to transform around.
/// [Widget] to offset.
final Widget child;

@override
Expand Down