Skip to content

feat: improve chat message animations #7890

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

Merged
merged 6 commits into from
May 7, 2025

Conversation

LucasXu0
Copy link
Collaborator

@LucasXu0 LucasXu0 commented May 7, 2025

Feature Preview


PR Checklist

  • My code adheres to AppFlowy's Conventions
  • I've listed at least one issue that this PR fixes in the description above.
  • I've added a test(s) to validate changes in this PR, or this PR only contains semantic changes.
  • All existing tests are passing.

Summary by Sourcery

Improve chat message animations and scrolling behavior in the AppFlowy chat interface

New Features:

  • Implemented a more robust scrolling mechanism for chat messages using ScrollablePositionedList

Enhancements:

  • Refactored chat list scrolling logic
  • Improved message positioning and animation
  • Enhanced scroll-to-bottom functionality

Chores:

  • Cleaned up unused code in chat message list implementation
  • Simplified message scrolling and positioning logic

Copy link
Contributor

sourcery-ai bot commented May 7, 2025

Reviewer's Guide

This pull request significantly improves chat message animations and list behavior by refactoring the main chat list to use ScrollablePositionedList for enhanced scroll management. A new ChatMessage widget was introduced for consistent message styling. Further improvements include optimized bulleted list icon rendering, more accurate font family resolution, refined reminder logging to reduce noise, and minor UI text and layout updates.

Sequence Diagram for New Message Handling in ChatAnimatedList

sequenceDiagram
    participant User as U
    participant ChatController as CC
    participant ChatAnimatedListState as CALS
    participant ItemScrollController as ISC

    CC->>CALS: New message received (triggers _onInserted)
    CALS->>CALS: _onInserted(position, data)
    alt If message is the last and by current user
        CALS->>CALS: _scrollLastMessageToTop(data)
        CALS->>ISC: scrollTo(index, duration, curve)
    end
Loading

Sequence Diagram for User Scrolling to Bottom of Chat

sequenceDiagram
    actor User
    participant ScrollToBottomButton as STBB
    participant ChatAnimatedListState as CALS
    participant ItemScrollController as ISC
    participant "_scrollToBottomController (AnimationController)" as AnimCtrl

    User->>STBB: Clicks "Scroll to Bottom"
    STBB->>CALS: Calls _handleScrollToBottom()
    CALS->>AnimCtrl: reverse() (hides button)
    CALS->>ISC: scrollTo(index, alignment, duration, curve) to scroll to end
Loading

Class Diagram: ChatAnimatedListState Refactor

classDiagram
    class ChatAnimatedListState {
        -ScrollOffsetController scrollOffsetController
        -ItemScrollController itemScrollController
        -ScrollOffsetListener scrollOffsetListener
        -ItemPositionsListener itemPositionsListener
        -int _lastUserMessageIndex
        -bool _isScrollingToBottom
        +initState()
        +dispose()
        +build(BuildContext context) Widget
        -_handleScrollToBottom() void
        -_handleToggleScrollToBottom() void
        -_onInserted(int position, Message data) void
        -_scrollLastMessageToTop(Message data) void
    }
    note for ChatAnimatedListState "Refactored to use ScrollablePositionedList for improved scrolling and animation. Removed _userHasScrolled and related logic. Updated message insertion and scroll handling methods."
Loading

Class Diagram: BulletedListIcon Refactor

classDiagram
    BulletedListIcon --|> StatefulWidget
    _BulletedListIconState --|> State
    BulletedListIcon ..> _BulletedListIconState : creates
    class BulletedListIcon {
        +Node node
        +final List~String~ bulletedListIcons
        +createState() _BulletedListIconState
    }
    class _BulletedListIconState {
        -int index
        -double size
        +void initState()
        +Widget build(BuildContext context)
        -int get level
    }
    note for BulletedListIcon "Refactored from StatelessWidget to StatefulWidget to dynamically update icon based on nesting level, improving rendering performance and correctness."
Loading

Class Diagram: New ChatMessage Widget

classDiagram
    ChatMessage --|> StatelessWidget
    class ChatMessage {
        +final Message message
        +final Widget child
        +final AlignmentGeometry sentMessageAlignment
        +final AlignmentGeometry receivedMessageAlignment
        +final EdgeInsetsGeometry padding
        +Widget build(BuildContext context)
    }
    note for ChatMessage "New widget to encapsulate chat message styling and alignment logic, promoting reusability and consistency."
Loading

Class Diagram: ReminderBloc Logging Update

classDiagram
    class ReminderBloc {
        -final DeepCollectionEquality _deepEquality
        +ReminderBloc()
        +StreamSubscription _fetchAllRemindersSubscription
    }
    note for ReminderBloc "Updated reminder fetching logic to use DeepCollectionEquality for comparing reminder ID sets. This reduces unnecessary logging when the reminder list hasn't actually changed."
Loading

Class Diagram: LoadChatMessageStatusReady Update

classDiagram
    class LoadChatMessageStatusReady {
        +View view
        +UserProfilePB userProfile
        +Widget build(BuildContext context)
    }
    LoadChatMessageStatusReady ..> ChatMessage : uses in chatMessageBuilder
    LoadChatMessageStatusReady ..> ChatAnimationListWidget : configures
    class ChatMessage
    class ChatAnimationListWidget
    note for LoadChatMessageStatusReady "Updated to use the new ChatMessage widget for rendering messages. Removed 'enableReversedList' property from ChatAnimationListWidget as part of the list behavior refactor."
Loading

File-Level Changes

Change Details Files
Revamped chat list rendering and scroll mechanics using ScrollablePositionedList.
  • Replaced CustomScrollView and SliverAnimatedList with ScrollablePositionedList for chat item display.
  • Integrated ItemScrollController for programmatic scrolling and ItemPositionsListener for item visibility detection.
  • Updated logic for automatic scrolling to new messages and to the end of the list.
  • Removed manual tracking of user scroll state.
frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/animated_chat_list.dart
Introduced a dedicated ChatMessage widget for consistent message styling.
  • Created a new widget to manage alignment (based on sender) and padding for individual chat messages.
  • Integrated the new ChatMessage widget into the chat list's item builder.
frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_page/chat_message_widget.dart
frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_page/load_chat_message_status_ready.dart
Enhanced rendering efficiency and font consistency.
  • Converted BulletedListIcon to a StatefulWidget, caching its display properties to improve rendering performance.
  • Implemented a robust mechanism for resolving display font names to actual font family names.
  • Applied this new font resolution across the application for more consistent text appearance.
frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/bulleted_list/bulleted_list_icon.dart
frontend/appflowy_flutter/lib/util/font_family_extension.dart
frontend/appflowy_flutter/lib/startup/tasks/app_widget.dart
frontend/appflowy_flutter/lib/plugins/document/presentation/editor_style.dart
Optimized reminder logging for clarity.
  • Refined reminder service logging to trigger only when reminder data actually changes, reducing log noise.
frontend/appflowy_flutter/lib/user/application/reminder/reminder_bloc.dart
Updated UI text and made minor layout adjustments.
  • Updated localization key for the 'Upgrade Plan' button in member invitation dialogs.
  • Adjusted top padding in the reversed animated chat list.
frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/members/inivitation/inivite_member_by_link.dart
frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/animated_chat_list_reversed.dart

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @LucasXu0 - I've reviewed your changes - here's some feedback:

  • The transition from SliverAnimatedList to ScrollablePositionedList might alter how individual message insertion animations are handled; verify this aligns with the intended animation improvements.
  • The chat now scrolls the current user's last message towards the top on new message arrival; confirm this specific scrolling behavior is intended for all new messages.
  • The fixed 400 pixel padding in chat lists could be made more adaptive, perhaps by relating it to screen height or making it a themeable constant.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -168,7 +168,7 @@ class ChatAnimatedListReversedState extends State<ChatAnimatedListReversed>
slivers: <Widget>[
SliverPadding(
padding: EdgeInsets.only(
top: widget.bottomPadding ?? 0,
top: 400,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Hard-coded top padding value may need review.

Verify that the 400px top padding is intentional and adapts correctly to various screen sizes and orientations.

@LucasXu0 LucasXu0 added the v0.9.2 label May 7, 2025
@LucasXu0 LucasXu0 merged commit 38839b4 into AppFlowy-IO:main May 7, 2025
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant