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] Use Reanimated in bottom sheet height animation #52563

Conversation

fluiddot
Copy link
Contributor

@fluiddot fluiddot commented Jul 12, 2023

What?

The main goal of this PR is to update the animation framework used to animate the bottom sheet's height. Currently, we use layout animations (reference) that will be replaced with Reanimated.

Why?

On Android, using layout animations can lead to inconsistent visual states when used in combination with React navigation. Specifically in the Image block, the content of the bottom sheet gets transparent after setting a custom URL.

Additionally, layout animations are experimental on Android, so it would be great to avoid them.

How?

The height was being animated using the function setHeight, which keeps the height value in the component's state and updates the styles, and then invoking performLayoutAnimation to execute the layout animation. This logic has been replaced using Reanimated's shared value to keep the height value, and withTiming in combination with useAnimatedStyle to animate the value. This implementation can be seen in 634b2fd.

Testing Instructions

Inconsistent visual state in "Link to" setting

  1. Open a post/page in the app.
  2. Add an Image block.
  3. Set an image.
  4. Open the block settings by tapping on the ⚙️ button.
  5. Tap on "Link to" option.
  6. Tap on "Custom URL" option.
  7. Type a URL.
  8. Tap on the ✔️ /Submit key in the keyboard.
  9. Observe that it navigates back to the block settings sheet.
  10. Observe that the "Link to" option displays the value "Custom URL".

Bottom sheet's height animation

NOTE: This covers a wide range of test cases, so we can't provide a specific case.

  1. Add different blocks.
  2. Open the block settings of each block.
  3. Navigate through different block settings.
  4. Observe that the bottom sheet's height is animated accordingly.

Testing Instructions for Keyboard

N/A

Screenshots or screencast

Android iOS
android-bottom-sheet-height-animation.mp4
ios-bottom-sheet-height-animation.mp4

@fluiddot fluiddot added [Type] Bug An existing feature does not function as intended Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) labels Jul 12, 2023
@fluiddot fluiddot self-assigned this Jul 12, 2023
@github-actions
Copy link

github-actions bot commented Jul 12, 2023

Size Change: 0 B

Total Size: 1.42 MB

ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 955 B
build/annotations/index.min.js 2.69 kB
build/api-fetch/index.min.js 2.28 kB
build/autop/index.min.js 2.1 kB
build/blob/index.min.js 451 B
build/block-directory/index.min.js 6.99 kB
build/block-directory/style-rtl.css 1.02 kB
build/block-directory/style.css 1.02 kB
build/block-editor/content-rtl.css 4.25 kB
build/block-editor/content.css 4.24 kB
build/block-editor/default-editor-styles-rtl.css 381 B
build/block-editor/default-editor-styles.css 381 B
build/block-editor/index.min.js 209 kB
build/block-editor/style-rtl.css 14.6 kB
build/block-editor/style.css 14.6 kB
build/block-library/blocks/archives/editor-rtl.css 61 B
build/block-library/blocks/archives/editor.css 60 B
build/block-library/blocks/archives/style-rtl.css 90 B
build/block-library/blocks/archives/style.css 90 B
build/block-library/blocks/audio/editor-rtl.css 150 B
build/block-library/blocks/audio/editor.css 150 B
build/block-library/blocks/audio/style-rtl.css 122 B
build/block-library/blocks/audio/style.css 122 B
build/block-library/blocks/audio/theme-rtl.css 126 B
build/block-library/blocks/audio/theme.css 126 B
build/block-library/blocks/avatar/editor-rtl.css 116 B
build/block-library/blocks/avatar/editor.css 116 B
build/block-library/blocks/avatar/style-rtl.css 104 B
build/block-library/blocks/avatar/style.css 104 B
build/block-library/blocks/block/editor-rtl.css 305 B
build/block-library/blocks/block/editor.css 305 B
build/block-library/blocks/button/editor-rtl.css 584 B
build/block-library/blocks/button/editor.css 582 B
build/block-library/blocks/button/style-rtl.css 624 B
build/block-library/blocks/button/style.css 623 B
build/block-library/blocks/buttons/editor-rtl.css 337 B
build/block-library/blocks/buttons/editor.css 337 B
build/block-library/blocks/buttons/style-rtl.css 332 B
build/block-library/blocks/buttons/style.css 332 B
build/block-library/blocks/calendar/style-rtl.css 239 B
build/block-library/blocks/calendar/style.css 239 B
build/block-library/blocks/categories/editor-rtl.css 113 B
build/block-library/blocks/categories/editor.css 112 B
build/block-library/blocks/categories/style-rtl.css 124 B
build/block-library/blocks/categories/style.css 124 B
build/block-library/blocks/code/editor-rtl.css 53 B
build/block-library/blocks/code/editor.css 53 B
build/block-library/blocks/code/style-rtl.css 121 B
build/block-library/blocks/code/style.css 121 B
build/block-library/blocks/code/theme-rtl.css 124 B
build/block-library/blocks/code/theme.css 124 B
build/block-library/blocks/columns/editor-rtl.css 108 B
build/block-library/blocks/columns/editor.css 108 B
build/block-library/blocks/columns/style-rtl.css 409 B
build/block-library/blocks/columns/style.css 409 B
build/block-library/blocks/comment-author-avatar/editor-rtl.css 125 B
build/block-library/blocks/comment-author-avatar/editor.css 125 B
build/block-library/blocks/comment-content/style-rtl.css 92 B
build/block-library/blocks/comment-content/style.css 92 B
build/block-library/blocks/comment-template/style-rtl.css 199 B
build/block-library/blocks/comment-template/style.css 198 B
build/block-library/blocks/comments-pagination-numbers/editor-rtl.css 123 B
build/block-library/blocks/comments-pagination-numbers/editor.css 121 B
build/block-library/blocks/comments-pagination/editor-rtl.css 222 B
build/block-library/blocks/comments-pagination/editor.css 209 B
build/block-library/blocks/comments-pagination/style-rtl.css 235 B
build/block-library/blocks/comments-pagination/style.css 231 B
build/block-library/blocks/comments-title/editor-rtl.css 75 B
build/block-library/blocks/comments-title/editor.css 75 B
build/block-library/blocks/comments/editor-rtl.css 840 B
build/block-library/blocks/comments/editor.css 839 B
build/block-library/blocks/comments/style-rtl.css 637 B
build/block-library/blocks/comments/style.css 636 B
build/block-library/blocks/cover/editor-rtl.css 647 B
build/block-library/blocks/cover/editor.css 650 B
build/block-library/blocks/cover/style-rtl.css 1.61 kB
build/block-library/blocks/cover/style.css 1.6 kB
build/block-library/blocks/details/editor-rtl.css 65 B
build/block-library/blocks/details/editor.css 65 B
build/block-library/blocks/details/style-rtl.css 159 B
build/block-library/blocks/details/style.css 159 B
build/block-library/blocks/embed/editor-rtl.css 293 B
build/block-library/blocks/embed/editor.css 293 B
build/block-library/blocks/embed/style-rtl.css 410 B
build/block-library/blocks/embed/style.css 410 B
build/block-library/blocks/embed/theme-rtl.css 126 B
build/block-library/blocks/embed/theme.css 126 B
build/block-library/blocks/file/editor-rtl.css 316 B
build/block-library/blocks/file/editor.css 316 B
build/block-library/blocks/file/style-rtl.css 269 B
build/block-library/blocks/file/style.css 270 B
build/block-library/blocks/file/view.min.js 312 B
build/block-library/blocks/footnotes/style-rtl.css 191 B
build/block-library/blocks/footnotes/style.css 188 B
build/block-library/blocks/freeform/editor-rtl.css 2.58 kB
build/block-library/blocks/freeform/editor.css 2.58 kB
build/block-library/blocks/gallery/editor-rtl.css 947 B
build/block-library/blocks/gallery/editor.css 952 B
build/block-library/blocks/gallery/style-rtl.css 1.53 kB
build/block-library/blocks/gallery/style.css 1.53 kB
build/block-library/blocks/gallery/theme-rtl.css 108 B
build/block-library/blocks/gallery/theme.css 108 B
build/block-library/blocks/group/editor-rtl.css 654 B
build/block-library/blocks/group/editor.css 654 B
build/block-library/blocks/group/style-rtl.css 57 B
build/block-library/blocks/group/style.css 57 B
build/block-library/blocks/group/theme-rtl.css 78 B
build/block-library/blocks/group/theme.css 78 B
build/block-library/blocks/heading/style-rtl.css 76 B
build/block-library/blocks/heading/style.css 76 B
build/block-library/blocks/html/editor-rtl.css 336 B
build/block-library/blocks/html/editor.css 337 B
build/block-library/blocks/image/editor-rtl.css 834 B
build/block-library/blocks/image/editor.css 833 B
build/block-library/blocks/image/style-rtl.css 1.42 kB
build/block-library/blocks/image/style.css 1.42 kB
build/block-library/blocks/image/theme-rtl.css 126 B
build/block-library/blocks/image/theme.css 126 B
build/block-library/blocks/image/view-interactivity.min.js 1.46 kB
build/block-library/blocks/latest-comments/style-rtl.css 357 B
build/block-library/blocks/latest-comments/style.css 357 B
build/block-library/blocks/latest-posts/editor-rtl.css 213 B
build/block-library/blocks/latest-posts/editor.css 212 B
build/block-library/blocks/latest-posts/style-rtl.css 478 B
build/block-library/blocks/latest-posts/style.css 478 B
build/block-library/blocks/list/style-rtl.css 88 B
build/block-library/blocks/list/style.css 88 B
build/block-library/blocks/media-text/editor-rtl.css 266 B
build/block-library/blocks/media-text/editor.css 263 B
build/block-library/blocks/media-text/style-rtl.css 507 B
build/block-library/blocks/media-text/style.css 505 B
build/block-library/blocks/more/editor-rtl.css 431 B
build/block-library/blocks/more/editor.css 431 B
build/block-library/blocks/navigation-link/editor-rtl.css 712 B
build/block-library/blocks/navigation-link/editor.css 711 B
build/block-library/blocks/navigation-link/style-rtl.css 115 B
build/block-library/blocks/navigation-link/style.css 115 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 296 B
build/block-library/blocks/navigation-submenu/editor.css 295 B
build/block-library/blocks/navigation/editor-rtl.css 2.26 kB
build/block-library/blocks/navigation/editor.css 2.26 kB
build/block-library/blocks/navigation/style-rtl.css 2.21 kB
build/block-library/blocks/navigation/style.css 2.2 kB
build/block-library/blocks/navigation/view.min.js 906 B
build/block-library/blocks/nextpage/editor-rtl.css 395 B
build/block-library/blocks/nextpage/editor.css 395 B
build/block-library/blocks/page-list/editor-rtl.css 401 B
build/block-library/blocks/page-list/editor.css 401 B
build/block-library/blocks/page-list/style-rtl.css 175 B
build/block-library/blocks/page-list/style.css 175 B
build/block-library/blocks/paragraph/editor-rtl.css 174 B
build/block-library/blocks/paragraph/editor.css 174 B
build/block-library/blocks/paragraph/style-rtl.css 279 B
build/block-library/blocks/paragraph/style.css 281 B
build/block-library/blocks/post-author/style-rtl.css 175 B
build/block-library/blocks/post-author/style.css 176 B
build/block-library/blocks/post-comments-form/editor-rtl.css 96 B
build/block-library/blocks/post-comments-form/editor.css 96 B
build/block-library/blocks/post-comments-form/style-rtl.css 508 B
build/block-library/blocks/post-comments-form/style.css 508 B
build/block-library/blocks/post-date/style-rtl.css 61 B
build/block-library/blocks/post-date/style.css 61 B
build/block-library/blocks/post-excerpt/editor-rtl.css 71 B
build/block-library/blocks/post-excerpt/editor.css 71 B
build/block-library/blocks/post-excerpt/style-rtl.css 141 B
build/block-library/blocks/post-excerpt/style.css 141 B
build/block-library/blocks/post-featured-image/editor-rtl.css 588 B
build/block-library/blocks/post-featured-image/editor.css 586 B
build/block-library/blocks/post-featured-image/style-rtl.css 319 B
build/block-library/blocks/post-featured-image/style.css 319 B
build/block-library/blocks/post-navigation-link/style-rtl.css 153 B
build/block-library/blocks/post-navigation-link/style.css 153 B
build/block-library/blocks/post-template/editor-rtl.css 99 B
build/block-library/blocks/post-template/editor.css 98 B
build/block-library/blocks/post-template/style-rtl.css 314 B
build/block-library/blocks/post-template/style.css 314 B
build/block-library/blocks/post-terms/style-rtl.css 96 B
build/block-library/blocks/post-terms/style.css 96 B
build/block-library/blocks/post-time-to-read/style-rtl.css 69 B
build/block-library/blocks/post-time-to-read/style.css 69 B
build/block-library/blocks/post-title/style-rtl.css 100 B
build/block-library/blocks/post-title/style.css 100 B
build/block-library/blocks/preformatted/style-rtl.css 103 B
build/block-library/blocks/preformatted/style.css 103 B
build/block-library/blocks/pullquote/editor-rtl.css 135 B
build/block-library/blocks/pullquote/editor.css 135 B
build/block-library/blocks/pullquote/style-rtl.css 335 B
build/block-library/blocks/pullquote/style.css 335 B
build/block-library/blocks/pullquote/theme-rtl.css 167 B
build/block-library/blocks/pullquote/theme.css 167 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B
build/block-library/blocks/query-pagination/editor-rtl.css 221 B
build/block-library/blocks/query-pagination/editor.css 211 B
build/block-library/blocks/query-pagination/style-rtl.css 288 B
build/block-library/blocks/query-pagination/style.css 284 B
build/block-library/blocks/query-title/style-rtl.css 63 B
build/block-library/blocks/query-title/style.css 63 B
build/block-library/blocks/query/editor-rtl.css 450 B
build/block-library/blocks/query/editor.css 449 B
build/block-library/blocks/quote/style-rtl.css 222 B
build/block-library/blocks/quote/style.css 222 B
build/block-library/blocks/quote/theme-rtl.css 223 B
build/block-library/blocks/quote/theme.css 226 B
build/block-library/blocks/read-more/style-rtl.css 132 B
build/block-library/blocks/read-more/style.css 132 B
build/block-library/blocks/rss/editor-rtl.css 149 B
build/block-library/blocks/rss/editor.css 149 B
build/block-library/blocks/rss/style-rtl.css 289 B
build/block-library/blocks/rss/style.css 288 B
build/block-library/blocks/search/editor-rtl.css 178 B
build/block-library/blocks/search/editor.css 178 B
build/block-library/blocks/search/style-rtl.css 587 B
build/block-library/blocks/search/style.css 584 B
build/block-library/blocks/search/theme-rtl.css 114 B
build/block-library/blocks/search/theme.css 114 B
build/block-library/blocks/search/view.min.js 531 B
build/block-library/blocks/separator/editor-rtl.css 146 B
build/block-library/blocks/separator/editor.css 146 B
build/block-library/blocks/separator/style-rtl.css 234 B
build/block-library/blocks/separator/style.css 234 B
build/block-library/blocks/separator/theme-rtl.css 194 B
build/block-library/blocks/separator/theme.css 194 B
build/block-library/blocks/shortcode/editor-rtl.css 323 B
build/block-library/blocks/shortcode/editor.css 323 B
build/block-library/blocks/site-logo/editor-rtl.css 754 B
build/block-library/blocks/site-logo/editor.css 754 B
build/block-library/blocks/site-logo/style-rtl.css 203 B
build/block-library/blocks/site-logo/style.css 203 B
build/block-library/blocks/site-tagline/editor-rtl.css 86 B
build/block-library/blocks/site-tagline/editor.css 86 B
build/block-library/blocks/site-title/editor-rtl.css 116 B
build/block-library/blocks/site-title/editor.css 116 B
build/block-library/blocks/site-title/style-rtl.css 57 B
build/block-library/blocks/site-title/style.css 57 B
build/block-library/blocks/social-link/editor-rtl.css 184 B
build/block-library/blocks/social-link/editor.css 184 B
build/block-library/blocks/social-links/editor-rtl.css 674 B
build/block-library/blocks/social-links/editor.css 673 B
build/block-library/blocks/social-links/style-rtl.css 1.43 kB
build/block-library/blocks/social-links/style.css 1.42 kB
build/block-library/blocks/spacer/editor-rtl.css 348 B
build/block-library/blocks/spacer/editor.css 348 B
build/block-library/blocks/spacer/style-rtl.css 48 B
build/block-library/blocks/spacer/style.css 48 B
build/block-library/blocks/table/editor-rtl.css 433 B
build/block-library/blocks/table/editor.css 433 B
build/block-library/blocks/table/style-rtl.css 645 B
build/block-library/blocks/table/style.css 644 B
build/block-library/blocks/table/theme-rtl.css 146 B
build/block-library/blocks/table/theme.css 146 B
build/block-library/blocks/tag-cloud/style-rtl.css 251 B
build/block-library/blocks/tag-cloud/style.css 253 B
build/block-library/blocks/template-part/editor-rtl.css 403 B
build/block-library/blocks/template-part/editor.css 403 B
build/block-library/blocks/template-part/theme-rtl.css 101 B
build/block-library/blocks/template-part/theme.css 101 B
build/block-library/blocks/term-description/style-rtl.css 111 B
build/block-library/blocks/term-description/style.css 111 B
build/block-library/blocks/text-columns/editor-rtl.css 95 B
build/block-library/blocks/text-columns/editor.css 95 B
build/block-library/blocks/text-columns/style-rtl.css 166 B
build/block-library/blocks/text-columns/style.css 166 B
build/block-library/blocks/verse/style-rtl.css 99 B
build/block-library/blocks/verse/style.css 99 B
build/block-library/blocks/video/editor-rtl.css 552 B
build/block-library/blocks/video/editor.css 555 B
build/block-library/blocks/video/style-rtl.css 174 B
build/block-library/blocks/video/style.css 174 B
build/block-library/blocks/video/theme-rtl.css 126 B
build/block-library/blocks/video/theme.css 126 B
build/block-library/classic-rtl.css 179 B
build/block-library/classic.css 179 B
build/block-library/common-rtl.css 1.1 kB
build/block-library/common.css 1.1 kB
build/block-library/editor-elements-rtl.css 75 B
build/block-library/editor-elements.css 75 B
build/block-library/editor-rtl.css 12.1 kB
build/block-library/editor.css 12.1 kB
build/block-library/elements-rtl.css 54 B
build/block-library/elements.css 54 B
build/block-library/index.min.js 201 kB
build/block-library/reset-rtl.css 478 B
build/block-library/reset.css 478 B
build/block-library/style-rtl.css 13.7 kB
build/block-library/style.css 13.7 kB
build/block-library/theme-rtl.css 686 B
build/block-library/theme.css 691 B
build/block-serialization-default-parser/index.min.js 1.12 kB
build/block-serialization-spec-parser/index.min.js 2.87 kB
build/blocks/index.min.js 51 kB
build/commands/index.min.js 14.9 kB
build/commands/style-rtl.css 827 B
build/commands/style.css 827 B
build/components/index.min.js 240 kB
build/components/style-rtl.css 11.7 kB
build/components/style.css 11.7 kB
build/compose/index.min.js 12 kB
build/core-commands/index.min.js 2.26 kB
build/core-data/index.min.js 16.1 kB
build/customize-widgets/index.min.js 12 kB
build/customize-widgets/style-rtl.css 1.46 kB
build/customize-widgets/style.css 1.45 kB
build/data-controls/index.min.js 640 B
build/data/index.min.js 8.27 kB
build/date/index.min.js 17.8 kB
build/deprecated/index.min.js 451 B
build/dom-ready/index.min.js 324 B
build/dom/index.min.js 4.63 kB
build/edit-post/classic-rtl.css 544 B
build/edit-post/classic.css 545 B
build/edit-post/index.min.js 35.3 kB
build/edit-post/style-rtl.css 7.58 kB
build/edit-post/style.css 7.57 kB
build/edit-site/index.min.js 85.4 kB
build/edit-site/style-rtl.css 12.6 kB
build/edit-site/style.css 12.6 kB
build/edit-widgets/index.min.js 16.9 kB
build/edit-widgets/style-rtl.css 4.53 kB
build/edit-widgets/style.css 4.53 kB
build/editor/index.min.js 45.4 kB
build/editor/style-rtl.css 3.58 kB
build/editor/style.css 3.58 kB
build/element/index.min.js 4.8 kB
build/escape-html/index.min.js 537 B
build/format-library/index.min.js 7.62 kB
build/format-library/style-rtl.css 554 B
build/format-library/style.css 553 B
build/hooks/index.min.js 1.55 kB
build/html-entities/index.min.js 448 B
build/i18n/index.min.js 3.58 kB
build/interactivity/index.min.js 10 kB
build/is-shallow-equal/index.min.js 527 B
build/keyboard-shortcuts/index.min.js 1.64 kB
build/keycodes/index.min.js 1.84 kB
build/list-reusable-blocks/index.min.js 2.13 kB
build/list-reusable-blocks/style-rtl.css 836 B
build/list-reusable-blocks/style.css 836 B
build/media-utils/index.min.js 2.9 kB
build/notices/index.min.js 948 B
build/plugins/index.min.js 1.77 kB
build/preferences-persistence/index.min.js 1.84 kB
build/preferences/index.min.js 1.24 kB
build/primitives/index.min.js 943 B
build/priority-queue/index.min.js 1.52 kB
build/private-apis/index.min.js 943 B
build/react-i18n/index.min.js 615 B
build/react-refresh-entry/index.min.js 8.44 kB
build/react-refresh-runtime/index.min.js 7.31 kB
build/redux-routine/index.min.js 2.7 kB
build/reusable-blocks/index.min.js 2.39 kB
build/reusable-blocks/style-rtl.css 243 B
build/reusable-blocks/style.css 243 B
build/rich-text/index.min.js 10.9 kB
build/router/index.min.js 1.77 kB
build/server-side-render/index.min.js 1.94 kB
build/shortcode/index.min.js 1.39 kB
build/style-engine/index.min.js 1.83 kB
build/token-list/index.min.js 582 B
build/url/index.min.js 3.57 kB
build/vendors/inert-polyfill.min.js 2.48 kB
build/vendors/react-dom.min.js 41.8 kB
build/vendors/react.min.js 4.02 kB
build/viewport/index.min.js 958 B
build/warning/index.min.js 268 B
build/widgets/index.min.js 7.16 kB
build/widgets/style-rtl.css 1.15 kB
build/widgets/style.css 1.16 kB
build/wordcount/index.min.js 1.02 kB

compressed-size-action

@fluiddot fluiddot marked this pull request as ready for review July 12, 2023 17:33
@fluiddot fluiddot requested review from SiobhyB and removed request for ellatrix July 12, 2023 17:33
@@ -6,7 +6,7 @@ import { createContext } from '@wordpress/element';
// Navigation context in BottomSheet is necessary for controlling the
// height of navigation container.
export const BottomSheetNavigationContext = createContext( {
currentHeight: 1,
currentHeight: { value: 0 },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This structure matches Reanimated's shared value. I changed the default value to 0 as I feel it's a more appropriate default value.

Copy link
Member

Choose a reason for hiding this comment

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

I agree that 0 seems like a more reasonable default.

That said, my gut tells me moving to 0 may introduce a bug. I was unable to find a direct answer (indirectly not answered), but my hunch is that using 1 as the default may be a cryptic way of ensuring something occurs when first setting the height, but not if the height is set to 0 in the future. I.e. that "something" should not occur if the height comes through as 0, which more likely to organically occur than 1.

Does that make sense?

My fear may be irrational and not worth following, particularly if we do not observe any bugs while testing now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These default values will only be used when using the provider without setting the value prop. AFAIK this is not our case (reference), so similarly to setting an empty function for setHeight below, I used 0 as the empty value for currentHeight.

Regarding the default value to use for the height animation, I agree it's a bit cryptic why we use 1. I haven't checked this but my gut feeling is that, since we need to calculate the layout of the content to set the final height, using a 0 value would prevent the layout calculations to happen.

Copy link
Member

Choose a reason for hiding this comment

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

The impact — or lack thereof — of the default Context value makes sense. Thank you for noting that.

Comment on lines +88 to +97
const defaultTheme = useMemo(
() => ( {
...DefaultTheme,
colors: {
...DefaultTheme.colors,
background: backgroundStyle.backgroundColor,
},
} ),
[ backgroundStyle.backgroundColor ]
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is memoized to avoid potentially generating a new object on every render in _theme.

jest.useRealTimers();
} );
it( 'animates height transitioning from non-full-screen to non-full-screen', async () =>
withReanimatedTimer( async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note the use of withReanimatedTimer helper, this is needed when testing Reanimated animations.

if ( shouldAnimate ) {
currentHeight.value = withTiming( newHeight, {
duration: HEIGHT_ANIMATION_DURATION,
easing: Easing.out( Easing.cubic ),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can check the easing function here.

Copy link
Member

@dcalhoun dcalhoun 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 exploring how we might move away from LayoutAnimation, it has caused numerous issues in the past.

I tested this using an Android emulator. I noticed a few things that I'd like to get your input on.

Full-height bottom sheets appear to no longer animate. I noticed the setHeight callback fires multiple times for this scenario, but not for non-full-height scenarios.

Full-Height Animation
Before After
Screen_Recording_20230713_095648_Jetpack.mp4
Screen_Recording_20230713_095715_Gutenberg.mp4
Full-Height Logs bottom-sheet-height-animation-changes

I also noticed the bottom sheet animation jitters when opening the text formatting options. Similar to full-height, it appears the setHeight callback runs multiple times in this scenario.

Text Formatting Jitter
Screen_Recording_20230713_095858_Gutenberg.mp4
Text Formatting Logs text-color-1 text-color-2

Any thoughts as to what might be happening in these two scenarios?

@@ -6,7 +6,7 @@ import { createContext } from '@wordpress/element';
// Navigation context in BottomSheet is necessary for controlling the
// height of navigation container.
export const BottomSheetNavigationContext = createContext( {
currentHeight: 1,
currentHeight: { value: 0 },
Copy link
Member

Choose a reason for hiding this comment

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

I agree that 0 seems like a more reasonable default.

That said, my gut tells me moving to 0 may introduce a bug. I was unable to find a direct answer (indirectly not answered), but my hunch is that using 1 as the default may be a cryptic way of ensuring something occurs when first setting the height, but not if the height is set to 0 in the future. I.e. that "something" should not occur if the height comes through as 0, which more likely to organically occur than 1.

Does that make sense?

My fear may be irrational and not worth following, particularly if we do not observe any bugs while testing now.

@fluiddot
Copy link
Contributor Author

fluiddot commented Jul 13, 2023

Thanks @dcalhoun for reviewing the PR, I appreciate your feedback 🙇 !

I tested this using an Android emulator. I noticed a few things that I'd like to get your input on.

Full-height bottom sheets appear to no longer animate. I noticed the setHeight callback fires multiple times for this scenario, but not for non-full-height scenarios.

Full-Height Animation
Full-Height Logs

Oh, good catch. I need to check this further but it might be possible that full-screen sheets won't be animated.

I also noticed the bottom sheet animation jitters when opening the text formatting options. Similar to full-height, it appears the setHeight callback runs multiple times in this scenario.

Text Formatting Jitter
Text Formatting Logs
Any thoughts as to what might be happening in these two scenarios?

That's interesting. I'll check this scenario further following what you shared about setHeight being called multiple times 🤔.
Thanks 🙇 !

@fluiddot
Copy link
Contributor Author

@dcalhoun I tried to debut the issues recently shared in this comment. Here are my findings so far:

I tested this using an Android emulator. I noticed a few things that I'd like to get your input on.
Full-height bottom sheets appear to no longer animate. I noticed the setHeight callback fires multiple times for this scenario, but not for non-full-height scenarios.
Full-Height Animation
Full-Height Logs

Oh, good catch. I need to check this further but it might be possible that full-screen sheets won't be animated.

When the bottom sheet is set to full screen, KeyboardAvoidingView component (container of navigator) is expanded to fit the screen size.


flex: isFullScreen ? 1 : undefined,

This makes any changes to the navigator's height not visually reflected. In fact, I noticed that we could even remove this line as it's not really animating the height.

This wasn't the case when using Layout animations, as they animate any changes made to the layout. We could investigate a potential fix but based on the current state of the bottom sheet component, I'm concerned that it will end up being a major refactor and it will be probably out of the scope of this PR.

At this point, I see two options:

  1. Continue with this fix and disable the animations when navigating to fullscreen sheets.
  2. Work on a refactor of the bottom sheet to use Reanimated when animating fullscreen sheet transitions.

WDYT?

I also noticed the bottom sheet animation jitters when opening the text formatting options. Similar to full-height, it appears the setHeight callback runs multiple times in this scenario.
Text Formatting Jitter
Text Formatting Logs
Any thoughts as to what might be happening in these two scenarios?

That's interesting. I'll check this scenario further following what you shared about setHeight being called multiple times 🤔.

I'm not experiencing this issue on a physical device 🤔 , although I see multiple calls to the setHeight function. The content of the Color sheet seems to be added dynamically after naviating to the sheet. This explains why the onLayout event and setHeight is called several times. This was also the case before these changes, but maybe it was less prominent due to the use of Layout animations and debouncing the calls to setHeight.

I'll try to use Reanimated's layout animation and revert the removal of the setHeightDebounce function, in case that helps with this issue.

@dcalhoun
Copy link
Member

At this point, I see two options:

  1. Continue with this fix and disable the animations when navigating to fullscreen sheets.
  2. Work on a refactor of the bottom sheet to use Reanimated when animating fullscreen sheet transitions.

WDYT?

I believe we should pursue Option 1. The lack of animations for full-screen sheets is annoying, but it is not disruptive and it is limited to a subset of the product. We should prioritize upgrading our foundational dependency in React Native. We can follow up on the animations later.

I'm not experiencing this issue on a physical device 🤔 , although I see multiple calls to the setHeight function.

I retested using a Samsung Galaxy S20 5G FE running WPAndroid. The issue is definitely less notable in that context, but the animation is still less smooth than the previous version relying upon LayoutAnimation. I do not think it is enough to block this PR, though.

These complex issues are a good reminder of the value in pursuing #37559, potentially through #42192 and #42201.

I'll try to use Reanimated's layout animation and revert the removal of the setHeightDebounce function, in case that helps with this issue.

Let me know if you'd like to move forward with the current implementation. I will approve it.

@fluiddot
Copy link
Contributor Author

I believe we should pursue Option 1. The lack of animations for full-screen sheets is annoying, but it is not disruptive and it is limited to a subset of the product. We should prioritize upgrading our foundational dependency in React Native. We can follow up on the animations later.

I agree 👍, let's continue with this approach and follow up on this later.

I retested using a Samsung Galaxy S20 5G FE running WPAndroid. The issue is definitely less notable in that context, but the animation is still less smooth than the previous version relying upon LayoutAnimation. I do not think it is enough to block this PR, though.

Great, I'm glad it's not that bad when using WP-Android, that was my impression when testing too.

These complex issues are a good reminder of the value in pursuing #37559, potentially through #42192 and #42201.

Definitely, sooner than later we should tackle these issues. I feel that every time we have to make any minor updates to the bottom sheet we end up hitting a block due to the current status of that component.

In fact, when trying to apply the workaround I shared here related to using Reanimated's layout animation, I realized that it won't work out of the box due to how that component is structured and the usage of React Navigation. As an example, when navigating to the Colors sub-sheet from the block settings sheet, there are several components that impact the height:

  • In BottomSheet component, with Modal and KeyboardAvoidingView.
  • Block settings sheet, with NavigationContainer.
  • Colors settings sheet, with another instance of NavigationContainer.

It took me a while until I realized that NavigationContainer can be nested in some cases, and that each instance is managing its height independently.

Let me know if you'd like to move forward with the current implementation. I will approve it.

@dcalhoun In the spirit of unblocking the RN upgrade, I think we could move it forward as-is. And as you mentioned, we could follow up on improvements to the bottom sheet afterwards. Thanks!

@dcalhoun
Copy link
Member

Definitely, sooner than later we should tackle these issues. I feel that every time we have to make any minor updates to the bottom sheet we end up hitting a block due to the current status of that component.

Agreed. It seems to be a frequent occurrence.

[...] there are several components that impact the height [...]

Yes, it can be difficult to understand their relationship. Atop its low comprehensibility, my hunch is that the competing "managers" may lead to bugs we have noted.

@fluiddot
Copy link
Contributor Author

Yes, it can be difficult to understand their relationship. Atop its low comprehensibility, my hunch is that the competing "managers" may lead to bugs we have noted.

Absolutely. I also have the gut feeling that most of the bugs we have in the bottom sheet are related to this.

@fluiddot fluiddot merged commit 0411df1 into rnmobile/upgrade/react-native-0.71.8 Jul 14, 2023
47 of 51 checks passed
@fluiddot fluiddot deleted the rnmobile/fix/bottom-sheet-height-layout-animation branch July 14, 2023 14:44
fluiddot added a commit that referenced this pull request Jul 27, 2023
* Upgrade `react-native` dependency

* Upgrade `@babel/runtime` dependency

* Upgrade `metro-react-native-babel` preset and transformer dependencies

* Upgrade `cocoapods` gem

* Re-apply `react-devtools-core` patch to new version

* Update jest snapshots with new a11y values

* Mock `Linking.addEventListener` function

`Linking.removeEventListener` has been removed in RN `0.71`. The library is mocked by default but doesn't return the `remove` function when calling `addEventListener`.

* Update tests that fail due to use of debounce and link suggestions

* Fix `MediaUpload` component test

* Update `@react-navigation/native` package to version `6.0.14`

* Update `react-native-reanimated` to version `2.17.0`

* Update `react-native-gesture-handler` to version `2.10.2`

* Fix `act` warnings produced during block insertion

* Fix `act` warnings in Columns block tests

* Fix `act` warnings in List block tests

* Upgrade `react-native` dependency to version `0.71.11`

It also upgrades `metro-react-native-babel` dependencies following the upgrade helper.

* Mock return value of Linking `addEventListener`

We only need to mock the return the value, hence we don't need to mock the entire library.

* Remove `waitForModalVisible` usage in Paragraph block tests

* Remove `waitFor` usage in Link settings tests

* test: Fix act warning by awaiting LinkPicker loading indicator removal

The loading indicator is displayed and subsequently removed once the
suggestion fetches resolve. Explicitly awaiting this element's removal
fixes the `act` warnings.

* build: Update react-native-safe-area-context to 4.6.3

* build: Upgrade react-native-screens to 3.22.0

* build: Upgrade react-native-svg to 13.9.0

Based on the release notes breaking changes, we should look out for odd
sizing or display of icons, particularly on Android.

* build: Upgrade @react-native-masked-view/masked-view to 0.2.9

* build: Upgrade @react-native-clipboard/clipboard to 1.11.2

* build: Upgrade react-native-modal to 13.0.1

* test: Update link modal snapshot

This change is a result of applying new props from the RN upgrade to a
newly introduced snapshot in trunk: 71d2dc5

* Update `@react-navigation/stack` to version `6.3.5`

* Upgrade `react-native-linear-gradient` to version `2.7.3`

This commit also updates the `react-native-hsv-color-picker` library to point to the same version of `react-native-linear-gradient`.

* Use `react-native-safe-area-context` mock provided by the library

* Update link modal snapshot

* Update `package-lock.json` file

The integrity checksum of `react-native-hsv-color-picker` changed because the package has been modified (ref: wordpress-mobile/react-native-hsv-color-picker#10 (comment))

* Disable `react-native-screens` in navigators

`react-native-screens` is meant to be used at root level to save memory when having inactive screens. This is not the case of the editor, as the stack navigators are used within the Bottom sheet component.
As a side note, enabling `react-native-screens` here leads to the editor crashing.

* Fix render order of animated view to highlight selected segment

Rendering the animated view before the segments will ensure that is rendered behind them.

* Update source of `react-native-hsv-color-picker` to use tag version

* Revert "Update link modal snapshot"

This reverts commit 7988b0e.

This is needed after disabling `react-native-screens` in navigators (ref: e5838f4).

* [RNMobile] Upgrade React Native `0.71.11` - iOS changes (#51386)

* refactor: Extract bundle version number to var

* refactor: Delete /.ruby-version, no longer needed

* refactor: Update /podfile to align w/RN updates

* refactor: Remove path names as part of RN upgrade

* Update `Podfile` with changes from RN upgrade helper

* Fix React Native path for `react_native_post_install` script

* Update Pods

* Add patch to fix Reanimated podspec

Without this patch, Reanimated tries to use Hermes version of React Native and produced a build failure. Seems there's an issue in the `podspec` file, as the JSC module is not being added.
Reference: software-mansion/react-native-reanimated#4254

* Update pods to reflect 0.71.11 target

* Apply changes to pods following `pod install`

* Update `Podfile.lock` file

---------

Co-authored-by: Siobhan <siobhan@automattic.com>

* [RNMobile] Upgrade React Native `0.71.11` - Android changes (#51289)

* Upgrade Gradle to version 7.5.1

* Upgrade Gradle plugin

* Remove no longer needed files in new version

* Update Flipper initialization

* Update demo project main application

* Remove gradle download task plugin

* Bump ndk version

* Remove no longer need logic related to `newArchEnabled`

* Apply plugin React Native Gradle plugin

* Use React Native and Hermes modules from Maven

We no longer need to publish these binaries because React Native team is publishing React Native binaries to Maven.

* Remove exclude group from Flipper

* Update comments in `build.gradle` to align with new RN version

* Remove deprecated Gradle property

* Add `mavenLocal` repository to allow testing local binaries

* Bump Reanimated and Gesture handler libraries

* Revert "Upgrade Gradle plugin"

This reverts commit 82764a2.

* build: Resolve react-native-gradle-plugin incompatability

Due to host app requirements, we must use AGP 7.2.1. The included patch
disables logic requiring AGP 7.3. The logic appears to not be required
for our use cases in the Demo editor or host apps.

We should remove this patch once we upgrade past AGP 7.3.

* Reduce priority of `mavenLocal` repository in Android build configurations

Maven local is used to provide dependencies located locally, which is mainly used for testing and debugging. Hence, published dependencies should be prioritized over local ones.

* Disable `react-native-screens` in navigators

`react-native-screens` is meant to be used at root level to save memory when having inactive screens. This is not the case of the editor, as the stack navigators are used within the Bottom sheet component.
As a side note, enabling `react-native-screens` here leads to the editor crashing.

* Fix render order of animated view to highlight selected segment

Rendering the animated view before the segments will ensure that is rendered behind them.

* Bump Linear gradient Android library

This library is now published via the `react-native-libraries-publisher` repository.

---------

Co-authored-by: David Calhoun <github@davidcalhoun.me>

* Avoid exception in E2E tests when typing an empty string on Android

* Update a11y id queries for Android E2E tests

Starting in React Native 0.71, the accessibility hint is no longer appended to the accessibility content description. Reference: facebook/react-native@0b70b38

* Update button inline appender query for Android E2E tests

* Unify press keycode function for E2E tests

* Update comments in functions related to pressing a keycode

* Update block drop position using Reanimated's shared value

Seems there's some kind of incompatibility on calling a JS function from a worklet invoked from a gesture handler. For this reason, the logic to set the dropping insertion point has been updated. It now uses a Reanimated's shared value to keep the dragging over position and  `useDerivedValue` hook to listen for changes.

* Remove unneeded `hidden` param in Paragraph block test case

Co-authored-by: David Calhoun <github@davidcalhoun.me>

* Revert removing `.ruby-version` file

* Add inline comment in Reanimated patch

* Use `waitForElementToBeRemoved` in Paragraph block test cases

This way we can avoid waiting for any microtasks of link suggestions.

* Remove `act` statements from Link Settings test cases

* fix: Cover focal point drag handle visibility

The lack of an explicit width or height resulted in a invisible drag
handle. The logic passing the dimensions to the SVG expected a single
style object. The reality is that it (1) referenced only the Sass styles
and (2) the combined reference was actually an array of style objects.

Updating the reference and flattening it ensures the appropriate width
and height are passed to the SVG.

It appears the absence of explicit dimensions was not an issue in
earlier versions of React Native, but it makes sense why it might be
required.

* [RNMobile] Use Reanimated in bottom sheet height animation (#52563)

* Expose max height properties in `BottomSheetProvider`

* Animate bottom sheet's height with Reanimated

Pass `currentHeight` in bottom sheet navigation context

* Use pixel value when setting fullscreen height

We need to pass pixel values in order to animate the height with Reanimated.

* Rename `heightRef` to `maxHeight`

* Re-enable `exhaustive-deps` lint rule in `BottomSheetNavigationContainer`

* Avoid setting height using debounce

* Add test ID to navigation container component

* Mock Reanimated's `now` function

* Update test cases related to bottom sheet height animation

* Update test snapshots

* Update `react-native-editor` changelog

* Drop unsupported `--no-jetifier` from Android cmd

The `--no-jetifier` option no longer appears to be supported and results in an error when attempting to build the Android demo app.

Ref: wordpress-mobile/gutenberg-mobile#5881 (comment)

* Revert accidental change to .ruby-version

* Restore correct dependencies to package-lock.json

* Update `react-native-editor` changelog

* Update `package-lock.json` file to revert previous conflict resolutions

In 4482b9d we had a conflict in `package-lock.json` that was solved using the changes from this branch. However, seems that something went wrong and that although the editor has no issues, some e2e tests are failing due to this.

This has been solved by using the latest version of `package-lock.json` file from `trunk` and updating it with the package updates required in the React Native upgrade.

* Re-apply `react-devtools-core` patch to new version

* Update `Podfile.lock` file

---------

Co-authored-by: David Calhoun <github@davidcalhoun.me>
Co-authored-by: Siobhan <siobhan@automattic.com>
dcalhoun added a commit that referenced this pull request Aug 1, 2023
This warning appears to no longer occur, presumably thanks to:

#52563
dcalhoun added a commit that referenced this pull request Aug 3, 2023
* refactor: Remove unsupported line height Aztec warning

While arguably educational, this warning increases the amount of noise
within the server log, which can make it difficult to debug errors,
warnings, or intentionally logged values.

* refactor: Remove Hermes engine status log

While informative, this un-filterable log increases the amount of noise
in the server log, which can make it difficult to debug errors,
warnings, or intentionally logged values. Additionally, the Hermes
engine is now globally enabled for both iOS and Android.

* refactor: Remove outdated LogBox configuration for LayoutAnimation

This warning appears to no longer occur, presumably thanks to:

#52563

* refactor: Remove outdated LogBox configuration for gesture handler

This warning appears to no longer occur. The configuration was
originally added in: a1b11c5
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) [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants