mirror of
https://github.com/ikun0014/lx-music-mobile.git
synced 2025-07-04 05:52:10 +08:00
修复键盘弹出时背景图片出现缩放的问题
This commit is contained in:
parent
4a13c90f62
commit
4cddb9c947
@ -1,16 +1,18 @@
|
||||
import { memo, useCallback, useRef } from 'react'
|
||||
import { type LayoutChangeEvent, StyleSheet, View, StatusBar } from 'react-native'
|
||||
import { memo, useCallback, useRef, useEffect } from 'react'
|
||||
import { type LayoutChangeEvent, StyleSheet, View, StatusBar, Dimensions } from 'react-native'
|
||||
import commonState from '@/store/common/state'
|
||||
import { setStatusbarHeight } from '@/core/common'
|
||||
import { windowSizeTools, getWindowSize } from '@/utils/windowSizeTools'
|
||||
|
||||
|
||||
export default memo(() => {
|
||||
// const viewRef = useRef<View>(null)
|
||||
const currentHeightRef = useRef(commonState.statusbarHeight)
|
||||
const dimensionsChangedRef = useRef(true)
|
||||
const handleLayout = useCallback(({ nativeEvent: { layout } }: LayoutChangeEvent | { nativeEvent: { layout: { width: number, height: number } } }) => {
|
||||
// console.log('handleLayout')
|
||||
if (!dimensionsChangedRef.current) return
|
||||
void getWindowSize().then(size => {
|
||||
dimensionsChangedRef.current = false
|
||||
// console.log(layout, size)
|
||||
const height = parseFloat(size.height.toFixed(2)) >= parseFloat(layout.height.toFixed(2))
|
||||
? 0
|
||||
@ -27,9 +29,10 @@ export default memo(() => {
|
||||
}
|
||||
})
|
||||
}, [])
|
||||
// useEffect(() => {
|
||||
useEffect(() => {
|
||||
// let timeout: NodeJS.Timeout | null = null
|
||||
// Dimensions.addEventListener('change', () => {
|
||||
const subscription = Dimensions.addEventListener('change', () => {
|
||||
dimensionsChangedRef.current = true
|
||||
// if (timeout) clearTimeout(timeout)
|
||||
// timeout = setTimeout(() => {
|
||||
// timeout = null
|
||||
@ -37,8 +40,12 @@ export default memo(() => {
|
||||
// handleLayout({ nativeEvent: { layout: { width, height } } })
|
||||
// })
|
||||
// }, 100)
|
||||
// })
|
||||
// }, [])
|
||||
})
|
||||
|
||||
return () => {
|
||||
subscription.remove()
|
||||
}
|
||||
}, [])
|
||||
return (<View style={StyleSheet.absoluteFill} onLayout={handleLayout} />)
|
||||
}, () => true)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user