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
Always set theme color to background color ✅ #19391
Changes from 7 commits
37bc45f
99fe621
4290304
dfc75da
42b6ba1
57158a3
9effbcd
8a13ee5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,6 +180,11 @@ const TAG = 'amp-story'; | |
const HIDE_ON_BOOKEND_SELECTOR = | ||
'amp-story-page, .i-amphtml-story-system-layer'; | ||
|
||
/** | ||
* The default light gray for chrome supported theme color. | ||
* @const {string} | ||
*/ | ||
const DEFAULT_THEME_COLOR = '#F1F3F4'; | ||
|
||
/** | ||
* @implements {./media-pool.MediaPoolRoot} | ||
|
@@ -348,6 +353,7 @@ export class AmpStory extends AMP.BaseElement { | |
this.initializeListeners_(); | ||
this.initializeListenersForDev_(); | ||
|
||
this.setThemeColor_(); | ||
this.storeService_.dispatch(Action.TOGGLE_UI, this.getUIType_()); | ||
|
||
this.navigationState_.observe(stateChangeEvent => { | ||
|
@@ -418,6 +424,20 @@ export class AmpStory extends AMP.BaseElement { | |
}); | ||
} | ||
|
||
/** | ||
* @private | ||
*/ | ||
setThemeColor_() { | ||
// The theme color should be copied from the story's primary accent color | ||
// if possible, with the fall back being default light gray. | ||
let meta = document.createElement('meta'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, AMP is very weird about the way that we use |
||
const styles = computedStyle(this.win.document.body); | ||
meta.name = 'theme-color'; | ||
meta.content = styles.getPropertyValue('primary-color') || | ||
DEFAULT_THEME_COLOR; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I think the style is to indent hanging lines +4 spaces from the previous line. So: meta.content = styles.getPropertyValue('primary-color') ||
DEFAULT_THEME_COLOR; |
||
document.getElementsByTagName('head')[0].appendChild(meta); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you want to apply what you used to get the document ( |
||
} | ||
|
||
/** | ||
* @private | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -398,6 +398,14 @@ describes.realWin('amp-story', { | |
}); | ||
}); | ||
|
||
it('should have a meta tag that sets the theme color', () => { | ||
createPages(story.element, 2); | ||
story.buildCallback(); | ||
const metaTags = story.element.getElementsByTagName('meta'); | ||
const metaTagNames = Array.from(metTagNames).map(el => el.name); | ||
expect(metaTagNames.contains('theme-color')).to.be.true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: you could avoid looping through an array by selecting your meta tag directly. Something like |
||
}); | ||
|
||
describe('amp-story consent', () => { | ||
it('should pause the story if there is a consent', () => { | ||
sandbox.stub(Services, 'actionServiceForDoc') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is very unlikely, but publishers may provide a
<meta name="theme-color" ... >
when writing their story HTML. Should we try to check if there's one, so we don't override it?We could check this by doing something like
What do you think about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes a lot of sense! Will add in a check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that unlikely. E.g. the PWA audit in Lighthouse recommends it.