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

Supported right-to-left layout #445

Merged
merged 26 commits into from
Sep 6, 2020
Merged

Supported right-to-left layout #445

merged 26 commits into from
Sep 6, 2020

Conversation

grahammendick
Copy link
Owner

On Android, setLayoutDirection from the react native isRTL flag. On iOS, set semanticContentAttribute from the react native isRTL flag.

The problem was that ViewPager doesn’t support RTL layout direction. The swipe gesture to switch tabs doesn’t change when RTL. Android stopped development on ViewPager. Instead, they’ve created ViewPager2 for RTL support. But ViewPager2 isn’t as feature rich as ViewPager, for example, can’t have horizontally scrolling tab content.

Decided to keep ViewPager for LTR and use ViewPager2 for RTL. Means LTR isn’t compromised and that RTL is supported.

Going for new approach - ViewPager for LTR and ViewPager2 for RTL
Want ViewPager2 and ViewPager events to match. ViewPager2 raises an initial page selected that ViewPager doesn't, so ignore if the position is 0 (might be non-zero if controlled tab prop)
If go from A,B,C with B selected and remove A then it selected C instead of B with dataSetChanged. With itemInserted it selected A which matches ViewPager
They don't match ViewPager exactly, e.g., an initial event fires on first render event for tab 0. But can't get them to match exactly because a selected event fires when the recycler view layout runs. Test case is A,B,C and select B and remove C - with ViewPager that fires B once and ViewPager2 fires B twice, the second one coming from the CoordinatorLayout layout runing
When starting a new stack the initial scene fragment wasn't loaded until the view is attached to window. This causes a black background to show when switching tabs with stacks. Instead, ran the first navigation as soon as the scenes are added.
Catered for when the stack is loaded without a navigation. In this case don't need a start navigation because the onUpdateAfterTransaction fires after children and keys set when the navigation finally happens. Identified this case by passing empty keys. Only need special handling for when it loads with a navigation - when keys not empty
This matches ViewPager2 approach. ViewPager2 is final so couldn't subclass and intercept touch
Hard-coded TabBarPager and TabLayout to LTR because ViewPager doesn't work in RTL and there are RTL versions of these components
Not sure if this is necessary - tried in iOS 12 and seemed to be needed, but then edited out and it still worked?! Anyway, including for completeness and sure it's needed
@grahammendick grahammendick merged commit 2800d42 into master Sep 6, 2020
@grahammendick grahammendick deleted the rtl-language branch September 6, 2020 11:54
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.

1 participant