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

Ensure icons for image/video are SVG components #15863

Merged
merged 1 commit into from
May 30, 2019

Conversation

koke
Copy link
Contributor

@koke koke commented May 28, 2019

In #15551, these were changed to support passing props, but that also means
that when you pass the video icon to the Icon component, it won't inject the
right size, since it's not a SVG component.

Instead, we can export the new function to allow for a customizable icon, while
exporting the SVG component by default.

How has this been tested?

Tested this through wordpress-mobile/gutenberg-mobile#1036 by unregistering the video block, and viewing a post with videos in it.

Screenshots

Before:

IMG_723F87963C95-1

After:

IMG_B8C8445DBCCD-1

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.

In #15551, these were changed to support passing props, but that also means
that when you pass the video icon to the `Icon` component, it won't inject the
right size, since it's not a SVG component.

Instead, we can export the new function to allow for a customizable icon, while
exporting the SVG component by default.
@koke koke added the Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) label May 28, 2019
@koke koke requested a review from hypest May 28, 2019 11:08
return <SVG viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" { ...props }><Path d="M0,0h24v24H0V0z" fill="none" /><Path d="m19 5v14h-14v-14h14m0-2h-14c-1.1 0-2 0.9-2 2v14c0 1.1 0.9 2 2 2h14c1.1 0 2-0.9 2-2v-14c0-1.1-0.9-2-2-2z" /><Path d="m14.14 11.86l-3 3.87-2.14-2.59-3 3.86h12l-3.86-5.14z" /></SVG>;
}

export default svg;
export default SvgIcon( {} );
Copy link
Contributor

Choose a reason for hiding this comment

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

I know these icon.js files are supposed to be normalized across all block types. Both the previous and the new notations seem wrong to me (compared to the other files)

cc @gziolo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the idea is to revert this in #15778, and this is just a temporary fix for this week's mobile release. @hypest should we create a 1.6 branch and merge this there instead of master? We can then revert the icon changes as part of #15778

Copy link
Member

Choose a reason for hiding this comment

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

In other places, we do something as follows:

return (
    <SVG viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><Path d="M0,0h24v24H0V0z" fill="none" /><Path d="m19 5v14h-14v-14h14m0-2h-14c-1.1 0-2 0.9-2 2v14c0 1.1 0.9 2 2 2h14c1.1 0 2-0.9 2-2v-14c0-1.1-0.9-2-2-2z" /><Path d="m14.14 11.86l-3 3.87-2.14-2.59-3 3.86h12l-3.86-5.14z" /></SVG>;
);

it's an element rather than a component. If that's an issue we can think about ways to update all block icons.

Copy link
Member

@gziolo gziolo May 29, 2019

Choose a reason for hiding this comment

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

Technically speaking, you can use cloneElement( icon, extraProps ) to inject more props as well.

See: https://reactjs.org/docs/react-api.html#cloneelement

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed the base branch to rnmobile/release-v1.6.0 and noted the required changes in the upcoming PR: #15778 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

Technically speaking, you can use cloneElement( icon, extraProps ) to inject more props as well.

I used that API in here and to be honest, it felt kinda awkward, a bit hacky and probably not a well maintainable solution. AFAICT, the Gutenberg code leans more on HOCs to do augmentations on components and we probably should try something similar here? I.e. perhaps the assumptions of the Icon code here are too strict and inflexible?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess we could replace that check with extending the SVG component to translate the size prop into width/height

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 going to review approve and merge this PR (to the release branch, not master) if it's working OK. We'll need to work on a separate PR to make it mergable to master.

@koke koke changed the base branch from master to rnmobile/release-v1.6.0 May 29, 2019 08:02
@hypest
Copy link
Contributor

hypest commented May 30, 2019

@koke , should we do the same treatment to image/icon-retry and video/icon-retry too?

@koke
Copy link
Contributor Author

koke commented May 30, 2019

The retry icons are only used explicitly by the blocks, so there’s no need. The problem was only with the default icon, as the missing block was trying to use that

@hypest
Copy link
Contributor

hypest commented May 30, 2019

Not a blocker for this PR but, would it still make sense to unify the implementation to avoid confusion? If yes, we can do it in a separate PR or this one if quick enough.

@koke
Copy link
Contributor Author

koke commented May 30, 2019

That's already done in #15778 😁

@hypest
Copy link
Contributor

hypest commented May 30, 2019

That's already done in #15778 😁

Works for me!

Copy link
Contributor

@hypest hypest left a comment

Choose a reason for hiding this comment

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

LGTM!

As discussed over Slack, we might want to simplify the SvgIcon( {} ) pattern to a simpler one (that won't pass anything at all) in the PR that will supersede this, far from a blocker for this PR.

@hypest hypest merged commit 4319ad3 into rnmobile/release-v1.6.0 May 30, 2019
@hypest hypest deleted the rnmobile/fix-missing-video-icon branch May 30, 2019 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants