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

Re-structure TabList Animated Indicator code to work better with RTL layouts #3236

Merged
merged 11 commits into from
Dec 13, 2023

Conversation

lawrencewin
Copy link
Contributor

@lawrencewin lawrencewin commented Nov 15, 2023

Platforms Impacted

  • iOS
  • macOS
  • win32 (Office)
  • windows
  • android

Description of changes

Currently, we style and animate the TabList's animated indicator by calculating, setting, and adjusting its start layout position. On RTL layouts, the start value is calculated by flipping the left offset of a given tab by subtracting it from the width of the tablist. On mac, this also means that the translate transform for JS animations needs to be flipped.

While this works, the extra logic to set the start layout style results in code that is more complex than it needs to be. This PR changes the approach for positioning the indicator. Instead of calculating the start of the indicator, we set its position to be absolute and calculate its left / top offsets relative to the entire tablist. This removes the need for extra logic on RTL layouts. The code is also re-organized to include all of the layout math in useTabAnimation and remove it from the win32's useAnimatedIndicatorStyles (unfortunately, math still has to be done on math because we're calculating transforms 😞).

Other changes:

  • Miscellaneous styling fixes
  • Refactor different animated indicator related types
  • Fix TabList test page title to be "TabList" instead of "TabsV1"

Verification

Before After
image image

Mac video:

Rtl.mac.final.MOV

Pull request checklist

This PR has considered (when applicable):

  • Automated Tests
  • Documentation and examples
  • Keyboard Accessibility
  • Voiceover
  • Internationalization and Right-to-left Layouts

@lawrencewin lawrencewin requested a review from a team as a code owner November 15, 2023 21:28
Copy link
Collaborator

@rurikoaraki rurikoaraki left a comment

Choose a reason for hiding this comment

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

:shipit:

This commit simplifies the logic of the animated indicator. Rather than
positioning the indicator using a calculated `start` value, we position
it using absolute layout values within the tablist. Now, the
`useTabAnimation` hook does all the math to figure out the top and left
offsets of the indicator, and the styling hook for the animatedIndicator
simply uses them to position the `top` and `left` layout props.

The container slot of the animated indicator is also removed.
@lawrencewin lawrencewin changed the title Fix positioning of TabList indicator on RTL layouts Re-structure TabList Animated Indicator code to work better with RTL layouts Dec 8, 2023
@lawrencewin lawrencewin merged commit 942da04 into microsoft:main Dec 13, 2023
11 checks passed
@lawrencewin lawrencewin deleted the tablist-rtl-fix branch December 13, 2023 18:16
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.

3 participants