Skip to content

[RNMobile] Add missing RTL support for some mobile components#21502

Merged
jbinda merged 16 commits intomasterfrom
rnmobile/fix/rtl-support
May 6, 2020
Merged

[RNMobile] Add missing RTL support for some mobile components#21502
jbinda merged 16 commits intomasterfrom
rnmobile/fix/rtl-support

Conversation

@jbinda
Copy link
Copy Markdown
Contributor

@jbinda jbinda commented Apr 9, 2020

Description

This PR adds missing RTL support for buttons in GalleryImage and redo/undo buttons in HeaderToolbar on mobile side.

TODOS:

  • - rotate GalleryImage movers buttons in RTL mode
  • - rotate HeaderToolbar redo/undo buttons in RTL mode
  • - Inner block floating toolbar: Arrows icons need to be flipped (this is implemented in FloatingToolbar PR here)
  • - List block icons need to be flipped (need to add icon for flipped numbered list - done )
  • - Default text alignment icon is inconsistent with default RTL language alignment
  • - Switch icons for positioning in Media-Text block in RTL mode

EXCLUDED (according to this comment):

  • - List block has the bullets in the opposite side.
  • - All RichText placeholders seem to be missing (in LTR mode it also missing when align right is set - I think its more RichText issue rather that RTL)

Please also refer to:
Related gutenberg-mobile PR
Related gutenberg-mobile issue

How has this been tested?

  1. Follow reproduce step described in related issue
  2. Expect in RTL mode icons in buttons has proper orientation
  3. Expect in LTR(default) mode icons in buttons do not change its orientation

To verify point 2 and 3 please follow screenshots provided in related issue description

Screenshots

LTR vs RTL mode
Gallery

MediaText
Screenshot 2020-04-14 at 14 53 35
Screenshot 2020-04-14 at 14 53 21

Paragraph default alignment icon
Screenshot 2020-04-14 at 14 56 00

Screenshot 2020-04-14 at 14 55 56

List icons
Screenshot 2020-04-17 at 09 08 38
Screenshot 2020-04-17 at 09 08 31

Types of changes

Change - add RTL support for below components:

  • GalleryImage movers buttons
  • HeaderToolbar redo/undo buttons
  • List block icons for alignment and indentation
  • Default text alignment icon in paragraph
  • Icons for media positioning in Media-Text block

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@jbinda jbinda added [Type] Enhancement A suggestion for improvement. Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) labels Apr 9, 2020
@jbinda jbinda requested review from Tug, etoledom and pinarol April 9, 2020 10:43
@jbinda jbinda self-assigned this Apr 9, 2020
@jbinda
Copy link
Copy Markdown
Contributor Author

jbinda commented Apr 9, 2020

I also wonder if we shouldn't move I18nManager.isRTL check to some global hook and use it similar to withViewportMatch (e.g. withRTLSupport) when exporting component.

@etoledom, @Tug, @dratwas WDYT ?

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 9, 2020

Size Change: -3.61 kB (0%)

Total Size: 821 kB

Filename Size Change
build/annotations/index.js 3.62 kB +1 B
build/api-fetch/index.js 4.08 kB -3 B (0%)
build/block-directory/index.js 6.6 kB +1 B
build/block-editor/index.js 101 kB -5.58 kB (5%)
build/block-editor/style-rtl.css 10.2 kB +16 B (0%)
build/block-editor/style.css 10.2 kB +16 B (0%)
build/block-library/editor-rtl.css 7.08 kB +4 B (0%)
build/block-library/editor.css 7.08 kB +4 B (0%)
build/block-library/index.js 115 kB +414 B (0%)
build/block-library/style-rtl.css 7.24 kB +23 B (0%)
build/block-library/style.css 7.25 kB +26 B (0%)
build/blocks/index.js 48.1 kB +1 B
build/components/index.js 179 kB +7 B (0%)
build/compose/index.js 6.66 kB +1 B
build/core-data/index.js 11.4 kB -13 B (0%)
build/data/index.js 8.44 kB +4 B (0%)
build/date/index.js 5.47 kB -1 B
build/edit-navigation/index.js 4.05 kB +1 B
build/edit-post/index.js 28.1 kB +1 B
build/edit-post/style-rtl.css 12.2 kB +3 B (0%)
build/edit-post/style.css 12.2 kB +3 B (0%)
build/edit-site/index.js 12.3 kB +873 B (7%) 🔍
build/edit-site/style-rtl.css 5.19 kB +14 B (0%)
build/edit-site/style.css 5.2 kB +15 B (0%)
build/edit-widgets/index.js 8.33 kB +557 B (6%) 🔍
build/editor/index.js 44.3 kB -9 B (0%)
build/escape-html/index.js 734 B +1 B
build/format-library/index.js 7.63 kB -1 B
build/keyboard-shortcuts/index.js 2.51 kB +2 B (0%)
build/keycodes/index.js 1.94 kB +1 B
build/media-utils/index.js 5.29 kB -1 B
build/notices/index.js 1.79 kB +1 B
build/primitives/index.js 1.5 kB +1 B
build/redux-routine/index.js 2.85 kB +3 B (0%)
build/server-side-render/index.js 2.67 kB -1 B
build/shortcode/index.js 1.7 kB +1 B
build/token-list/index.js 1.28 kB +1 B
build/url/index.js 4.02 kB -1 B
build/warning/index.js 1.14 kB -1 B
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.02 kB 0 B
build/autop/index.js 2.82 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/style-rtl.css 760 B 0 B
build/block-directory/style.css 761 B 0 B
build/block-library/theme-rtl.css 683 B 0 B
build/block-library/theme.css 685 B 0 B
build/block-serialization-default-parser/index.js 1.88 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/components/style-rtl.css 16.9 kB 0 B
build/components/style.css 16.9 kB 0 B
build/data-controls/index.js 1.29 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 3.1 kB 0 B
build/edit-navigation/style-rtl.css 485 B 0 B
build/edit-navigation/style.css 485 B 0 B
build/edit-widgets/style-rtl.css 4.67 kB 0 B
build/edit-widgets/style.css 4.66 kB 0 B
build/editor/editor-styles-rtl.css 428 B 0 B
build/editor/editor-styles.css 431 B 0 B
build/editor/style-rtl.css 5.07 kB 0 B
build/editor/style.css 5.08 kB 0 B
build/element/index.js 4.65 kB 0 B
build/format-library/style-rtl.css 502 B 0 B
build/format-library/style.css 502 B 0 B
build/hooks/index.js 2.13 kB 0 B
build/html-entities/index.js 622 B 0 B
build/i18n/index.js 3.56 kB 0 B
build/is-shallow-equal/index.js 710 B 0 B
build/list-reusable-blocks/index.js 3.13 kB 0 B
build/list-reusable-blocks/style-rtl.css 226 B 0 B
build/list-reusable-blocks/style.css 226 B 0 B
build/nux/index.js 3.4 kB 0 B
build/nux/style-rtl.css 616 B 0 B
build/nux/style.css 613 B 0 B
build/plugins/index.js 2.56 kB 0 B
build/priority-queue/index.js 789 B 0 B
build/rich-text/index.js 14.8 kB 0 B
build/viewport/index.js 1.84 kB 0 B
build/wordcount/index.js 1.18 kB 0 B

compressed-size-action

@jbinda jbinda changed the title [RNMobile] Add missing RTL support for some mobile buttons [RNMobile] Add missing RTL support for some mobile components Apr 9, 2020
@jbinda jbinda removed the [Type] Enhancement A suggestion for improvement. label Apr 9, 2020
@jbinda jbinda requested a review from dratwas April 9, 2020 14:36
Copy link
Copy Markdown
Contributor

@etoledom etoledom left a comment

Choose a reason for hiding this comment

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

Thank you for this PR @jbinda !

The gallery arrows now look and works great on RTL! 🎉

There's still a problem with undo/redo: Since it's a representation of time over the X axis, we need to respect the past (undo) going to the left and the future (redo) going to the right. The directionality representation of time doesn't change on RTL languages.

I also left a comment with an alternative implementation idea. I'd like to know your opinion about it!

select( 'core/editor' ).getEditorSettings().richEditingEnabled,
isTextModeEnabled:
select( 'core/edit-post' ).getEditorMode() === 'text',
isRTL: I18nManager.isRTL,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder if we could use something like isRTL: select( 'core/block-editor' ).getSettings().isRTL, here.
We are not setting this property, but maybe we could overwrite it?

I did a test overwriting settings.isRTL on BlockEditorProvider when it mounts and it works. Not sure if it's the best place to do this though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think that would be good approach according to my previous comment here because it is commonly used on web side.

I also saw this check on web side const isRTL = () => document.documentElement.dir === 'rtl';

Do you think it is aligned with the settings.isRTL ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Right! I missed that comment, sorry about that!

This isRTL definition seems to be internal of the component components/src/date-time/date.js.

What I think settings.isRTL does is to apply the RTL layout depending on the language setting set to the WordPress Interface, independent of the browser language, so it's what is mostly used in the project. I believe we would want to use it too.

An example of usage is on the Block Mover

What I'm not sure is where should we call setSettings with the correct isRTL value for mobile. Another chance for this is to set it as soon as the stores are configured, together with setupLocale on gutenberg-mobile repo.

Maybe @Tug will have a better idea about this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We might also pass it from the native apps as an init setting in the same way it is set on web, but I don't think is really needed. 🤔

I wonder if we could inject this isRTL setting on the initial props when they arrive to RN, before the editor is set up. Sounds a bit hacky though 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

List component has shared edit.js file between web and mobile so having isRTL in getSettings() does make sense. However as you said I'm not sure if place where I inject it to provider is the proper one (see here)

@Tug do you have any opinion about this ?

@jbinda
Copy link
Copy Markdown
Contributor Author

jbinda commented Apr 14, 2020

There's still a problem with undo/redo: Since it's a representation of time over the X axis, we need to respect the past (undo) going to the left and the future (redo) going to the right. The directionality representation of time doesn't change on RTL languages.

Ok, you're right I replace only the Icon and the whole button should be flipped. I have applied the fix :)

Comment on lines +23 to +26
this.props.updateSettings( {
...this.props.settings,
isRTL: I18nManager.isRTL,
} );
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@etoledom according to our conversation on isRTL selector I have manage to add isRTL to settings in PBLockEditorProvider this way.

Using it in blocks is very readable and intuitive. Also we don't need to use different markup on web vs native site - it's cross platform after implement in this way. I have refactor other block to align with this - you can check this out.

However I think we need to confirm if it's good place to do this as you mentioned earlier.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@Tug could you please take a look at this bit?

Copy link
Copy Markdown
Contributor

@Tug Tug May 4, 2020

Choose a reason for hiding this comment

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

I believe it's the right approach if we need to update this setting dynamically from the editor itself.

What's missing right now though it the ability to "refresh" the editor when the settings change. If we look at the post editor we can see that the EditorProvider get the settings from the editor.
On the web, those settings are given from the PHP side of the plugin. So similarly we would need to pass it as a props from the parent apps.

Concerning isRTL, I guess we can use I18nManager.isRTL instead for now. What do you think about simply overwriting this setting in the native post editor:

At https://github.com/WordPress/gutenberg/blob/master/packages/edit-post/src/editor.native.js#L47
have:

		settings = {
			...settings,
			isRTL: I18nManager.isRTL,
			hasFixedToolbar,
			focusMode,
		};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for checking this. I think it make sense. Let me provide changes and well see how it works

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@Tug @etoledom I have applied changes mentioned above. It works fine so if you can taka a look one more time on this and do not have any other remarks I think we can merge

@etoledom
Copy link
Copy Markdown
Contributor

Thank you @jbinda for the update!

Undo-redo looks perfect ✨

New changes looks pretty good too, congrats 🎉
The only thing is not sure I'd be comfortable shipping the ordered list icon if it's not the proper rtf icon. Shipping the backward 1 would be a bit awkward in my opinion.

Screenshot 2020-04-16 at 13 06 22.

@iamthomasbishop what do you think about it? Any idea when will we have the new proper icon for this? Thank you!

I noticed another issue, but I think this one is to be tackled separately since it's not related to RTL in particular (might be related to Aztec).

Screenshot 2020-04-16 at 13 09 07

The Quote block doesn't respect changes on alignment. This also happens on normal LTR layout. (We might have broken it at some point). cc @SergioEstevao @mchowning

@mchowning
Copy link
Copy Markdown
Contributor

mchowning commented Apr 16, 2020

I noticed another issue, but I think this one is to be tackled separately since it's not related to RTL in particular (might be related to Aztec). The Quote block doesn't respect changes on alignment. This also happens on normal LTR layout. (We might have broken it at some point)

Created an issue to track this. Thanks for spotting the problem @etoledom ! 🙇

I agree that this issue should not block this PR.

@iamthomasbishop
Copy link
Copy Markdown

what do you think about it? Any idea when will we have the new proper icon for this? Thank you!

@etoledom @jbinda I made some custom icons for the RTL scenarios. I haven't had a chance to propose them as part of the core GB icon set, so for now, perhaps we can use the ones I've dropped into the design docs.

Does this work? I think using RTL-specific icons is preferred over rotating but if we want to continue rotating certain ones, that's fine for now.

@jbinda
Copy link
Copy Markdown
Contributor Author

jbinda commented Apr 16, 2020

Does this work? I think using RTL-specific icons is preferred over rotating but if we want to continue rotating certain ones, that's fine for now.

I will give it a shot and let you know. I prepared rotated versions as new icon with suffix -rtl so it should be quick to replace with given icons. Thanks !

@jbinda
Copy link
Copy Markdown
Contributor Author

jbinda commented Apr 17, 2020

I have add the icons you shared @iamthomasbishop

Now it look like this:

Screenshot 2020-04-17 at 09 08 38

Screenshot 2020-04-17 at 09 08 31

@iamthomasbishop
Copy link
Copy Markdown

@jbinda Icons look great in the screenshots above. Aren't the bullets for the list supposed to align to the right side of the canvas for RTL? Maybe a known issue, I haven't had a chance to read all of the history here 😬

@jbinda
Copy link
Copy Markdown
Contributor Author

jbinda commented Apr 20, 2020

Aren't the bullets for the list supposed to align to the right side of the canvas for RTL?

Working on that. I think it's the only one think left in scope of this PR

@iamthomasbishop
Copy link
Copy Markdown

@jbinda Perfect! Thank you!

@dratwas
Copy link
Copy Markdown
Contributor

dratwas commented Apr 24, 2020

Working on that. I think it's the only one think left in scope of this PR

@jbinda I'm afraid that it needs to be done in Aztec.

@SergioEstevao
Copy link
Copy Markdown
Contributor

@jbinda I'm afraid that it needs to be done in Aztec.

Correct, I tried to implement this before, but one of the challenges was that the UITextView adapts the layout and rendering depending of the text language that is passed to it and/or the device system language.
If we now have an prop that say that we the block should be RTL or LTR we will need to pass this to the AztecView and then in native code trigger the necessary changes to adapt.

@dratwas
Copy link
Copy Markdown
Contributor

dratwas commented Apr 24, 2020

Yeah, so definitely it shouldn't be in the scope of this PR :)

@etoledom etoledom self-requested a review April 28, 2020 10:30
@jbinda
Copy link
Copy Markdown
Contributor Author

jbinda commented May 4, 2020

I have excluded 2 below task mentioned in PR description from scope of this project because of above conversation. It will be addressed separately.

EXCLUDED tasks:

  • - List block has the bullets in the opposite side.
  • - All RichText placeholders seem to be missing (in LTR mode it also missing when align right is set - I think its more RichText issue rather that RTL)

Copy link
Copy Markdown
Contributor

@Tug Tug left a comment

Choose a reason for hiding this comment

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

Code LGTM 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants