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

fix: Swipable too sensitive #1280

Merged
merged 1 commit into from
Dec 3, 2024
Merged

Conversation

alexrisch
Copy link
Contributor

@alexrisch alexrisch commented Dec 3, 2024

Added check for translation to handle read/unread setting

Closes #1281

Summary by CodeRabbit

  • New Features

    • Enhanced swipe gesture functionality for toggling read status in conversation lists, ensuring it only activates with significant swipes.
    • Improved context menu actions for group conversations, including asynchronous updates for user interactions.
  • Bug Fixes

    • Adjusted error handling and control flow related to user interactions in group conversation management.
  • Documentation

    • Added new type definitions for better clarity on component props and interactions.

Added check for translation to handle read/unread setting
@alexrisch alexrisch requested a review from a team as a code owner December 3, 2024 17:08
Copy link
Contributor

coderabbitai bot commented Dec 3, 2024

Walkthrough

The changes in this pull request focus on enhancing the swipe gesture handling for the V3DMListItem and V3GroupConversationListItem components. The logic for toggling the read status upon a left swipe has been updated to include a threshold check based on swipe translation values. Additionally, the V3GroupConversationListItem component sees improvements in its context menu functionality and asynchronous operations for user actions. New type definitions have been introduced, and there are adjustments to ensure that the latest references are used in callback functions.

Changes

File Change Summary
components/V3DMListItem.tsx - Updated onLeftSwipe to toggle read status based on swipe translation exceeding 100.
- Added ref to the dependency array of onLeftSwipe.
components/V3GroupConversationListItem.tsx - Modified onLeftSwipe to check swipe translation before toggling read status.
- Updated handleDelete and handleRestore for async operations.
- Used useMemo for context menu items.
- Adjusted showContextMenu for setting context menu data.
- Added new type definitions and exported the V3GroupConversationListItem function.

Possibly related PRs

  • fix: URL Crash  #1084: The changes in the onLeftSwipe function in both the main PR and the retrieved PR involve modifying the logic for handling swipe gestures and toggling read statuses based on certain conditions, indicating a direct connection in functionality.

Suggested reviewers

  • thierryskoda

🐰 In the meadow where rabbits play,
A swipe now makes the read status sway.
With logic refined and gestures clear,
We hop along, spreading cheer!
So swipe away, let your fingers dance,
For every gesture, there's a chance! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

toggleReadStatus();
}, [toggleReadStatus]);
const translation = ref.current?.state.rowTranslation;
if (translation && (translation as any)._value > 100) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would love to not do this, but moving stuff over from V2

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
components/V3DMListItem.tsx (1)

155-159: Improve type safety and threshold configuration

While the translation threshold check effectively addresses the sensitivity issue, there are a couple of improvements to consider:

  1. The type assertion as any could be replaced with proper typing
  2. The threshold value (100) should be defined as a named constant for better maintainability

Consider applying these improvements:

+const SWIPE_TRANSLATION_THRESHOLD = 100; // pixels
+
 const onLeftSwipe = useCallback(() => {
   const translation = ref.current?.state.rowTranslation;
-  if (translation && (translation as any)._value > 100) {
+  if (translation?._value > SWIPE_TRANSLATION_THRESHOLD) {
     toggleReadStatus();
   }
 }, [toggleReadStatus, ref]);
components/V3GroupConversationListItem.tsx (1)

298-303: Document swipe behavior and thresholds

While the implementation effectively addresses the sensitivity issue, it would benefit from documentation explaining:

  1. The expected swipe behavior
  2. The reasoning behind the chosen threshold value
  3. The relationship between swipe distance and read status toggle

Consider adding a JSDoc comment:

+  /**
+   * Handles left swipe gesture to toggle read status
+   * Only triggers when swipe distance exceeds threshold to prevent accidental toggles
+   * @see https://github.com/ephemeraHQ/converse-app/pull/1280
+   */
   const onLeftSwipe = useCallback(() => {
     const translation = ref.current?.state.rowTranslation;
     if (translation && (translation as any)._value > 100) {
       toggleReadStatus();
     }
   }, [ref, toggleReadStatus]);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0882b4d and 5a2a9af.

📒 Files selected for processing (2)
  • components/V3DMListItem.tsx (1 hunks)
  • components/V3GroupConversationListItem.tsx (1 hunks)
🔇 Additional comments (3)
components/V3DMListItem.tsx (2)

155-159: LGTM: Swipe sensitivity fix is well implemented

The addition of a translation threshold check is a good solution to prevent accidental triggering of the read/unread toggle. The implementation:

  • Properly checks the current swipe translation
  • Only triggers the action when the swipe exceeds a significant distance
  • Maintains the existing haptic feedback for user interaction
  • Correctly includes the ref in the dependency array

155-159: Verify consistent swipe threshold across components

Since similar changes were made to V3GroupConversationListItem.tsx, we should ensure both components use the same translation threshold for a consistent user experience.

✅ Verification successful

Swipe threshold is consistent across components

The verification shows that both V3DMListItem.tsx and V3GroupConversationListItem.tsx use the same translation threshold value of 100 for triggering the read status toggle, ensuring a consistent swipe behavior across the application.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for translation threshold checks in conversation list items
rg -A 3 "rowTranslation.*_value.*>" --type typescript

Length of output: 90


Script:

#!/bin/bash
# Search for translation threshold checks in conversation list items using ripgrep without file type restriction
rg -A 3 "rowTranslation.*_value.*>"

Length of output: 37


Script:

#!/bin/bash
# First, let's find all relevant list item components
fd "V3.*ListItem.tsx"

# Then search for any translation or swipe related code
rg -A 5 "translation|swipe|rowTranslation" $(fd "V3.*ListItem.tsx")

Length of output: 1199

components/V3GroupConversationListItem.tsx (1)

299-303: Verify consistent swipe threshold across components

Since this PR addresses swipe sensitivity, we should ensure consistent behavior across all swipeable components.

✅ Verification successful

Let me gather more specific information about the swipe threshold implementation in these components.


Swipe threshold implementation is consistent in list items but differs in message replies

The verification reveals:

  • Both V3GroupConversationListItem and V3DMListItem consistently use the same threshold of 100 for swipe actions to toggle read status
  • RepliableMessageWrapper uses a different threshold variable xTresholdToReply for reply actions, which is appropriate as it serves a different purpose
  • ConversationListItem doesn't show any translation threshold, suggesting it might be using a different mechanism
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other swipeable components and their threshold implementations
echo "Searching for swipeable components and their threshold implementations..."

# Look for similar translation checks in other files
rg -A 3 "rowTranslation" --type typescript

# Look for other swipeable components
ast-grep --pattern 'import { Swipeable } from "react-native-gesture-handler"'

Length of output: 736


Script:

#!/bin/bash
# Search for translation threshold checks in the identified components
echo "Checking translation threshold implementations..."

# Look for translation threshold checks
rg -A 5 "translation.*_value" components/V3GroupConversationListItem.tsx components/V3DMListItem.tsx components/ConversationListItem/ConversationListItem.tsx components/Chat/Message/RepliableMessageWrapper.tsx

# Look for any other numeric threshold checks related to swipe
rg -A 5 "translation.*\d+" components/V3GroupConversationListItem.tsx components/V3DMListItem.tsx components/ConversationListItem/ConversationListItem.tsx components/Chat/Message/RepliableMessageWrapper.tsx

Length of output: 2645

Comment on lines +299 to +303
const translation = ref.current?.state.rowTranslation;
if (translation && (translation as any)._value > 100) {
toggleReadStatus();
}
}, [ref, toggleReadStatus]);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve type safety and maintainability of the swipe threshold check

The current implementation has several issues:

  1. Using as any bypasses TypeScript's type checking
  2. Hardcoded threshold value lacks context
  3. Accessing internal _value property is fragile

Consider this safer implementation:

-    const translation = ref.current?.state.rowTranslation;
-    if (translation && (translation as any)._value > 100) {
+    const SWIPE_THRESHOLD = 100; // pixels
+    const translation = ref.current?.state.rowTranslation?.getValue?.();
+    if (typeof translation === 'number' && translation > SWIPE_THRESHOLD) {
       toggleReadStatus();
     }

Also, consider adding these improvements:

  1. Define the threshold as a constant at component/module level
  2. Add a comment explaining the threshold's significance
  3. Consider making the threshold configurable via props if needed by other components
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const translation = ref.current?.state.rowTranslation;
if (translation && (translation as any)._value > 100) {
toggleReadStatus();
}
}, [ref, toggleReadStatus]);
const SWIPE_THRESHOLD = 100; // pixels
const translation = ref.current?.state.rowTranslation?.getValue?.();
if (typeof translation === 'number' && translation > SWIPE_THRESHOLD) {
toggleReadStatus();
}
}, [ref, toggleReadStatus]);

Copy link
Contributor

github-actions bot commented Dec 3, 2024

Performance Comparison Report

  • Current: f74f2a1 - 2024-12-03 17:12:14Z
  • Baseline: release/3.0.0 (0882b4d) - 2024-12-03 17:11:06Z

Significant Changes To Duration

There are no entries

Meaningless Changes To Duration

Show entries
Name Type Duration Count
Avatar Image 10 runs render 1.1 ms → 1.1 ms 1 → 1
Avatar Image 50 runs render 1.1 ms → 1.2 ms (+0.1 ms, +8.8%) 1 → 1
Empty Avatar 10 runs render 0.9 ms → 1.0 ms (+0.1 ms, +11.1%) 1 → 1
Empty Avatar 50 runs render 0.7 ms → 0.9 ms (+0.2 ms, +24.3%) 🔴 1 → 1
Text Component with color prop - 10 runs render 0.6 ms → 0.0 ms (-0.6 ms, -100.0%) 🟢 1 → 1
Text Component with default props - 10 runs render 0.6 ms → 0.3 ms (-0.3 ms, -50.0%) 🟢 1 → 1
Text Component with translation key - 10 runs render 0.4 ms → 0.5 ms (+0.1 ms, +25.0%) 🔴 1 → 1
Text Component with weight and size - 10 runs render 0.3 ms → 0.1 ms (-0.2 ms, -66.7%) 🟢 1 → 1
Show details
Name Type Duration Count
Avatar Image 10 runs render Baseline
Mean: 1.1 ms
Stdev: 0.3 ms (28.7%)
Runs: 1 1 1 1 1 2 1 1 1 1
Warmup runs: 2

Current
Mean: 1.1 ms
Stdev: 0.3 ms (28.7%)
Runs: 1 1 1 1 2 1 1 1 1 1
Warmup runs: 2
Baseline
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:

Current
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:
Avatar Image 50 runs render Baseline
Mean: 1.1 ms
Stdev: 0.4 ms (35.5%)
Runs: 1 2 1 2 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 2 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 2 1
Warmup runs: 1

Current
Mean: 1.2 ms
Stdev: 0.5 ms (38.4%)
Runs: 1 2 1 2 1 2 2 1 2 2 1 1 1 1 1 2 1 1 0 1 1 1 1 2 2 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 2
Warmup runs: 1
Baseline
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Render issues:

Current
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Render issues:
Empty Avatar 10 runs render Baseline
Mean: 0.9 ms
Stdev: 0.3 ms (35.1%)
Runs: 1 1 1 1 1 1 1 1 0 1
Warmup runs: 3

Current
Mean: 1.0 ms
Stdev: 0.5 ms (47.1%)
Runs: 1 1 0 1 2 1 1 1 1 1
Warmup runs: 3
Baseline
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:

Current
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:
Empty Avatar 50 runs render Baseline
Mean: 0.7 ms
Stdev: 0.4 ms (59.9%)
Runs: 0 0 1 1 0 1 1 0 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 1 0 1 1 1 1 0 1 1 0 1 0
Warmup runs: 1

Current
Mean: 0.9 ms
Stdev: 0.3 ms (37.0%)
Runs: 1 1 1 1 1 1 1 0 1 1 1 1 2 1 1 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1
Warmup runs: 1
Baseline
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Render issues:

Current
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Render issues:
Text Component with color prop - 10 runs render Baseline
Mean: 0.6 ms
Stdev: 0.5 ms (86.1%)
Runs: 1 0 1 1 0 0 1 0 1 1
Warmup runs: 0

Current
Mean: 0.0 ms
Stdev: 0.0 ms (NaN%)
Runs: 0 0 0 0 0 0 0 0 0 0
Warmup runs: 0
Baseline
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:

Current
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:
Text Component with default props - 10 runs render Baseline
Mean: 0.6 ms
Stdev: 0.5 ms (86.1%)
Runs: 1 0 0 1 0 0 1 1 1 1
Warmup runs: 1

Current
Mean: 0.3 ms
Stdev: 0.5 ms (161.0%)
Runs: 0 0 0 0 1 0 1 1 0 0
Warmup runs: 0
Baseline
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:

Current
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:
Text Component with translation key - 10 runs render Baseline
Mean: 0.4 ms
Stdev: 0.5 ms (129.1%)
Runs: 1 0 0 1 0 0 0 1 1 0
Warmup runs: 0

Current
Mean: 0.5 ms
Stdev: 0.5 ms (105.4%)
Runs: 0 0 1 1 1 0 0 1 0 1
Warmup runs: 0
Baseline
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:

Current
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:
Text Component with weight and size - 10 runs render Baseline
Mean: 0.3 ms
Stdev: 0.5 ms (161.0%)
Runs: 0 0 0 0 1 1 0 0 1 0
Warmup runs: 1

Current
Mean: 0.1 ms
Stdev: 0.3 ms (316.2%)
Runs: 1 0 0 0 0 0 0 0 0 0
Warmup runs: 1
Baseline
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:

Current
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:

Render Count Changes

There are no entries

Render Issues

There are no entries

Added Scenarios

There are no entries

Removed Scenarios

There are no entries

Generated by 🚫 dangerJS against 5a2a9af

@alexrisch alexrisch merged commit 7d67143 into release/3.0.0 Dec 3, 2024
6 checks passed
@alexrisch alexrisch deleted the ar/swipe-distance-v3 branch December 3, 2024 19:17
technoplato pushed a commit that referenced this pull request Dec 17, 2024
Added check for translation to handle read/unread setting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants