ios: generate scrollbars for panels on iOS 13+
This commit is contained in:
parent
a972c1a31a
commit
92e46402ad
5 changed files with 133 additions and 5 deletions
|
|
@ -3,7 +3,8 @@ var Panel = require('./panel'),
|
|||
resize = require('../../events/resize'),
|
||||
doubletab = require('../mixins/double_tap'),
|
||||
html = require('nanohtml'),
|
||||
raw = require('nanohtml/raw')
|
||||
raw = require('nanohtml/raw'),
|
||||
iOS13 = require('../../ui/ios') === 13
|
||||
|
||||
class Modal extends Panel {
|
||||
|
||||
|
|
@ -67,6 +68,14 @@ class Modal extends Panel {
|
|||
this.container.appendChild(this.popup)
|
||||
this.popupContent = DOM.get(this.popup, '.popup-content')[0]
|
||||
|
||||
|
||||
if (iOS13) {
|
||||
for (let dir in this.iosScrollbars) {
|
||||
this.container.removeChild(this.iosScrollbars[dir].container)
|
||||
this.popupContent.appendChild(this.iosScrollbars[dir].container)
|
||||
}
|
||||
}
|
||||
|
||||
// convert dimensions / coordinates to rem
|
||||
var geometry = {}
|
||||
for (var g of ['Width', 'Height', 'Left', 'Top']) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,10 @@ var Container = require('../common/container'),
|
|||
parser = require('../../parser'),
|
||||
html = require('nanohtml'),
|
||||
{enableTraversingGestures, disableTraversingGestures} = require('../../events/drag'),
|
||||
setScrollbarColor = require('../../ui/scrollbar-color')
|
||||
setScrollbarColor = require('../../ui/scrollbar-color'),
|
||||
iOS13 = require('../../ui/ios') === 13,
|
||||
Fader = require('../sliders/fader'), faderDefaults,
|
||||
resize = require('../../events/resize')
|
||||
|
||||
class Panel extends Container() {
|
||||
|
||||
|
|
@ -82,6 +85,57 @@ class Panel extends Container() {
|
|||
|
||||
this.container.classList.add('contains-widgets')
|
||||
|
||||
if (iOS13) {
|
||||
|
||||
faderDefaults = faderDefaults || Fader.defaults()._props()
|
||||
|
||||
this.iosScrollbars = {}
|
||||
for (let dir of ['vertical', 'horizontal']) {
|
||||
this.iosScrollbars[dir] = new Fader({props:{
|
||||
...faderDefaults,
|
||||
design:'compact',
|
||||
horizontal: dir === 'horizontal',
|
||||
range: dir === 'horizontal' ? {min:0, max:1} : {min:1, max:0}
|
||||
}, parent: this})
|
||||
this.iosScrollbars[dir].container.classList.add('not-editable')
|
||||
this.iosScrollbars[dir].container.classList.add('ios-scrollbar')
|
||||
this.iosScrollbars[dir].container.classList.add(dir)
|
||||
this.iosScrollbars[dir]._scrollable = false
|
||||
this.container.appendChild(this.iosScrollbars[dir].container)
|
||||
}
|
||||
this.widget.addEventListener('scroll', ()=>{
|
||||
if (this.iosScrollbars.horizontal._scrollable) this.iosScrollbars.horizontal.setValue(this.widget.scrollLeft / (this.widget.scrollWidth - this.widget.clientWidth))
|
||||
if (this.iosScrollbars.vertical._scrollable) this.iosScrollbars.vertical.setValue(this.widget.scrollTop / (this.widget.scrollHeight - this.widget.clientHeight))
|
||||
})
|
||||
this.iosScrollbars.horizontal.on('change', (e)=>{
|
||||
e.stopPropagation = true
|
||||
this.widget.scrollLeft = parseInt(e.widget.getValue() * (this.widget.scrollWidth - this.widget.clientWidth))
|
||||
})
|
||||
this.iosScrollbars.vertical.on('change', (e)=>{
|
||||
e.stopPropagation = true
|
||||
this.widget.scrollTop = parseInt(e.widget.getValue() * (this.widget.scrollHeight - this.widget.clientHeight))
|
||||
})
|
||||
|
||||
this.checkScrollBars = ()=>{
|
||||
this.iosScrollbars.horizontal.container.style.setProperty('--knob-size', parseInt(this.widget.clientWidth * this.widget.clientWidth / this.widget.scrollWidth) + 'px')
|
||||
this.iosScrollbars.vertical.container.style.setProperty('--knob-size', parseInt(this.widget.clientHeight * this.widget.clientHeight / this.widget.scrollHeight) + 'px')
|
||||
this.iosScrollbars.horizontal._scrollable = this.container.classList.toggle('has-ios-scrollbar-h', this.widget.scrollWidth > this.widget.clientWidth)
|
||||
this.iosScrollbars.vertical._scrollable = this.container.classList.toggle('has-ios-scrollbar-v', this.widget.scrollHeight > this.widget.clientHeight)
|
||||
this.iosScrollbars.vertical.container.classList.toggle('double-scrollbar', this.iosScrollbars.horizontal._scrollable && this.iosScrollbars.vertical._scrollable)
|
||||
if (this.iosScrollbars.horizontal._scrollable) resize.check(this.iosScrollbars.horizontal.container, true)
|
||||
if (this.iosScrollbars.vertical._scrollable) resize.check(this.iosScrollbars.vertical.container, true)
|
||||
|
||||
|
||||
this.iosScrollbars.horizontal.batchDraw()
|
||||
}
|
||||
|
||||
this.on('resize', (event)=>{
|
||||
this.checkScrollBars()
|
||||
}, {element: this.widget})
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -236,8 +290,9 @@ class Panel extends Container() {
|
|||
|
||||
case 'colorBg':
|
||||
this.setCssVariables()
|
||||
case 'colorText':
|
||||
case 'colorWidget':
|
||||
if (iOS13) this.checkScrollBars()
|
||||
case 'colorText':
|
||||
case 'colorFill':
|
||||
case 'colorStroke':
|
||||
case 'alphaStroke':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue