Skip to content
This repository has been archived by the owner on Aug 13, 2023. It is now read-only.

Image placeholder amp support #4334

Merged
merged 20 commits into from
Feb 24, 2021
Merged

Image placeholder amp support #4334

merged 20 commits into from
Feb 24, 2021

Conversation

HarveyPeachey
Copy link
Contributor

@HarveyPeachey HarveyPeachey commented Feb 10, 2021

Resolves bbc/simorgh#8811

Overall change: Adds an amp-image fallback component for amp pages. This shows a placeholder while the amp-image is loading and also a fallback if the image cannot load. All the sizes and styling for the placeholder and fallbacks are based on the existing canonical fallback whilst adhering to AMP's fundamentals.

Code changes:

  • Added separate file for amp image placeholder
  • Added a storybook to show amp image placeholders under Images
  • Added dark mode support
  • Added snapshot tests
  • Updated README to reflect this addition

  • I have assigned myself to this PR and the corresponding issues
  • Automated jest tests added (for new features) or updated (for existing features)
  • This PR requires manual testing

…placeholder, added switching logic for dark mode
@HarveyPeachey HarveyPeachey self-assigned this Feb 10, 2021
@HarveyPeachey HarveyPeachey added the ws-articles Tasks for the WS Articles Team label Feb 11, 2021
@github-actions
Copy link

Checkout your storybook preview here http://psammead-preview.tools.bbc.co.uk/4334

@HarveyPeachey HarveyPeachey marked this pull request as ready for review February 17, 2021 15:55
const bgImageDark = `data:image/svg+xml;base64,${BBC_BLOCKS_DARK_MODE}`;
const bgImageRegular = `data:image/svg+xml;base64,${BBC_BLOCKS}`;

const AmpImgPlaceholderContainer = ({
Copy link
Contributor Author

@HarveyPeachey HarveyPeachey Feb 17, 2021

Choose a reason for hiding this comment

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

Attempted to use emotion to create a styled component instead of using the inline style method. However currently fallback isn't supported in the installed version of emotion as a valid prop so it is being stripped out on render. This has been fixed here: emotion-js/emotion#2224 and is now supported in the latest version of emotion.

A seperate issue will be created to amend this once all the emotion issues are fixed within Simorgh and Psammead is updated to the latest version of emotion.

This is what it should look like:

const AmpImgPlaceholderContainer = styled.div`
  background-color: ${({ darkMode }) => (darkMode ? C_SHADOW : C_LUNAR)};
`;

Copy link
Contributor

Choose a reason for hiding this comment

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

We have upgraded to Emotion 11, have we not got the version with this fix?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're currently on version 11.0.0 https://github.com/bbc/psammead/blob/4737f88e2cf5efab353b32c916817c2615d23c23/package.json#L46-L48

There was a new version 11.1.5 that came out a few days ago which included the fix from emotion-js/emotion#2224.

But it looks like it's been reverted https://www.npmjs.com/package/emotion, probably due to the Opera mini mishap. So currently there isn't a live build with the fix. Although I tested it before it was reverted and it worked a treat👌

Copy link
Contributor

Choose a reason for hiding this comment

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

We've put it back to a pretty new version, I think we might wanna upgrade and use the new feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep definitely agree, going to merge this PR in first and apply the improvements in a follow up PR as this has been ongoing for quite some time now.

);
};

const AmpImgPlaceholder = props => (
Copy link
Contributor Author

@HarveyPeachey HarveyPeachey Feb 17, 2021

Choose a reason for hiding this comment

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

Attempted to also use emotion here but for some reason the styling wasn't applying and seemed to be stripped out. Here's the code I tried:

const AmpImgPlaceholder = styled('amp-img')`
  position: 'absolute';
  top: '50%';
  left: '50%';
  transform: 'translate(-50%, -50%)';
`;

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, maybe worth raising an issue in the emotion repo, there seems to be patchy support for styling amp components?

@@ -0,0 +1,91 @@
/* eslint react/prop-types: 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.

@HarveyPeachey HarveyPeachey added cross-team For visibility for both World Service teams (Engage & Media) bug Something isn't working and removed ws-articles Tasks for the WS Articles Team labels Feb 17, 2021
Copy link
Contributor

@FK78 FK78 left a comment

Choose a reason for hiding this comment

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

Nice work!

Copy link
Contributor

@andrewscfc andrewscfc left a comment

Choose a reason for hiding this comment

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

Great work, one or two bits we should work with emotion on I think

const bgImageDark = `data:image/svg+xml;base64,${BBC_BLOCKS_DARK_MODE}`;
const bgImageRegular = `data:image/svg+xml;base64,${BBC_BLOCKS}`;

const AmpImgPlaceholderContainer = ({
Copy link
Contributor

Choose a reason for hiding this comment

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

We have upgraded to Emotion 11, have we not got the version with this fix?

);
};

const AmpImgPlaceholder = props => (
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, maybe worth raising an issue in the emotion repo, there seems to be patchy support for styling amp components?

@HarveyPeachey HarveyPeachey merged commit db3a61b into latest Feb 24, 2021
@HarveyPeachey HarveyPeachey deleted the image-placeholder-amp branch February 24, 2021 16:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working cross-team For visibility for both World Service teams (Engage & Media)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[PS AMP] Transparent images show the BBC blocks placeholder behind
4 participants