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][Embed block] Block settings #33654

Merged
merged 19 commits into from
Aug 13, 2021
Merged

[RNMobile][Embed block] Block settings #33654

merged 19 commits into from
Aug 13, 2021

Conversation

ceyhun
Copy link
Member

@ceyhun ceyhun commented Jul 23, 2021

Description

If embed block variation and site's theme supports it, a settings icon is shown inside the block and a bottom sheet opens when pressing it, which shows a toggle for “Resize for smaller devices.”

Gutenberg Mobile PR: wordpress-mobile/gutenberg-mobile#3753

How has this been tested?

Which embed variations support this setting can be checked from the responsive attribute in variations.js:

Supported:

attributes: { providerNameSlug: 'twitter', responsive: true },

Unsupported:

attributes: { providerNameSlug: 'amazon-kindle' },

For supported case:

  1. Add embed block
  2. Enter a supported embed variation URL (e.g. https://www.youtube.com/watch?v=8qpkAdp1K0M)
  3. Press settings button
  4. Turn toggle off
  5. Update post and preview
  6. Close preview and turn toggle on
  7. Update post and preview again

For unsupported case:

A WP.com free plan site may not support responsive-embeds, so it can be used to test where the setting doesn't appear. This is actually not related to the site plan, but only related to which theme the site is using and if that theme supports responsive-embeds. For example, Mayland theme supports responsive-embeds, but Baskerville 2 doesn’t.

Another way to test unsupported case is with an unsupported embed variation like Amazon Kindle embed.

Known issues

Facebook and Instagram embed variations have block in their scope as they are deprecated:

This results in responsive attribute not being passed into the embed block and as a result it's assumed false.

Screenshots

iOS Android
Toggle Off Toggle On

Types of changes

New feature (non-breaking change which adds functionality)

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • 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 (please manually search all *.native.js files for terms that need renaming or removal).

@ceyhun ceyhun added Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) [Block] Embed Affects the Embed Block labels Jul 23, 2021
@ceyhun ceyhun requested a review from fluiddot July 23, 2021 14:28
@ceyhun ceyhun requested a review from ajitbohra as a code owner July 23, 2021 14:28
@ceyhun ceyhun removed the request for review from ajitbohra July 23, 2021 14:29
@@ -6,7 +6,7 @@ import apiFetch from '@wordpress/api-fetch';

// Please add only wp.org API paths here!
const SUPPORTED_ENDPOINTS = [
/wp\/v2\/(media|categories|blocks)\/?\d*?.*/i,
/wp\/v2\/(media|categories|blocks|themes)\/?\d*?.*/i,
Copy link
Member Author

Choose a reason for hiding this comment

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

getThemeSupports selector may trigger a request to /wp/v2/themes?status=active

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if we should fetch theme data via the bridge instead of directly making the API request, for other values like colors or gradients, we're getting them from the editor settings:

private func properties(from editorSettings: GutenbergEditorSettings?) -> [String : Any] {
var settingsUpdates = [String : Any]()
settingsUpdates["isFSETheme"] = editorSettings?.isFSETheme ?? false
if let rawStyles = editorSettings?.rawStyles {
settingsUpdates["rawStyles"] = rawStyles
}
if let rawFeatures = editorSettings?.rawFeatures {
settingsUpdates["rawFeatures"] = rawFeatures
}
if let colors = editorSettings?.colors {
settingsUpdates["colors"] = colors
}
if let gradients = editorSettings?.gradients {
settingsUpdates["gradients"] = gradients
}
return settingsUpdates
}

From my POV it's totally ok to fetch from the editor but we might have issues for supporting offline mode, wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried fetching it from the bridge on WPiOS via WordPressKit-iOS, but it seems like the /wp-block-editor/v1/settings endpoint is used instead of /wp/v2/themes if the blog supports it here and the /settings endpoint currently doesn't seem to return the responsive-embeds value we need.

Copy link
Contributor

Choose a reason for hiding this comment

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

I tried fetching it from the bridge on WPiOS via WordPressKit-iOS, but it seems like the /wp-block-editor/v1/settings endpoint is used instead of /wp/v2/themes if the blog supports it here and the /settings endpoint currently doesn't seem to return the responsive-embeds value we need.

Right, I checked the schema of /wp-block-editor/v1/settings (reference) and there's no reference to responsive-embeds, so looks like the theme support settings are only included in the theme model. Now I'm wondering if we should continue fetching the theme via the api-fetch or from the theme service (WordPress-iOS reference and WordPressKit-iOS reference) and expose it in the RN bridge, wdyt?

NOTE: I noticed that the Theme model (reference) doesn't include the theme support settings so, in case we go that way, we should include it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the response from /sites/%@/themes/mine also doesn't return the responsive-embeds value. I couldn't find any other endpoint that returns it, but could be that I missed out something.
Otherwise I guess we can still fetch it from /wp/v2/themes via BlockEditorSettingsServiceRemote in WordPressKit-iOS with the function here, even when the blog supports /wp-block-editor/v1/settings endpoint. But I think WPiOS is expecting both endpoints to have the same response structure as they are both handed the same completion handler here. I think this is not the case, but again I may be overlooking something.
This might mean that we may need to create a new model for the /wp/v2/themes response along with its local persistence counterparts, which might require some more effort.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point, I'm afraid that this could turn more complex than what we would expect for this task. At this point, I'd lean towards stick with using the fetch as you originally implemented and open an issue as a follow-up to tackle this in the future, wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, opened an issue for this: wordpress-mobile/gutenberg-mobile#3825

@github-actions
Copy link

github-actions bot commented Jul 23, 2021

Size Change: -15 B (0%)

Total Size: 1.03 MB

Filename Size Change
build/block-library/index.min.js 147 kB -15 B (0%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 931 B
build/admin-manifest/index.min.js 1.09 kB
build/annotations/index.min.js 2.7 kB
build/api-fetch/index.min.js 2.19 kB
build/autop/index.min.js 2.08 kB
build/blob/index.min.js 459 B
build/block-directory/index.min.js 6.21 kB
build/block-directory/style-rtl.css 1.01 kB
build/block-directory/style.css 1.01 kB
build/block-editor/index.min.js 118 kB
build/block-editor/style-rtl.css 13.9 kB
build/block-editor/style.css 13.9 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 65 B
build/block-library/blocks/archives/style.css 65 B
build/block-library/blocks/audio/editor-rtl.css 58 B
build/block-library/blocks/audio/editor.css 58 B
build/block-library/blocks/audio/style-rtl.css 111 B
build/block-library/blocks/audio/style.css 111 B
build/block-library/blocks/audio/theme-rtl.css 125 B
build/block-library/blocks/audio/theme.css 125 B
build/block-library/blocks/block/editor-rtl.css 161 B
build/block-library/blocks/block/editor.css 161 B
build/block-library/blocks/button/editor-rtl.css 474 B
build/block-library/blocks/button/editor.css 474 B
build/block-library/blocks/button/style-rtl.css 605 B
build/block-library/blocks/button/style.css 604 B
build/block-library/blocks/buttons/editor-rtl.css 315 B
build/block-library/blocks/buttons/editor.css 315 B
build/block-library/blocks/buttons/style-rtl.css 370 B
build/block-library/blocks/buttons/style.css 370 B
build/block-library/blocks/calendar/style-rtl.css 207 B
build/block-library/blocks/calendar/style.css 207 B
build/block-library/blocks/categories/editor-rtl.css 84 B
build/block-library/blocks/categories/editor.css 83 B
build/block-library/blocks/categories/style-rtl.css 79 B
build/block-library/blocks/categories/style.css 79 B
build/block-library/blocks/code/style-rtl.css 90 B
build/block-library/blocks/code/style.css 90 B
build/block-library/blocks/code/theme-rtl.css 131 B
build/block-library/blocks/code/theme.css 131 B
build/block-library/blocks/columns/editor-rtl.css 194 B
build/block-library/blocks/columns/editor.css 193 B
build/block-library/blocks/columns/style-rtl.css 474 B
build/block-library/blocks/columns/style.css 475 B
build/block-library/blocks/cover/editor-rtl.css 666 B
build/block-library/blocks/cover/editor.css 670 B
build/block-library/blocks/cover/style-rtl.css 1.23 kB
build/block-library/blocks/cover/style.css 1.23 kB
build/block-library/blocks/embed/editor-rtl.css 488 B
build/block-library/blocks/embed/editor.css 488 B
build/block-library/blocks/embed/style-rtl.css 400 B
build/block-library/blocks/embed/style.css 400 B
build/block-library/blocks/embed/theme-rtl.css 124 B
build/block-library/blocks/embed/theme.css 124 B
build/block-library/blocks/file/editor-rtl.css 300 B
build/block-library/blocks/file/editor.css 300 B
build/block-library/blocks/file/style-rtl.css 255 B
build/block-library/blocks/file/style.css 255 B
build/block-library/blocks/file/view.min.js 322 B
build/block-library/blocks/freeform/editor-rtl.css 2.44 kB
build/block-library/blocks/freeform/editor.css 2.44 kB
build/block-library/blocks/gallery/editor-rtl.css 707 B
build/block-library/blocks/gallery/editor.css 706 B
build/block-library/blocks/gallery/style-rtl.css 1.05 kB
build/block-library/blocks/gallery/style.css 1.05 kB
build/block-library/blocks/gallery/theme-rtl.css 122 B
build/block-library/blocks/gallery/theme.css 122 B
build/block-library/blocks/group/editor-rtl.css 159 B
build/block-library/blocks/group/editor.css 159 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 93 B
build/block-library/blocks/group/theme.css 93 B
build/block-library/blocks/heading/editor-rtl.css 152 B
build/block-library/blocks/heading/editor.css 152 B
build/block-library/blocks/heading/style-rtl.css 76 B
build/block-library/blocks/heading/style.css 76 B
build/block-library/blocks/home-link/style-rtl.css 247 B
build/block-library/blocks/home-link/style.css 247 B
build/block-library/blocks/html/editor-rtl.css 283 B
build/block-library/blocks/html/editor.css 284 B
build/block-library/blocks/image/editor-rtl.css 728 B
build/block-library/blocks/image/editor.css 728 B
build/block-library/blocks/image/style-rtl.css 482 B
build/block-library/blocks/image/style.css 487 B
build/block-library/blocks/image/theme-rtl.css 124 B
build/block-library/blocks/image/theme.css 124 B
build/block-library/blocks/latest-comments/style-rtl.css 284 B
build/block-library/blocks/latest-comments/style.css 284 B
build/block-library/blocks/latest-posts/editor-rtl.css 137 B
build/block-library/blocks/latest-posts/editor.css 137 B
build/block-library/blocks/latest-posts/style-rtl.css 528 B
build/block-library/blocks/latest-posts/style.css 527 B
build/block-library/blocks/list/style-rtl.css 63 B
build/block-library/blocks/list/style.css 63 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 488 B
build/block-library/blocks/media-text/style.css 485 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 474 B
build/block-library/blocks/navigation-link/editor.css 474 B
build/block-library/blocks/navigation-link/style-rtl.css 94 B
build/block-library/blocks/navigation-link/style.css 94 B
build/block-library/blocks/navigation/editor-rtl.css 1.69 kB
build/block-library/blocks/navigation/editor.css 1.69 kB
build/block-library/blocks/navigation/style-rtl.css 1.65 kB
build/block-library/blocks/navigation/style.css 1.64 kB
build/block-library/blocks/navigation/view.min.js 2.52 kB
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 310 B
build/block-library/blocks/page-list/editor.css 310 B
build/block-library/blocks/page-list/style-rtl.css 242 B
build/block-library/blocks/page-list/style.css 242 B
build/block-library/blocks/paragraph/editor-rtl.css 157 B
build/block-library/blocks/paragraph/editor.css 157 B
build/block-library/blocks/paragraph/style-rtl.css 248 B
build/block-library/blocks/paragraph/style.css 248 B
build/block-library/blocks/post-author/editor-rtl.css 210 B
build/block-library/blocks/post-author/editor.css 210 B
build/block-library/blocks/post-author/style-rtl.css 182 B
build/block-library/blocks/post-author/style.css 181 B
build/block-library/blocks/post-comments-form/style-rtl.css 140 B
build/block-library/blocks/post-comments-form/style.css 140 B
build/block-library/blocks/post-comments/style-rtl.css 360 B
build/block-library/blocks/post-comments/style.css 359 B
build/block-library/blocks/post-content/editor-rtl.css 138 B
build/block-library/blocks/post-content/editor.css 138 B
build/block-library/blocks/post-excerpt/editor-rtl.css 73 B
build/block-library/blocks/post-excerpt/editor.css 73 B
build/block-library/blocks/post-excerpt/style-rtl.css 69 B
build/block-library/blocks/post-excerpt/style.css 69 B
build/block-library/blocks/post-featured-image/editor-rtl.css 412 B
build/block-library/blocks/post-featured-image/editor.css 412 B
build/block-library/blocks/post-featured-image/style-rtl.css 143 B
build/block-library/blocks/post-featured-image/style.css 143 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 378 B
build/block-library/blocks/post-template/style.css 379 B
build/block-library/blocks/post-terms/style-rtl.css 73 B
build/block-library/blocks/post-terms/style.css 73 B
build/block-library/blocks/post-title/style-rtl.css 60 B
build/block-library/blocks/post-title/style.css 60 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 198 B
build/block-library/blocks/pullquote/editor.css 198 B
build/block-library/blocks/pullquote/style-rtl.css 361 B
build/block-library/blocks/pullquote/style.css 360 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 270 B
build/block-library/blocks/query-pagination/editor.css 262 B
build/block-library/blocks/query-pagination/style-rtl.css 168 B
build/block-library/blocks/query-pagination/style.css 168 B
build/block-library/blocks/query-title/editor-rtl.css 85 B
build/block-library/blocks/query-title/editor.css 85 B
build/block-library/blocks/query/editor-rtl.css 131 B
build/block-library/blocks/query/editor.css 132 B
build/block-library/blocks/quote/style-rtl.css 169 B
build/block-library/blocks/quote/style.css 169 B
build/block-library/blocks/quote/theme-rtl.css 220 B
build/block-library/blocks/quote/theme.css 222 B
build/block-library/blocks/rss/editor-rtl.css 202 B
build/block-library/blocks/rss/editor.css 204 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 165 B
build/block-library/blocks/search/editor.css 165 B
build/block-library/blocks/search/style-rtl.css 374 B
build/block-library/blocks/search/style.css 375 B
build/block-library/blocks/search/theme-rtl.css 64 B
build/block-library/blocks/search/theme.css 64 B
build/block-library/blocks/separator/editor-rtl.css 99 B
build/block-library/blocks/separator/editor.css 99 B
build/block-library/blocks/separator/style-rtl.css 250 B
build/block-library/blocks/separator/style.css 250 B
build/block-library/blocks/separator/theme-rtl.css 172 B
build/block-library/blocks/separator/theme.css 172 B
build/block-library/blocks/shortcode/editor-rtl.css 474 B
build/block-library/blocks/shortcode/editor.css 474 B
build/block-library/blocks/site-logo/editor-rtl.css 462 B
build/block-library/blocks/site-logo/editor.css 464 B
build/block-library/blocks/site-logo/style-rtl.css 153 B
build/block-library/blocks/site-logo/style.css 153 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 84 B
build/block-library/blocks/site-title/editor.css 84 B
build/block-library/blocks/social-link/editor-rtl.css 165 B
build/block-library/blocks/social-link/editor.css 165 B
build/block-library/blocks/social-links/editor-rtl.css 812 B
build/block-library/blocks/social-links/editor.css 811 B
build/block-library/blocks/social-links/style-rtl.css 1.33 kB
build/block-library/blocks/social-links/style.css 1.33 kB
build/block-library/blocks/spacer/editor-rtl.css 307 B
build/block-library/blocks/spacer/editor.css 307 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 471 B
build/block-library/blocks/table/editor.css 472 B
build/block-library/blocks/table/style-rtl.css 481 B
build/block-library/blocks/table/style.css 481 B
build/block-library/blocks/table/theme-rtl.css 188 B
build/block-library/blocks/table/theme.css 188 B
build/block-library/blocks/tag-cloud/style-rtl.css 146 B
build/block-library/blocks/tag-cloud/style.css 146 B
build/block-library/blocks/template-part/editor-rtl.css 636 B
build/block-library/blocks/template-part/editor.css 635 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/editor-rtl.css 90 B
build/block-library/blocks/term-description/editor.css 90 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 87 B
build/block-library/blocks/verse/style.css 87 B
build/block-library/blocks/video/editor-rtl.css 571 B
build/block-library/blocks/video/editor.css 572 B
build/block-library/blocks/video/style-rtl.css 173 B
build/block-library/blocks/video/style.css 173 B
build/block-library/blocks/video/theme-rtl.css 124 B
build/block-library/blocks/video/theme.css 124 B
build/block-library/common-rtl.css 832 B
build/block-library/common.css 830 B
build/block-library/editor-rtl.css 9.38 kB
build/block-library/editor.css 9.37 kB
build/block-library/reset-rtl.css 527 B
build/block-library/reset.css 527 B
build/block-library/style-rtl.css 9.78 kB
build/block-library/style.css 9.79 kB
build/block-library/theme-rtl.css 688 B
build/block-library/theme.css 692 B
build/block-serialization-default-parser/index.min.js 1.09 kB
build/block-serialization-spec-parser/index.min.js 2.79 kB
build/blocks/index.min.js 47 kB
build/components/index.min.js 209 kB
build/components/style-rtl.css 15.7 kB
build/components/style.css 15.8 kB
build/compose/index.min.js 10.2 kB
build/core-data/index.min.js 12.3 kB
build/customize-widgets/index.min.js 10.4 kB
build/customize-widgets/style-rtl.css 1.5 kB
build/customize-widgets/style.css 1.49 kB
build/data-controls/index.min.js 614 B
build/data/index.min.js 7.03 kB
build/date/index.min.js 31.5 kB
build/deprecated/index.min.js 428 B
build/dom-ready/index.min.js 304 B
build/dom/index.min.js 4.53 kB
build/edit-navigation/index.min.js 13.4 kB
build/edit-navigation/style-rtl.css 3.1 kB
build/edit-navigation/style.css 3.1 kB
build/edit-post/classic-rtl.css 492 B
build/edit-post/classic.css 494 B
build/edit-post/index.min.js 28.4 kB
build/edit-post/style-rtl.css 7.18 kB
build/edit-post/style.css 7.17 kB
build/edit-site/index.min.js 25.9 kB
build/edit-site/style-rtl.css 5.01 kB
build/edit-site/style.css 5.01 kB
build/edit-widgets/index.min.js 15.9 kB
build/edit-widgets/style-rtl.css 4.01 kB
build/edit-widgets/style.css 4.02 kB
build/editor/index.min.js 37.5 kB
build/editor/style-rtl.css 3.92 kB
build/editor/style.css 3.91 kB
build/element/index.min.js 3.16 kB
build/escape-html/index.min.js 517 B
build/format-library/index.min.js 5.36 kB
build/format-library/style-rtl.css 668 B
build/format-library/style.css 669 B
build/hooks/index.min.js 1.55 kB
build/html-entities/index.min.js 424 B
build/i18n/index.min.js 3.59 kB
build/is-shallow-equal/index.min.js 501 B
build/keyboard-shortcuts/index.min.js 1.49 kB
build/keycodes/index.min.js 1.25 kB
build/list-reusable-blocks/index.min.js 1.85 kB
build/list-reusable-blocks/style-rtl.css 838 B
build/list-reusable-blocks/style.css 838 B
build/media-utils/index.min.js 2.88 kB
build/notices/index.min.js 845 B
build/nux/index.min.js 2.03 kB
build/nux/style-rtl.css 747 B
build/nux/style.css 743 B
build/plugins/index.min.js 1.83 kB
build/primitives/index.min.js 921 B
build/priority-queue/index.min.js 582 B
build/react-i18n/index.min.js 671 B
build/redux-routine/index.min.js 2.63 kB
build/reusable-blocks/index.min.js 2.28 kB
build/reusable-blocks/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
build/rich-text/index.min.js 10.6 kB
build/server-side-render/index.min.js 1.32 kB
build/shortcode/index.min.js 1.48 kB
build/token-list/index.min.js 562 B
build/url/index.min.js 1.72 kB
build/viewport/index.min.js 1.02 kB
build/warning/index.min.js 248 B
build/widgets/index.min.js 6.27 kB
build/widgets/style-rtl.css 1.04 kB
build/widgets/style.css 1.04 kB
build/wordcount/index.min.js 1.04 kB

compressed-size-action

// few popular ones.
( category !== 'embed' ||
( category === 'embed' &&
ALLOWED_EMBED_VARIATIONS.includes( id ) ) )
Copy link
Member Author

Choose a reason for hiding this comment

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

Normally the embed variations were hidden from the inserter as we had an empty embed/variations.native.js file (which I deleted in this PR). We needed to re-enable those as the information if an embed supports this setting is kept in the attributes there with the responsive flag:

attributes: { providerNameSlug: 'twitter', responsive: true },

This should also help us when we add a few more variations for wordpress-mobile/gutenberg-mobile#3278

@@ -118,7 +115,7 @@ const EmbedNoPreview = ( { label, icon, isSelected, onPress } ) => {
onPress={ onPressContainer }
>
<View style={ containerStyle }>
<Icon icon={ icon } fill={ embedIconStyle.fill } />
<BlockIcon icon={ icon } />
Copy link
Member Author

Choose a reason for hiding this comment

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

Now that we've enabled all the variations, icons can also be objects:

export const embedTwitterIcon = {
foreground: '#1da1f2',
src: (
<SVG xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<G>
<Path d="M22.23 5.924c-.736.326-1.527.547-2.357.646.847-.508 1.498-1.312 1.804-2.27-.793.47-1.67.812-2.606.996C18.325 4.498 17.258 4 16.078 4c-2.266 0-4.103 1.837-4.103 4.103 0 .322.036.635.106.935-3.41-.17-6.433-1.804-8.457-4.287-.353.607-.556 1.312-.556 2.064 0 1.424.724 2.68 1.825 3.415-.673-.022-1.305-.207-1.86-.514v.052c0 1.988 1.415 3.647 3.293 4.023-.344.095-.707.145-1.08.145-.265 0-.522-.026-.773-.074.522 1.63 2.038 2.817 3.833 2.85-1.404 1.1-3.174 1.757-5.096 1.757-.332 0-.66-.02-.98-.057 1.816 1.164 3.973 1.843 6.29 1.843 7.547 0 11.675-6.252 11.675-11.675 0-.178-.004-.355-.012-.53.802-.578 1.497-1.3 2.047-2.124z"></Path>
</G>
</SVG>
),
};

BlockIcon component was used in the web version and it handles this case as well.

Copy link
Contributor

@fluiddot fluiddot left a comment

Choose a reason for hiding this comment

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

I noticed the following issues when testing:

  • After toggling off the "Resize for smaller devices" option, it's required to update the post before displaying the preview, otherwise, the embed is not displayed as expected. I think this behavior could be confusing to users, as they probably expect that modifications will be reflected in the preview without saving, wdyt?
  • I tested with a post that contains all the providers and I noticed that the one for Amazon is not displaying the corresponding title and icon 🤔, any clue what is happening for this block?

packages/components/src/toggle-control/index.native.js Outdated Show resolved Hide resolved
packages/block-library/src/embed/embed-controls.js Outdated Show resolved Hide resolved
packages/block-library/src/embed/embed-controls.js Outdated Show resolved Hide resolved
@@ -6,7 +6,7 @@ import apiFetch from '@wordpress/api-fetch';

// Please add only wp.org API paths here!
const SUPPORTED_ENDPOINTS = [
/wp\/v2\/(media|categories|blocks)\/?\d*?.*/i,
/wp\/v2\/(media|categories|blocks|themes)\/?\d*?.*/i,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if we should fetch theme data via the bridge instead of directly making the API request, for other values like colors or gradients, we're getting them from the editor settings:

private func properties(from editorSettings: GutenbergEditorSettings?) -> [String : Any] {
var settingsUpdates = [String : Any]()
settingsUpdates["isFSETheme"] = editorSettings?.isFSETheme ?? false
if let rawStyles = editorSettings?.rawStyles {
settingsUpdates["rawStyles"] = rawStyles
}
if let rawFeatures = editorSettings?.rawFeatures {
settingsUpdates["rawFeatures"] = rawFeatures
}
if let colors = editorSettings?.colors {
settingsUpdates["colors"] = colors
}
if let gradients = editorSettings?.gradients {
settingsUpdates["gradients"] = gradients
}
return settingsUpdates
}

From my POV it's totally ok to fetch from the editor but we might have issues for supporting offline mode, wdyt?

@ceyhun
Copy link
Member Author

ceyhun commented Aug 4, 2021

I tested with a post that contains all the providers and I noticed that the one for Amazon is not displaying the corresponding title and icon 🤔, any clue what is happening for this block?

It eventually comes down to this:

// If we got a provider name from the API, use it for the slug, otherwise we use the title,
// because not all embed code gives us a provider name.
const { html, provider_name: providerName } = preview;
const providerNameSlug = kebabCase(
( providerName || title ).toLowerCase()
);

We use the title before fetching the preview, so it's correct. But in the fetched preview from /oembed endpoint the provider_name is Amazon instead of Amazon Kindle, so it's reverted back to the generic Embed block.

I'm not sure why but I observed that on WPCom simple sites this works fine, even when you add a generic embed block, if you use an Amazon Kindle link, it's correctly converted to the Amazon Kindle embed block variation. But on atomic or self hosted sites it's the same as it is here.

@fluiddot
Copy link
Contributor

fluiddot commented Aug 5, 2021

I'm not why but I observed that on WPCom simple sites this works fine, even when you add a generic embed block, if you use an Amazon Kindle link, it's correctly converted to the Amazon Kindle embed block variation. But on atomic or self hosted sites it's the same as it is here.

I think it has to do with the API used in each case, on Atomic, I see that it's fetching the following URL:
https://<MY_BLOG>/wp-json/oembed/1.0/proxy?url=<AMAZON_KINDLE_URL>&_locale=user
that has the same response as we have in the app, so it produces the same error.

However, on WPcom, instead of hitting that endpoint it's directly getting the embed content with:
https://public-api.wordpress.com/rest/v1.1/sites/<MY_BLOG_SITE_ID>/embeds/render?_envelope=1&embed_url=<AMAZON_KINDLE_URL>&force=wpcom&http_envelope=1&environment-id=<ENV_ID>&_gutenberg_nonce=<NONCE>&_locale=user
which returns:

{
  "code": 200,
  "headers": [{ "name": "Content-Type", "value": "application/json" }],
  "body": {
    "embed_url": "https://www.amazon.com/<REST_OF_AMAZON_KINDLE_URL>",
    "result": "<PREVIEW_HTML_CONTENT>"
  }
}

Not sure how we could address this issue but as it's also happening in the web version, I'm wondering if we could tackle it separately and not block this PR, wdyt?

@fluiddot
Copy link
Contributor

fluiddot commented Aug 5, 2021

After toggling off the "Resize for smaller devices" option, it's required to update the post before displaying the preview, otherwise, the embed is not displayed as expected. I think this behavior could be confusing to users, as they probably expect that modifications will be reflected in the preview without saving, wdyt?

I tested this PR on the inline preview one and I think I found the culprit for this. Looks like theclassName attribute should be updated along with allowResponsive:

Case 1 - Embed block is created ✅

HTML code:
<!-- wp:embed {"url":"https://youtu.be/6wPWFWUsPBw","type":"video","providerNameSlug":"youtube","responsive":true,"className":"wp-embed-aspect-16-9 wp-has-aspect-ratio"} -->

Post preview:
Screenshot 2021-08-05 at 19 33 13

In this case, the preview is rendered properly with "Resize for smaller devices" option enabled.

Case 2 - "Resize for smaller devices" option is disabled ❌

HTML code:
<!-- wp:embed {"url":"https://youtu.be/6wPWFWUsPBw","type":"video","providerNameSlug":"youtube","allowResponsive":false,"responsive":true,"className":"wp-embed-aspect-16-9 wp-has-aspect-ratio"} -->

Screenshot 2021-08-05 at 19 31 13

Note that the allowResponsive is false but it keeps the className attribute, this makes the preview not matching what is expected when "Resize for smaller devices" option is disabled.

In fact, if you switch to HTML code, switch back to visual mode and again to HTML code, you'll notice that the className attribute is now empty and the preview matches the expected size:
<!-- wp:embed {"url":"https://youtu.be/6wPWFWUsPBw","type":"video","providerNameSlug":"youtube","allowResponsive":false,"responsive":true,"className":""} -->

Screenshot 2021-08-05 at 19 30 39

This is the reason why it's required to update the post before displaying the preview, as it removes or empties the className attribute. The same happens when enabling the "Resize for smaller devices" option again.

I haven't explored further but I have the impression that we would need to update the className attribute somehow.

@ceyhun
Copy link
Member Author

ceyhun commented Aug 5, 2021

Not sure how we could address this issue but as it's also happening in the web version, I'm wondering if we could tackle it separately and not block this PR, wdyt?

I agree that it could be tackled separately. Maybe we can add a special case for Amazon's providerNameSlug.

@ceyhun
Copy link
Member Author

ceyhun commented Aug 5, 2021

This is the reason why it's required to update the post before displaying the preview, as it removes or empties the className attribute. The same happens when enabling the "Resize for smaller devices" option again.

That's an awesome find @fluiddot! I was looking into preview and remote draft update logic and was suspecting that it wasn't working as expected, it makes much more sense now. Thanks a lot 🙇

@fluiddot
Copy link
Contributor

fluiddot commented Aug 6, 2021

Not sure how we could address this issue but as it's also happening in the web version, I'm wondering if we could tackle it separately and not block this PR, wdyt?

I agree that it could be tackled separately. Maybe we can add a special case for Amazon's providerNameSlug.

Yeah, we could consider Amazon's case as a special one but I'm concerned that we bump in similar cases in the future, I think it would be great if we investigate this further in case it's covering an unknown issue but in any case, I wouldn't block the PR as it can be replicated in the web version.

@ceyhun
Copy link
Member Author

ceyhun commented Aug 11, 2021

@fluiddot I think the className issue is fixed by 14076e2. I've also merged in the changes from inline previews, so this should be ready for another review.

Copy link
Contributor

@fluiddot fluiddot left a comment

Choose a reason for hiding this comment

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

LGTM 🎊 !

Tested on Simulator iPad Pro (12.9-inch) - 4th generation (iOS 14.4) and Samsung Galaxy S20 FE 5G (Android 10).

return (
<SwitchCell
label={ label }
id={ id }
help={ help }
help={ helpLabel }
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed that on Android when tapping over the "Resize for smaller devices" element the ripple animation covers also the help message, not sure if this is expected 🤔 .

Screen_Recording_20210813-153056_WordPress.Pre-Alpha.mp4

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I didn't make changes around that in this PR. I've checked with Audio Block settings and it seems to be the same there. Pressing directly on the toggle doesn't create that effect, so I guess it could be the bottom sheet row being a touchable that's making that happen.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, looks like this is related to the fact that the help message is rendered within the TouchableRipple component:

{ help && (
<Text style={ [ cellHelpStyle, styles.placeholderColor ] }>
{ help }
</Text>
) }

If we're using it in other places I guess it's expected, thanks for checking it 🙇 .

@ceyhun ceyhun merged commit b77066b into trunk Aug 13, 2021
@ceyhun ceyhun deleted the rnmobile/embed-settings branch August 13, 2021 16:00
@github-actions github-actions bot added this to the Gutenberg 11.4 milestone Aug 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Embed Affects the Embed Block 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.

None yet

2 participants