Skip to content

Add OrientaionLock to BitSwipes (#9699)#9701

Merged
msynk merged 1 commit intobitfoundation:developfrom
msynk:9699-blazorui-swipes-orientationlock
Jan 19, 2025
Merged

Add OrientaionLock to BitSwipes (#9699)#9701
msynk merged 1 commit intobitfoundation:developfrom
msynk:9699-blazorui-swipes-orientationlock

Conversation

@msynk
Copy link
Member

@msynk msynk commented Jan 18, 2025

closes #9699

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced swipe functionality across multiple components with orientation locking
    • Added support for horizontal and vertical swipe orientations in dropdowns, time pickers, date pickers, and panels
  • Improvements

    • Improved panel and panel demo components with more flexible width styling
    • Refined swipe interaction handling to provide more precise control
  • Technical Enhancements

    • Updated JavaScript and C# methods to support new swipe orientation parameters
    • Simplified swipe gesture detection and handling

@coderabbitai
Copy link

coderabbitai bot commented Jan 18, 2025

Walkthrough

The changes introduce a comprehensive enhancement to the swipe functionality across multiple Blazor UI components. The primary modification involves adding an orientationLock parameter to the swipe setup method, allowing developers to specify and control the swipe orientation (horizontal or vertical) for various components like dropdowns, time pickers, date pickers, panels, and drop menus. This change is implemented consistently across TypeScript, C# extension methods, and individual component implementations, providing a unified approach to swipe gesture handling.

Changes

File Change Summary
*.razor.cs files Updated OnAfterRenderAsync methods to include BitSwipeOrientation parameter in BitSwipesSetup calls
SwipesJsRuntimeExtensions.cs Added BitSwipeOrientation parameter to BitSwipesSetup method signature
Swipes.ts Introduced new BitSwipeOrientation enum and modified swipe handling logic to respect orientation locking
Demo pages Updated inline styles from width:300px to max-width:300px for various panel and pro-panel components

Assessment against linked issues

Objective Addressed Explanation
Support OrientationLock for BitSwipes

Poem

🐰 Swipe left, swipe right,
Our code now dances with delight!
Orientation locked so tight,
Blazor UI takes playful flight!
Rabbit's code, a swipey might! 🌈

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

Copy link

@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: 0

🧹 Nitpick comments (3)
src/BlazorUI/Bit.BlazorUI/Components/Surfaces/Panel/BitPanel.razor.cs (1)

171-175: LGTM! Consider extracting the orientation logic.

The orientation locking based on panel position is well-implemented. However, consider extracting the orientation determination logic into a separate method for better readability and reusability.

+    private BitSwipeOrientation GetOrientationLock(BitPanelPosition position)
+    {
+        return position == BitPanelPosition.Start || position == BitPanelPosition.End
+               ? BitSwipeOrientation.Horizontal 
+               : BitSwipeOrientation.Vertical;
+    }

     protected override async Task OnAfterRenderAsync(bool firstRender)
     {
         if (firstRender)
         {
             var dotnetObj = DotNetObjectReference.Create(this);
             var position = Position ?? BitPanelPosition.End;
-            var orientationLock = position == BitPanelPosition.Start || position == BitPanelPosition.End
-                                    ? BitSwipeOrientation.Horizontal 
-                                    : BitSwipeOrientation.Vertical;
+            var orientationLock = GetOrientationLock(position);
             await _js.BitSwipesSetup(_containerId, SwipeTrigger ?? 0.25m, position, Dir == BitDir.Rtl, orientationLock, dotnetObj, false);
         }
src/BlazorUI/Bit.BlazorUI/Components/Utilities/SwipeTrap/BitSwipeTrap.ts (1)

Line range hint 49-78: Consider adjusting the threshold value for better touch sensitivity.

The threshold value of 5 pixels for swipe detection might be too low for some touch devices, potentially causing unintended swipe triggers.

Consider increasing the threshold:

-                const thresX = absX > 5;
-                const thresY = absY > 5;
+                const SWIPE_THRESHOLD = 10; // pixels
+                const thresX = absX > SWIPE_THRESHOLD;
+                const thresY = absY > SWIPE_THRESHOLD;
src/BlazorUI/Bit.BlazorUI/Extensions/JsInterop/SwipesJsRuntimeExtensions.cs (1)

7-15: LGTM! Consider adding XML documentation.

The method signature is well-structured with the new orientationLock parameter. Consider adding XML documentation to describe the purpose and usage of each parameter, especially the new orientationLock parameter.

 internal static ValueTask BitSwipesSetup<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(
     this IJSRuntime js,
     string id,
     decimal trigger,
     BitPanelPosition position,
     bool isRtl,
     BitSwipeOrientation orientationLock,
     DotNetObjectReference<T>? dotnetObj,
     bool isResponsive = true) where T : class
+    /// <summary>
+    /// Sets up swipe functionality for a UI component.
+    /// </summary>
+    /// <param name="js">The JavaScript runtime instance.</param>
+    /// <param name="id">The ID of the element to set up swipes for.</param>
+    /// <param name="trigger">The trigger threshold for swipe detection.</param>
+    /// <param name="position">The panel position.</param>
+    /// <param name="isRtl">Whether the component is in RTL mode.</param>
+    /// <param name="orientationLock">The orientation to lock swipes to.</param>
+    /// <param name="dotnetObj">The .NET object reference for callbacks.</param>
+    /// <param name="isResponsive">Whether the component is responsive.</param>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5cbc388 and cab5f04.

📒 Files selected for processing (14)
  • src/BlazorUI/Bit.BlazorUI/Components/Inputs/Dropdown/BitDropdown.razor.cs (1 hunks)
  • src/BlazorUI/Bit.BlazorUI/Components/Inputs/_Pickers/CircularTimePicker/BitCircularTimePicker.razor.cs (1 hunks)
  • src/BlazorUI/Bit.BlazorUI/Components/Inputs/_Pickers/DatePicker/BitDatePicker.razor.cs (1 hunks)
  • src/BlazorUI/Bit.BlazorUI/Components/Inputs/_Pickers/DateRangePicker/BitDateRangePicker.razor.cs (1 hunks)
  • src/BlazorUI/Bit.BlazorUI/Components/Inputs/_Pickers/TimePicker/BitTimePicker.razor.cs (1 hunks)
  • src/BlazorUI/Bit.BlazorUI/Components/Navs/DropMenu/BitDropMenu.razor.cs (1 hunks)
  • src/BlazorUI/Bit.BlazorUI/Components/Surfaces/Panel/BitPanel.razor.cs (1 hunks)
  • src/BlazorUI/Bit.BlazorUI/Components/Utilities/SwipeTrap/BitSwipeTrap.ts (1 hunks)
  • src/BlazorUI/Bit.BlazorUI/Extensions/JsInterop/SwipesJsRuntimeExtensions.cs (1 hunks)
  • src/BlazorUI/Bit.BlazorUI/Scripts/Swipes.ts (7 hunks)
  • src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Extras/ProPanel/BitProPanelDemo.razor (15 hunks)
  • src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Extras/ProPanel/BitProPanelDemo.razor.cs (15 hunks)
  • src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Surfaces/Panel/BitPanelDemo.razor (6 hunks)
  • src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Surfaces/Panel/BitPanelDemo.razor.cs (6 hunks)
✅ Files skipped from review due to trivial changes (2)
  • src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Extras/ProPanel/BitProPanelDemo.razor.cs
  • src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Surfaces/Panel/BitPanelDemo.razor.cs
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build and test
🔇 Additional comments (14)
src/BlazorUI/Bit.BlazorUI/Components/Inputs/Dropdown/BitDropdown.razor.cs (1)

858-858: LGTM! Horizontal swipe orientation aligns with dropdown's responsive behavior.

The horizontal swipe orientation is appropriate for the dropdown's side panel behavior in responsive mode.

src/BlazorUI/Bit.BlazorUI/Components/Inputs/_Pickers/DatePicker/BitDatePicker.razor.cs (2)

536-536: LGTM! Vertical swipe orientation suits the date picker's UI.

The vertical swipe orientation aligns well with the date picker's dropdown panel behavior.


Line range hint 351-351: Excellent consistency in swipe orientation implementation across components!

The implementation demonstrates a well-thought-out pattern:

  • Horizontal swipes for components that slide sideways (dropdowns)
  • Vertical swipes for components that use dropdown panels (pickers)

This consistency in UX behavior will help users develop muscle memory for interactions across the UI.

Also applies to: 313-314, 858-858, 536-536

src/BlazorUI/Bit.BlazorUI/Components/Inputs/_Pickers/DateRangePicker/BitDateRangePicker.razor.cs (1)

599-599: LGTM! Appropriate orientation choice.

The vertical orientation lock is a suitable choice for a date range picker component, as it prevents horizontal swipes from interfering with the calendar navigation.

src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Surfaces/Panel/BitPanelDemo.razor (2)

17-17: LGTM! Improved responsive design.

The change from fixed width:300px to max-width:300px enhances the responsive behavior of panels, allowing them to adapt to smaller screen sizes while maintaining their maximum width constraint.

Also applies to: 34-34, 48-48, 62-62, 178-178, 189-189


Line range hint 1-199: Verify alignment with PR objectives.

The changes in this file focus on responsive design improvements by modifying panel widths. However, the PR title and objectives mention adding OrientationLock to BitSwipes, but no such changes are visible in this file.

Run the following script to check for any swipe-related changes:

src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Extras/ProPanel/BitProPanelDemo.razor (2)

17-17: LGTM! Consistent responsive design improvements.

The changes from fixed width:300px to max-width:300px are consistently applied across all panel instances, improving the responsive behavior of the ProPanel component.

Also applies to: 31-31, 52-52, 67-67, 82-82, 108-108, 117-117, 126-126, 135-135, 144-144, 236-236, 251-251, 270-270, 296-296, 308-308


Line range hint 1-317: Verify PR scope and implementation.

While the responsive design improvements are valuable, they appear unrelated to the PR's stated objective of adding OrientationLock to BitSwipes. Let's verify if the swipe-related changes are present in other files.

Run the following script to locate the swipe-related implementation:

src/BlazorUI/Bit.BlazorUI/Components/Navs/DropMenu/BitDropMenu.razor.cs (1)

156-156: LGTM! Horizontal swipe orientation is appropriate for dropdown menus.

The addition of BitSwipeOrientation.Horizontal aligns with the natural interaction pattern for dropdown menus, where users expect horizontal swipe gestures.

src/BlazorUI/Bit.BlazorUI/Scripts/Swipes.ts (3)

49-61: Well-implemented orientation detection logic.

The implementation uses appropriate thresholds to determine the swipe direction and locks it for the duration of the gesture, preventing unintended direction changes mid-swipe.


63-77: Robust orientation locking implementation.

The orientation locking logic effectively:

  • Cancels movements perpendicular to the locked orientation
  • Maintains the primary movement direction
  • Handles both horizontal and vertical orientations consistently

236-240: Well-defined orientation enum.

The BitSwipeOrientation enum provides clear states for handling swipe directions.

src/BlazorUI/Bit.BlazorUI/Components/Inputs/_Pickers/TimePicker/BitTimePicker.razor.cs (1)

351-351: LGTM! Vertical swipe orientation is appropriate for top-sliding panels.

The addition of BitSwipeOrientation.Vertical aligns with the component's behavior of sliding from the top in responsive mode.

src/BlazorUI/Bit.BlazorUI/Components/Inputs/_Pickers/CircularTimePicker/BitCircularTimePicker.razor.cs (1)

313-314: LGTM! Vertical swipe orientation is appropriate for this picker.

The addition of BitSwipeOrientation.Vertical aligns with the component's behavior of sliding from the top. The setup is properly sequenced with the pointer event registrations.

@msynk msynk merged commit b77b18f into bitfoundation:develop Jan 19, 2025
@msynk msynk deleted the 9699-blazorui-swipes-orientationlock branch January 19, 2025 06:40
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.

The BitSwipes internal implementation in the BlazorUI needs to support the OrientationLock

2 participants