UBER-295: Fix blur'y popups (#3278)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2023-05-29 20:33:19 +07:00 committed by GitHub
parent 6b7e83ce8c
commit 16629be0d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 14 deletions

View File

@ -14,7 +14,7 @@
// limitations under the License. // limitations under the License.
--> -->
<script lang="ts"> <script lang="ts">
import { deviceOptionsStore as deviceInfo } from '..' import { deviceOptionsStore as deviceInfo, resizeObserver } from '..'
import { fitPopupElement } from '../popups' import { fitPopupElement } from '../popups'
import type { AnySvelteComponent, PopupAlignment, PopupOptions, PopupPositionElement } from '../types' import type { AnySvelteComponent, PopupAlignment, PopupOptions, PopupPositionElement } from '../types'
@ -34,6 +34,9 @@
let docSize: boolean = false let docSize: boolean = false
let fullSize: boolean = false let fullSize: boolean = false
let clientWidth = -1
let clientHeight = -1
let options: PopupOptions = { let options: PopupOptions = {
props: { props: {
top: '', top: '',
@ -74,11 +77,11 @@
contentPanel: HTMLElement | undefined contentPanel: HTMLElement | undefined
): void => { ): void => {
if ((fullSize || docSize) && (element === 'float' || element === 'centered')) { if ((fullSize || docSize) && (element === 'float' || element === 'centered')) {
options = fitPopupElement(modalHTML, 'full', contentPanel) options = fitPopupElement(modalHTML, 'full', contentPanel, clientWidth, clientHeight)
options.props.maxHeight = '100vh' options.props.maxHeight = '100vh'
if (!modalHTML.classList.contains('fullsize')) modalHTML.classList.add('fullsize') if (!modalHTML.classList.contains('fullsize')) modalHTML.classList.add('fullsize')
} else { } else {
options = fitPopupElement(modalHTML, element, contentPanel) options = fitPopupElement(modalHTML, element, contentPanel, clientWidth, clientHeight)
if (modalHTML.classList.contains('fullsize')) modalHTML.classList.remove('fullsize') if (modalHTML.classList.contains('fullsize')) modalHTML.classList.remove('fullsize')
} }
options.fullSize = fullSize options.fullSize = fullSize
@ -107,6 +110,8 @@
let oldModalHTML: HTMLElement | undefined = undefined let oldModalHTML: HTMLElement | undefined = undefined
$: if (modalHTML !== undefined && oldModalHTML !== modalHTML) { $: if (modalHTML !== undefined && oldModalHTML !== modalHTML) {
clientWidth = -1
clientHeight = -1
oldModalHTML = modalHTML oldModalHTML = modalHTML
fitPopup(modalHTML, element, contentPanel) fitPopup(modalHTML, element, contentPanel)
showing = true showing = true
@ -152,6 +157,11 @@
style:min-width={options.props.minWidth} style:min-width={options.props.minWidth}
style:min-height={options.props.minHeight} style:min-height={options.props.minHeight}
style:transform={options.props.transform} style:transform={options.props.transform}
use:resizeObserver={(element) => {
clientWidth = element.clientWidth
clientHeight = element.clientHeight
fitPopupInstance()
}}
> >
<svelte:component <svelte:component
this={is} this={is}

View File

@ -183,7 +183,9 @@ export function fitPopupPositionedElement (
export function fitPopupElement ( export function fitPopupElement (
modalHTML: HTMLElement, modalHTML: HTMLElement,
element?: PopupAlignment, element?: PopupAlignment,
contentPanel?: HTMLElement contentPanel?: HTMLElement,
clientWidth?: number,
clientHeight?: number
): PopupOptions { ): PopupOptions {
let show = true let show = true
const newProps: Record<string, string | number> = {} const newProps: Record<string, string | number> = {}
@ -205,9 +207,13 @@ export function fitPopupElement (
show = true show = true
} else if (element === 'top') { } else if (element === 'top') {
newProps.top = '15vh' newProps.top = '15vh'
newProps.left = '50%'
newProps.maxHeight = '75vh' newProps.maxHeight = '75vh'
if (clientWidth !== undefined && clientHeight !== undefined) {
newProps.left = `calc(50% - ${clientWidth / 2}px`
} else {
newProps.left = '50%'
newProps.transform = 'translateX(-50%)' newProps.transform = 'translateX(-50%)'
}
show = true show = true
} else if (element === 'float') { } else if (element === 'float') {
newProps.top = 'calc(var(--status-bar-height) + 4px)' newProps.top = 'calc(var(--status-bar-height) + 4px)'
@ -216,9 +222,14 @@ export function fitPopupElement (
newProps.right = '4px' newProps.right = '4px'
show = true show = true
} else if (element === 'center') { } else if (element === 'center') {
if (clientWidth !== undefined && clientHeight !== undefined) {
newProps.top = `calc(50% - ${clientHeight / 2}px`
newProps.left = `calc(50% - ${clientWidth / 2}px`
} else {
newProps.top = '50%' newProps.top = '50%'
newProps.left = '50%' newProps.left = '50%'
newProps.transform = 'translate(-50%, -50%)' newProps.transform = 'translate(-50%, -50%)'
}
show = true show = true
} else if (element === 'centered') { } else if (element === 'centered') {
newProps.top = newProps.bottom = '15%' newProps.top = newProps.bottom = '15%'
@ -285,18 +296,28 @@ export function fitPopupElement (
newProps.top = '15%' newProps.top = '15%'
} }
newProps.bottom = '12px' newProps.bottom = '12px'
if (clientWidth !== undefined && clientHeight !== undefined) {
newProps.left = `calc(50% - ${clientWidth / 2}px`
} else {
newProps.left = '50%' newProps.left = '50%'
newProps.transform = 'translateX(-50%)' newProps.transform = 'translateX(-50%)'
}
} else if (element === 'help-center') { } else if (element === 'help-center') {
newProps.top = 'calc(var(--status-bar-height) + 12px)' newProps.top = 'calc(var(--status-bar-height) + 12px)'
newProps.bottom = '12px' newProps.bottom = '12px'
newProps.right = '12px' newProps.right = '12px'
show = true show = true
} }
} else {
if (clientWidth !== undefined && clientHeight !== undefined) {
newProps.top = `calc(50% - ${clientHeight / 2}px`
newProps.left = `calc(50% - ${clientWidth / 2}px`
} else { } else {
newProps.top = '50%' newProps.top = '50%'
newProps.left = '50%' newProps.left = '50%'
newProps.transform = 'translate(-50%, -50%)' newProps.transform = 'translate(-50%, -50%)'
}
show = true show = true
} }
// applyStyle(newProps, modalHTML) // applyStyle(newProps, modalHTML)