mobile: apply root's (or themes) background color the the browser's topbar when possible
This commit is contained in:
parent
4451cffd36
commit
f891442e28
9 changed files with 73 additions and 35 deletions
|
|
@ -5,6 +5,7 @@ require('./notifications')
|
|||
require('./ui-workspace')
|
||||
require('./main-menu')
|
||||
require('./ui-console')
|
||||
require('./utils').updateMobileThemeColor()
|
||||
|
||||
if (!navigator.userAgent.match(/Android|iPhone|iPad|iPod/i)) {
|
||||
require('./ui-keyboard')
|
||||
|
|
|
|||
|
|
@ -1,32 +0,0 @@
|
|||
var chroma = require('chroma-js'),
|
||||
fastdom = require('fastdom')
|
||||
|
||||
module.exports = (container)=>{
|
||||
|
||||
fastdom.measure(()=>{
|
||||
|
||||
var computedStyle = window.getComputedStyle(container),
|
||||
alpha = parseFloat(computedStyle.getPropertyValue('--alpha-scrollbar')),
|
||||
alphaOn = parseFloat(computedStyle.getPropertyValue('--alpha-scrollbar-on')),
|
||||
color = computedStyle.getPropertyValue('--color-fill').trim()
|
||||
|
||||
if (color === 'transparent') {
|
||||
// prevent chroma-js error
|
||||
// irrelevant case, but still...
|
||||
color = 'rgb(0, 0, 0)'
|
||||
alpha = 0
|
||||
alphaOn = 0
|
||||
}
|
||||
|
||||
if (color) {
|
||||
fastdom.mutate(()=>{
|
||||
try {
|
||||
container.style.setProperty('--color-scrollbar', chroma(color).alpha(alpha).css())
|
||||
container.style.setProperty('--color-scrollbar-on', chroma(color).alpha(alphaOn).css())
|
||||
} catch(e) {}
|
||||
})
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
var UiWidget = require('./ui-widget'),
|
||||
setScrollbarColor = require('./scrollbar-color')
|
||||
{setScrollbarColor} = require('./utils')
|
||||
|
||||
class UiWorkspace extends UiWidget {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
var chroma = require('chroma-js'),
|
||||
fastdom = require('fastdom'),
|
||||
widgetManager = require('../managers/widgets')
|
||||
|
||||
module.exports = {
|
||||
|
||||
|
|
@ -10,6 +13,55 @@ module.exports = {
|
|||
return String(string).replace(/\^[^\s]{2,}/g,(x)=>{return module.exports.icon(x.substring(1))})
|
||||
},
|
||||
|
||||
setScrollbarColor: function(container) {
|
||||
|
||||
fastdom.measure(()=>{
|
||||
|
||||
var computedStyle = window.getComputedStyle(container),
|
||||
alpha = parseFloat(computedStyle.getPropertyValue('--alpha-scrollbar')),
|
||||
alphaOn = parseFloat(computedStyle.getPropertyValue('--alpha-scrollbar-on')),
|
||||
color = computedStyle.getPropertyValue('--color-fill').trim()
|
||||
|
||||
if (color === 'transparent') {
|
||||
// prevent chroma-js error
|
||||
// irrelevant case, but still...
|
||||
color = 'rgb(0, 0, 0)'
|
||||
alpha = 0
|
||||
alphaOn = 0
|
||||
}
|
||||
|
||||
if (color) {
|
||||
fastdom.mutate(()=>{
|
||||
try {
|
||||
container.style.setProperty('--color-scrollbar', chroma(color).alpha(alpha).css())
|
||||
container.style.setProperty('--color-scrollbar-on', chroma(color).alpha(alphaOn).css())
|
||||
} catch(e) {}
|
||||
})
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
},
|
||||
|
||||
updateMobileThemeColor: function(){
|
||||
|
||||
fastdom.measure(()=>{
|
||||
var root = widgetManager.getWidgetById('root')[0]
|
||||
var style = window.getComputedStyle(root ? root.widget : document.documentElement)
|
||||
|
||||
fastdom.mutate(()=>{
|
||||
|
||||
var color = style.getPropertyValue('--color-background').trim()
|
||||
try {
|
||||
for (var el of DOM.get('meta[name="theme-color"], meta[name="apple-mobile-web-app-status-bar-style"]')) {
|
||||
el.setAttribute('content', color)
|
||||
}
|
||||
} catch(e) {}
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue