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

[RNMobile][Android] Fix jumping keyboard when adding a new paragraph using "return" key #28101

Closed

Conversation

dratwas
Copy link
Contributor

@dratwas dratwas commented Jan 11, 2021

Description

After merging of #27737 the issue with the jumping keyboard was introduced. When splitting a paragraph or adding a new one by using "return" key the keyboard jumps because the paragraph that is selected is unmounted and the new one is created. (we call blur in componentWillUnmount)

I think that we don't need to create a new paragraph (or others block but I started from a paragraph) for the text that is before the caret. We could use the same block and set the correct attribute to it, or create a new one but with the same clientId. Thanks to that we will avoid unnecessary unmounting and mounting of the paragraph that is selected.

Outdated Unfortunately, I couldn't find an option to create or clone blocks with a specific clientID. In this PR I added a possibility to set clientID to the createBlock. I had also added one argument to the `onSplit` to determine if the returned block should have the same clientID as the selected block.

I'm not sure if it is the correct way to do that and if someone knows how to achieve that in another, more elegant way, please let me know.

In this PR I use the original block but with different attributes.content depending on the passed value in onSplit function.

This fixes also #26252

How has this been tested?

Screenshots

Types of changes

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.

@github-actions
Copy link

github-actions bot commented Jan 11, 2021

Size Change: +66.3 kB (+5%) 🔍

Total Size: 1.37 MB

Filename Size Change
build/annotations/index.js 3.77 kB -29 B (-1%)
build/api-fetch/index.js 3.4 kB -11 B (0%)
build/autop/index.js 2.84 kB +2 B (0%)
build/blob/index.js 665 B +1 B (0%)
build/block-directory/index.js 9.08 kB +41 B (0%)
build/block-editor/index.js 123 kB -7.46 kB (-6%)
build/block-editor/style-rtl.css 11.9 kB +582 B (+5%) 🔍
build/block-editor/style.css 11.9 kB +589 B (+5%) 🔍
build/block-library/blocks/archives/editor-rtl.css 61 B -135 B (-69%) 🏆
build/block-library/blocks/archives/editor.css 60 B -136 B (-69%) 🏆
build/block-library/blocks/audio/editor-rtl.css 58 B -136 B (-70%) 🏆
build/block-library/blocks/audio/editor.css 58 B -136 B (-70%) 🏆
build/block-library/blocks/audio/style-rtl.css 103 B -122 B (-54%) 🏆
build/block-library/blocks/audio/style.css 103 B -122 B (-54%) 🏆
build/block-library/blocks/block/editor-rtl.css 161 B -122 B (-43%) 🎉
build/block-library/blocks/block/editor.css 161 B -122 B (-43%) 🎉
build/block-library/blocks/button/editor-rtl.css 475 B -101 B (-18%) 👏
build/block-library/blocks/button/editor.css 474 B -103 B (-18%) 👏
build/block-library/blocks/button/style-rtl.css 447 B -105 B (-19%) 👏
build/block-library/blocks/button/style.css 447 B -105 B (-19%) 👏
build/block-library/blocks/buttons/editor-rtl.css 227 B -118 B (-34%) 🎉
build/block-library/blocks/buttons/editor.css 227 B -119 B (-34%) 🎉
build/block-library/blocks/buttons/style-rtl.css 297 B -122 B (-29%) 🎉
build/block-library/blocks/buttons/style.css 297 B -122 B (-29%) 🎉
build/block-library/blocks/calendar/style-rtl.css 208 B -111 B (-35%) 🎉
build/block-library/blocks/calendar/style.css 208 B -111 B (-35%) 🎉
build/block-library/blocks/categories/editor-rtl.css 84 B -126 B (-60%) 🏆
build/block-library/blocks/categories/editor.css 83 B -126 B (-60%) 🏆
build/block-library/blocks/categories/style-rtl.css 79 B -129 B (-62%) 🏆
build/block-library/blocks/categories/style.css 79 B -129 B (-62%) 🏆
build/block-library/blocks/code/style-rtl.css 90 B -126 B (-58%) 🏆
build/block-library/blocks/code/style.css 90 B -126 B (-58%) 🏆
build/block-library/blocks/columns/editor-rtl.css 190 B -110 B (-37%) 🎉
build/block-library/blocks/columns/editor.css 190 B -109 B (-36%) 🎉
build/block-library/blocks/columns/style-rtl.css 421 B -108 B (-20%) 🎉
build/block-library/blocks/columns/style.css 421 B -107 B (-20%) 🎉
build/block-library/blocks/cover/editor-rtl.css 392 B -116 B (-23%) 🎉
build/block-library/blocks/cover/editor.css 393 B -113 B (-22%) 🎉
build/block-library/blocks/cover/style-rtl.css 1.25 kB -76 B (-6%)
build/block-library/blocks/cover/style.css 1.25 kB -74 B (-6%)
build/block-library/blocks/embed/editor-rtl.css 486 B -108 B (-18%) 👏
build/block-library/blocks/embed/editor.css 486 B -109 B (-18%) 👏
build/block-library/blocks/embed/style-rtl.css 375 B -114 B (-23%) 🎉
build/block-library/blocks/embed/style.css 375 B -114 B (-23%) 🎉
build/block-library/blocks/file/editor-rtl.css 199 B -115 B (-37%) 🎉
build/block-library/blocks/file/editor.css 198 B -115 B (-37%) 🎉
build/block-library/blocks/file/style-rtl.css 248 B -104 B (-30%) 🎉
build/block-library/blocks/file/style.css 248 B -104 B (-30%) 🎉
build/block-library/blocks/freeform/editor-rtl.css 2.45 kB -98 B (-4%)
build/block-library/blocks/freeform/editor.css 2.45 kB -99 B (-4%)
build/block-library/blocks/gallery/editor-rtl.css 679 B -70 B (-9%)
build/block-library/blocks/gallery/editor.css 679 B -71 B (-9%)
build/block-library/blocks/gallery/style-rtl.css 1.07 kB -106 B (-9%)
build/block-library/blocks/gallery/style.css 1.06 kB -106 B (-9%)
build/block-library/blocks/group/editor-rtl.css 318 B -115 B (-27%) 🎉
build/block-library/blocks/group/editor.css 317 B -115 B (-27%) 🎉
build/block-library/blocks/group/style-rtl.css 57 B -133 B (-70%) 🏆
build/block-library/blocks/group/style.css 57 B -133 B (-70%) 🏆
build/block-library/blocks/heading/editor-rtl.css 129 B -119 B (-48%) 🎉
build/block-library/blocks/heading/editor.css 129 B -119 B (-48%) 🎉
build/block-library/blocks/heading/style-rtl.css 76 B -136 B (-64%) 🏆
build/block-library/blocks/heading/style.css 76 B -136 B (-64%) 🏆
build/block-library/blocks/html/editor-rtl.css 281 B -103 B (-27%) 🎉
build/block-library/blocks/html/editor.css 281 B -104 B (-27%) 🎉
build/block-library/blocks/image/editor-rtl.css 717 B -84 B (-10%) 👏
build/block-library/blocks/image/editor.css 716 B -84 B (-10%) 👏
build/block-library/blocks/image/style-rtl.css 477 B -92 B (-16%) 👏
build/block-library/blocks/image/style.css 478 B -92 B (-16%) 👏
build/block-library/blocks/latest-comments/editor-rtl.css 159 B -118 B (-43%) 🎉
build/block-library/blocks/latest-comments/editor.css 158 B -117 B (-43%) 🎉
build/block-library/blocks/latest-comments/style-rtl.css 269 B -113 B (-30%) 🎉
build/block-library/blocks/latest-comments/style.css 269 B -113 B (-30%) 🎉
build/block-library/blocks/latest-posts/editor-rtl.css 137 B -117 B (-46%) 🎉
build/block-library/blocks/latest-posts/editor.css 137 B -117 B (-46%) 🎉
build/block-library/blocks/latest-posts/style-rtl.css 523 B -111 B (-18%) 👏
build/block-library/blocks/latest-posts/style.css 522 B -112 B (-18%) 👏
build/block-library/blocks/list/editor-rtl.css 65 B -138 B (-68%) 🏆
build/block-library/blocks/list/editor.css 65 B -138 B (-68%) 🏆
build/block-library/blocks/list/style-rtl.css 63 B -138 B (-69%) 🏆
build/block-library/blocks/list/style.css 63 B -138 B (-69%) 🏆
build/block-library/blocks/media-text/editor-rtl.css 191 B -120 B (-39%) 🎉
build/block-library/blocks/media-text/editor.css 191 B -120 B (-39%) 🎉
build/block-library/blocks/media-text/style-rtl.css 535 B -107 B (-17%) 👏
build/block-library/blocks/media-text/style.css 532 B -108 B (-17%) 👏
build/block-library/blocks/more/editor-rtl.css 434 B -111 B (-20%) 🎉
build/block-library/blocks/more/editor.css 434 B -111 B (-20%) 🎉
build/block-library/blocks/navigation-link/editor-rtl.css 392 B -111 B (-22%) 🎉
build/block-library/blocks/navigation-link/editor.css 394 B -110 B (-22%) 🎉
build/block-library/blocks/navigation-link/style-rtl.css 704 B -101 B (-13%) 👏
build/block-library/blocks/navigation-link/style.css 702 B -101 B (-13%) 👏
build/block-library/blocks/navigation/editor-rtl.css 1.38 kB -2 B (0%)
build/block-library/blocks/navigation/editor.css 1.37 kB -6 B (0%)
build/block-library/blocks/navigation/style-rtl.css 171 B -103 B (-38%) 🎉
build/block-library/blocks/navigation/style.css 171 B -103 B (-38%) 🎉
build/block-library/blocks/nextpage/editor-rtl.css 395 B -112 B (-22%) 🎉
build/block-library/blocks/nextpage/editor.css 395 B -112 B (-22%) 🎉
build/block-library/blocks/paragraph/editor-rtl.css 109 B -127 B (-54%) 🏆
build/block-library/blocks/paragraph/editor.css 109 B -127 B (-54%) 🏆
build/block-library/blocks/paragraph/style-rtl.css 273 B -78 B (-22%) 🎉
build/block-library/blocks/paragraph/style.css 273 B -79 B (-22%) 🎉
build/block-library/blocks/post-author/editor-rtl.css 209 B -120 B (-36%) 🎉
build/block-library/blocks/post-author/editor.css 209 B -120 B (-36%) 🎉
build/block-library/blocks/post-author/style-rtl.css 183 B -120 B (-40%) 🎉
build/block-library/blocks/post-author/style.css 184 B -119 B (-39%) 🎉
build/block-library/blocks/post-comments-form/style-rtl.css 249 B -109 B (-30%) 🎉
build/block-library/blocks/post-comments-form/style.css 249 B -109 B (-30%) 🎉
build/block-library/blocks/post-content/editor-rtl.css 139 B -123 B (-47%) 🎉
build/block-library/blocks/post-content/editor.css 139 B -123 B (-47%) 🎉
build/block-library/blocks/post-excerpt/editor-rtl.css 73 B -133 B (-65%) 🏆
build/block-library/blocks/post-excerpt/editor.css 73 B -133 B (-65%) 🏆
build/block-library/blocks/post-featured-image/editor-rtl.css 338 B -115 B (-25%) 🎉
build/block-library/blocks/post-featured-image/editor.css 338 B -115 B (-25%) 🎉
build/block-library/blocks/post-featured-image/style-rtl.css 100 B -123 B (-55%) 🏆
build/block-library/blocks/post-featured-image/style.css 100 B -123 B (-55%) 🏆
build/block-library/blocks/preformatted/style-rtl.css 63 B -130 B (-67%) 🏆
build/block-library/blocks/preformatted/style.css 63 B -130 B (-67%) 🏆
build/block-library/blocks/pullquote/editor-rtl.css 183 B -121 B (-40%) 🎉
build/block-library/blocks/pullquote/editor.css 183 B -121 B (-40%) 🎉
build/block-library/blocks/pullquote/style-rtl.css 316 B -112 B (-26%) 🎉
build/block-library/blocks/pullquote/style.css 316 B -112 B (-26%) 🎉
build/block-library/blocks/query-loop/editor-rtl.css 90 B -127 B (-59%) 🏆
build/block-library/blocks/query-loop/editor.css 89 B -127 B (-59%) 🏆
build/block-library/blocks/query-loop/style-rtl.css 315 B -112 B (-26%) 🎉
build/block-library/blocks/query-loop/style.css 317 B -112 B (-26%) 🎉
build/block-library/blocks/query/editor-rtl.css 159 B -120 B (-43%) 🎉
build/block-library/blocks/query/editor.css 160 B -119 B (-43%) 🎉
build/block-library/blocks/quote/editor-rtl.css 61 B -134 B (-69%) 🏆
build/block-library/blocks/quote/editor.css 61 B -134 B (-69%) 🏆
build/block-library/blocks/quote/style-rtl.css 169 B -115 B (-40%) 🎉
build/block-library/blocks/quote/style.css 169 B -116 B (-41%) 🎉
build/block-library/blocks/rss/editor-rtl.css 201 B -106 B (-35%) 🎉
build/block-library/blocks/rss/editor.css 202 B -107 B (-35%) 🎉
build/block-library/blocks/rss/style-rtl.css 290 B -104 B (-26%) 🎉
build/block-library/blocks/rss/style.css 290 B -103 B (-26%) 🎉
build/block-library/blocks/search/editor-rtl.css 165 B -120 B (-42%) 🎉
build/block-library/blocks/search/editor.css 165 B -120 B (-42%) 🎉
build/block-library/blocks/search/style-rtl.css 342 B -112 B (-25%) 🎉
build/block-library/blocks/search/style.css 344 B -112 B (-25%) 🎉
build/block-library/blocks/separator/editor-rtl.css 99 B -130 B (-57%) 🏆
build/block-library/blocks/separator/editor.css 99 B -130 B (-57%) 🏆
build/block-library/blocks/separator/style-rtl.css 236 B -116 B (-33%) 🎉
build/block-library/blocks/separator/style.css 236 B -116 B (-33%) 🎉
build/block-library/blocks/shortcode/editor-rtl.css 504 B -99 B (-16%) 👏
build/block-library/blocks/shortcode/editor.css 504 B -99 B (-16%) 👏
build/block-library/blocks/site-logo/editor-rtl.css 201 B -120 B (-37%) 🎉
build/block-library/blocks/site-logo/editor.css 201 B -120 B (-37%) 🎉
build/block-library/blocks/site-logo/style-rtl.css 117 B -121 B (-51%) 🏆
build/block-library/blocks/site-logo/style.css 117 B -121 B (-51%) 🏆
build/block-library/blocks/social-link/editor-rtl.css 164 B -119 B (-42%) 🎉
build/block-library/blocks/social-link/editor.css 165 B -118 B (-42%) 🎉
build/block-library/blocks/social-links/editor-rtl.css 711 B -100 B (-12%) 👏
build/block-library/blocks/social-links/editor.css 712 B -98 B (-12%) 👏
build/block-library/blocks/social-links/style-rtl.css 1.37 kB -67 B (-5%)
build/block-library/blocks/social-links/style.css 1.37 kB -66 B (-5%)
build/block-library/blocks/spacer/editor-rtl.css 302 B -88 B (-23%) 🎉
build/block-library/blocks/spacer/editor.css 302 B -88 B (-23%) 🎉
build/block-library/blocks/spacer/style-rtl.css 48 B -136 B (-74%) 🏆
build/block-library/blocks/spacer/style.css 48 B -136 B (-74%) 🏆
build/block-library/blocks/subhead/editor-rtl.css 99 B -124 B (-56%) 🏆
build/block-library/blocks/subhead/editor.css 99 B -124 B (-56%) 🏆
build/block-library/blocks/subhead/style-rtl.css 80 B -130 B (-62%) 🏆
build/block-library/blocks/subhead/style.css 80 B -130 B (-62%) 🏆
build/block-library/blocks/table/editor-rtl.css 489 B -104 B (-18%) 👏
build/block-library/blocks/table/editor.css 489 B -104 B (-18%) 👏
build/block-library/blocks/table/style-rtl.css 386 B -115 B (-23%) 🎉
build/block-library/blocks/table/style.css 386 B -115 B (-23%) 🎉
build/block-library/blocks/tag-cloud/editor-rtl.css 118 B -119 B (-50%) 🏆
build/block-library/blocks/tag-cloud/editor.css 118 B -117 B (-50%) 🏆
build/block-library/blocks/tag-cloud/style-rtl.css 94 B -127 B (-57%) 🏆
build/block-library/blocks/tag-cloud/style.css 94 B -127 B (-57%) 🏆
build/block-library/blocks/template-part/editor-rtl.css 680 B -34 B (-5%)
build/block-library/blocks/template-part/editor.css 679 B -35 B (-5%)
build/block-library/blocks/text-columns/editor-rtl.css 95 B -125 B (-57%) 🏆
build/block-library/blocks/text-columns/editor.css 95 B -125 B (-57%) 🏆
build/block-library/blocks/text-columns/style-rtl.css 166 B -117 B (-41%) 🎉
build/block-library/blocks/text-columns/style.css 166 B -117 B (-41%) 🎉
build/block-library/blocks/verse/editor-rtl.css 62 B -132 B (-68%) 🏆
build/block-library/blocks/verse/editor.css 62 B -132 B (-68%) 🏆
build/block-library/blocks/verse/style-rtl.css 87 B -127 B (-59%) 🏆
build/block-library/blocks/verse/style.css 87 B -127 B (-59%) 🏆
build/block-library/blocks/video/editor-rtl.css 504 B -113 B (-18%) 👏
build/block-library/blocks/video/editor.css 503 B -114 B (-18%) 👏
build/block-library/blocks/video/style-rtl.css 193 B -110 B (-36%) 🎉
build/block-library/blocks/video/style.css 193 B -111 B (-37%) 🎉
build/block-library/editor-rtl.css 9.06 kB +127 B (+1%)
build/block-library/editor.css 9.05 kB +112 B (+1%)
build/block-library/index.js 143 kB -7.11 kB (-5%)
build/block-library/style-rtl.css 8.61 kB +76 B (+1%)
build/block-library/style.css 8.61 kB +79 B (+1%)
build/block-library/theme-rtl.css 748 B -112 B (-13%) 👏
build/block-library/theme.css 748 B -112 B (-13%) 👏
build/block-serialization-default-parser/index.js 1.88 kB -2 B (0%)
build/blocks/index.js 48.3 kB +251 B (+1%)
build/components/index.js 274 kB +102 kB (+60%) 🆘
build/components/style-rtl.css 15.5 kB +52 B (0%)
build/components/style.css 15.5 kB +48 B (0%)
build/compose/index.js 11.2 kB -85 B (-1%)
build/core-data/index.js 15.2 kB +107 B (+1%)
build/data/index.js 8.97 kB +3 B (0%)
build/deprecated/index.js 769 B +1 B (0%)
build/dom/index.js 4.93 kB -17 B (0%)
build/edit-navigation/index.js 11.1 kB -20 B (0%)
build/edit-post/index.js 306 kB -32 B (0%)
build/edit-post/style-rtl.css 6.51 kB -127 B (-2%)
build/edit-post/style.css 6.5 kB -124 B (-2%)
build/edit-site/index.js 24 kB +107 B (0%)
build/edit-site/style-rtl.css 4.01 kB -22 B (-1%)
build/edit-site/style.css 4.01 kB -21 B (-1%)
build/edit-widgets/index.js 23.6 kB -2.44 kB (-9%)
build/edit-widgets/style-rtl.css 3.17 kB -48 B (-1%)
build/edit-widgets/style.css 3.18 kB -45 B (-1%)
build/editor/editor-styles-rtl.css 658 B +182 B (+38%) 🚨
build/editor/editor-styles.css 660 B +182 B (+38%) 🚨
build/editor/index.js 41.8 kB -955 B (-2%)
build/element/index.js 4.62 kB -7 B (0%)
build/format-library/index.js 6.77 kB +19 B (0%)
build/format-library/style-rtl.css 637 B +17 B (+3%)
build/format-library/style.css 639 B +18 B (+3%)
build/hooks/index.js 2.27 kB -1 B (0%)
build/i18n/index.js 3.56 kB -2 B (0%)
build/is-shallow-equal/index.js 699 B +1 B (0%)
build/keyboard-shortcuts/index.js 2.53 kB -7 B (0%)
build/keycodes/index.js 1.93 kB -10 B (-1%)
build/list-reusable-blocks/index.js 3.14 kB -9 B (0%)
build/media-utils/index.js 5.32 kB +2 B (0%)
build/notices/index.js 1.85 kB -5 B (0%)
build/nux/index.js 3.41 kB -19 B (-1%)
build/plugins/index.js 2.54 kB -5 B (0%)
build/primitives/index.js 1.42 kB -12 B (-1%)
build/priority-queue/index.js 789 B -1 B (0%)
build/redux-routine/index.js 2.84 kB +3 B (0%)
build/rich-text/index.js 13.4 kB -65 B (0%)
build/server-side-render/index.js 2.76 kB -17 B (-1%)
build/shortcode/index.js 1.7 kB +1 B (0%)
build/url/index.js 3.02 kB -4 B (0%)
build/viewport/index.js 1.86 kB -2 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/block-directory/style-rtl.css 1.01 kB 0 B
build/block-directory/style.css 1.01 kB 0 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B 0 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B 0 B
build/block-library/blocks/query-pagination/editor-rtl.css 270 B 0 B
build/block-library/blocks/query-pagination/editor.css 262 B 0 B
build/block-library/blocks/query-pagination/style-rtl.css 168 B 0 B
build/block-library/blocks/query-pagination/style.css 168 B 0 B
build/block-library/common-rtl.css 1.01 kB 0 B
build/block-library/common.css 1.01 kB 0 B
build/block-serialization-spec-parser/index.js 3.06 kB 0 B
build/data-controls/index.js 830 B 0 B
build/date/index.js 31.8 kB 0 B
build/dom-ready/index.js 571 B 0 B
build/edit-navigation/style-rtl.css 938 B 0 B
build/edit-navigation/style.css 944 B 0 B
build/editor/style-rtl.css 3.89 kB 0 B
build/editor/style.css 3.89 kB 0 B
build/escape-html/index.js 735 B 0 B
build/html-entities/index.js 623 B 0 B
build/list-reusable-blocks/style-rtl.css 629 B 0 B
build/list-reusable-blocks/style.css 628 B 0 B
build/nux/style-rtl.css 731 B 0 B
build/nux/style.css 727 B 0 B
build/reusable-blocks/index.js 2.92 kB 0 B
build/token-list/index.js 1.27 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.22 kB 0 B

compressed-size-action

@dratwas dratwas marked this pull request as ready for review January 13, 2021 15:00
@dratwas dratwas requested review from youknowriad and removed request for talldan, ajitbohra and guarani January 18, 2021 09:38
Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

While I like the fact that when splitting, the original block should keep its id, I'm not sure I like how it's done here. I'd love @ellatrix's input on this PR.

packages/blocks/src/api/factory.js Outdated Show resolved Hide resolved
@dratwas
Copy link
Contributor Author

dratwas commented Jan 25, 2021

Hey, @youknowriad could you please take a look one more time? I have changed the way I return the "original" block from onSplit. In this approach, I don't need changes in createBlock anymore.

@@ -61,7 +69,17 @@ function HeadingEdit( {
value={ content }
onChange={ ( value ) => setAttributes( { content: value } ) }
onMerge={ mergeBlocks }
onSplit={ ( value ) => {
onSplit={ ( value, keepId ) => {
if ( keepId ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really want to have the "keepId" argument? I mean why not just replace the createBlock( 'core/heading' call a few lines down here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we still need the keepId since it determines if we should use the original block or create a new one. W/o that we wouldn't know if we should create a new block or make changes in the "original" one. I am wondering if I could use getBlock in the rich-text component and use onSplit only for creating new blocks but I'm not sure if it's a good way because we would lose the "flexibility" in that mechanism (currently it could work differently for heading, paragraph, list etc).

Copy link
Member

Choose a reason for hiding this comment

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

Adding keepId is a horrible API. We should go for one or the other for all cases. Any alternatives we can explore here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding keepId is a horrible API. We should go for one or the other for all cases.

Can you elaborate a bit? :)

IMHO it is still better than removing the original block and replacing it. Even from the performance perspective update is faster than unmount + mount (we use the clientId as a key in our block-list).

Any alternatives we can explore here?

As I mentioned I was wondering if it could be done inside rich-text/index.js. We could get block and change attributes inside instead of calling onSplit for the original block but i haven't investigated it.

content: value || '',
},
};
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question as above

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we do the same for the web version of this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we still need the keepId, unless you have a different concept for it.

I already added it to the web version :)

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

Well this new approach sounds simpler and easier to land (no framework impact)

@ellatrix
Copy link
Member

Why is the keyboard jumping? Because the original paragraph is removed?

The reason we're creating two new paragraphs is because one split action should be one change in the store (and so one undo level for the user). The way we achieve that right now is by replacing the current paragraph with two new ones. Alternatively we could create a new action for the store to split a block in one go.

I don't like the current approach of having two different behaviours for web and mobile at all. This is just making our APIs more complex and harder to use.

@dratwas
Copy link
Contributor Author

dratwas commented Jan 26, 2021

Why is the keyboard jumping? Because the original paragraph is removed?

Exactly. The original paragraph is removed so that means the selected block is unmounted, the blur is invoked, and the keyboard starts to hide. Then the new paragraph is focused and the keyboard opens again.

The reason we're creating two new paragraphs is because one split action should be one change in the store (and so one undo level for the user). The way we achieve that right now is by replacing the current paragraph with two new ones. Alternatively we could create a new action for the store to split a block in one go.

This still works in the same way. We replace the original paragraph with two others but the "first" one has the same clientID as the original one. Thanks to that the original block is not unmounted and mounted but only updated. It is still done in one replace action and creates one undo level.

I don't like the current approach of having two different behaviours for web and mobile at all. This is just making our APIs more complex and harder to use.

Hmmm, there is no different behavior for web and mobile. This works the same for mobile and web. The heading block has shared code so it has to be the same and I also updated the onSplit in the paragraph block.

@ellatrix
Copy link
Member

Why do we need the keep ID parameter then? Can't we always keep ID?

@dratwas
Copy link
Contributor Author

dratwas commented Jan 26, 2021

Why do we need the keep ID parameter then? Can't we always keep ID?

We can not because the onSplit is used for creating the new paragraph as well and we would end with two blocks with the same clientID.

@ellatrix
Copy link
Member

I created a PR to handle keeping the ID #28505

@dratwas dratwas closed this Jan 27, 2021
@youknowriad youknowriad deleted the rnmobile/rich-text/jumping-keyboard-when-adding-new branch January 27, 2021 17:04
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.

None yet

3 participants