feat: screen presentation and dismiss animations for mobile (#2073)

This commit is contained in:
Mo
2022-11-30 14:37:36 -06:00
committed by GitHub
parent 0e95b451d6
commit 7f2074a6ec
79 changed files with 1338 additions and 878 deletions

View File

@@ -0,0 +1,19 @@
import { ForwardedRef, useEffect, useRef } from 'react'
export const useForwardedRef = <T,>(ref: ForwardedRef<T>, initialValue = null) => {
const targetRef = useRef<T>(initialValue)
useEffect(() => {
if (!ref) {
return
}
if (typeof ref === 'function') {
ref(targetRef.current)
} else {
ref.current = targetRef.current
}
}, [ref])
return targetRef
}

View File

@@ -0,0 +1,37 @@
import { WebApplication } from '@/Application/Application'
import { useApplication } from '@/Components/ApplicationProvider'
import { isMobileScreen, isTabletOrMobileScreen, isTabletScreen } from '@/Utils'
import { useEffect, useState } from 'react'
export function getIsTabletOrMobileScreen(application: WebApplication) {
const isNativeMobile = application.isNativeMobileWeb()
const isTabletOrMobile = isTabletOrMobileScreen() || isNativeMobile
const isTablet = isTabletScreen() || (isNativeMobile && !isMobileScreen())
const isMobile = isMobileScreen() || (isNativeMobile && !isTablet)
return {
isTabletOrMobile,
isTablet,
isMobile,
}
}
export default function useIsTabletOrMobileScreen() {
const [_windowSize, setWindowSize] = useState(0)
const application = useApplication()
useEffect(() => {
const handleResize = () => {
setWindowSize(window.innerWidth)
}
window.addEventListener('resize', handleResize)
handleResize()
return () => {
window.removeEventListener('resize', handleResize)
}
}, [])
return getIsTabletOrMobileScreen(application)
}