Skip to content

Conversation

@kmelmon
Copy link
Contributor

@kmelmon kmelmon commented Apr 27, 2020

Fixes #4684
Fixes #4676
Fixes #4670

This change adds support for auto-detecting we're in an RTL locale, and flipping the FlowDirection on root view(s) to RightToLeft. It also adds support for two i18nManager APIs:
forceRTL: Used for testing, forces the framework into RTL mode even on LTR locales
allowRTL: When set true, the auto-detection logic runs and flips the root into RTL in RTL locales. The default value is true, same as the other platforms.

Note that if you toggle the primary language, you must restart the app for changes to be applied. This is consistent with other platforms.

Tested this change out in the RTLExample page in RNTester which has a control to toggle forceRTL.

Microsoft Reviewers: Open in CodeFlow

}

void I18nHelper::setAllowRTL(bool allowRTL) {
m_allowRTL = allowRTL;
Copy link
Contributor

@NickGerleman NickGerleman Apr 28, 2020

Choose a reason for hiding this comment

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

Are we okay with this as a global setting instead of per instance? Wondering why we moved to a singleton. #Resolved

Copy link
Contributor Author

@kmelmon kmelmon Apr 28, 2020

Choose a reason for hiding this comment

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

The singleton is there for simplicity and is modeled after how it was done on android. NativeUIManager now depends on functionality inside I18nManager. With the singleton helper we don't need to share the entire I18nModule with the UIManagerModule, which would lead to awkward lifetime issues (the modules are created lazily).

From a high level as to if it's OK to use a singleton, I think so. The information being queried from the OS is per application instance anyway, and it seems not useful for different instances to set allowRTL/forceRTL differently for different instances so simpler seems better to me.

// Push the appropriate FlowDirection into the root view.
auto flow = I18nHelper::Instance().getIsRTL() ? winrt::FlowDirection::RightToLeft : winrt::FlowDirection::LeftToRight;
view.as<winrt::FrameworkElement>().FlowDirection(
I18nHelper::Instance().getIsRTL() ? winrt::FlowDirection::RightToLeft : winrt::FlowDirection::LeftToRight);
Copy link
Member

@asklar asklar Apr 28, 2020

Choose a reason for hiding this comment

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

can you please use the updated namespaces? (xaml::FrameworkElement, etc.) #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


In reply to: 416489965 [](ancestors = 416489965)

@ghost ghost added the Needs: Author Feedback The issue/PR needs activity from its author (label drives bot activity) label Apr 28, 2020
@ghost ghost removed the Needs: Author Feedback The issue/PR needs activity from its author (label drives bot activity) label Apr 28, 2020

class I18nHelper {
public:
static I18nHelper &Instance();
Copy link
Member

Choose a reason for hiding this comment

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

) [](start = 30, length = 1)

Please consider to add noexcept to methods and constructors to keep binary code smaller.

I18nHelper();

void setInfo(I18nModule::I18nInfo &&i18nInfo);
std::string getLocaleIdentifier();
Copy link
Member

@vmoroz vmoroz Apr 28, 2020

Choose a reason for hiding this comment

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

) [](start = 34, length = 1)

Can it be const? #Resolved


private:
I18nModule::I18nInfo m_i18nInfo;
bool m_allowRTL = true;
Copy link
Member

@vmoroz vmoroz Apr 28, 2020

Choose a reason for hiding this comment

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

= true [](start = 17, length = 7)

The latest 'fashion' is to use the universal initializers:
bool m_allowRTL{true};

E.g. the std::atomic fails to initialize otherwise in Clang. #Resolved

Copy link
Member

@vmoroz vmoroz left a comment

Choose a reason for hiding this comment

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

:shipit:

@kmelmon kmelmon added the AutoMerge Causes a PR to be automatically merged once all requirements are passed (label drives bot activity) label Apr 28, 2020
@ghost
Copy link

ghost commented Apr 28, 2020

Hello @kmelmon!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@kmelmon kmelmon merged commit ee00cce into microsoft:master Apr 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AutoMerge Causes a PR to be automatically merged once all requirements are passed (label drives bot activity)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement i18nManager.allowRTL Implement i18nManager.forceRTL RN top-level window is laid out LTR in RTL locales

4 participants