mirror of
https://github.com/ikun0014/lx-music-mobile.git
synced 2025-05-23 22:37:41 +08:00
更改应用窗口大小获取方式,尝试解决在某些设备上的背景、弹出菜单显示问题
This commit is contained in:
parent
f6fce15440
commit
3c5e7a91da
@ -10,6 +10,7 @@ import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|||||||
|
|
||||||
public class UtilsEvent {
|
public class UtilsEvent {
|
||||||
final String SCREEN_STATE = "screen-state";
|
final String SCREEN_STATE = "screen-state";
|
||||||
|
final String SCREEN_SIZE_CHANGED = "screen-size-changed";
|
||||||
|
|
||||||
private final ReactApplicationContext reactContext;
|
private final ReactApplicationContext reactContext;
|
||||||
UtilsEvent(ReactApplicationContext reactContext) { this.reactContext = reactContext; }
|
UtilsEvent(ReactApplicationContext reactContext) { this.reactContext = reactContext; }
|
||||||
|
@ -14,6 +14,8 @@ import android.net.wifi.WifiManager;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewTreeObserver;
|
||||||
|
import android.view.Window;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
|
||||||
import androidx.core.app.LocaleManagerCompat;
|
import androidx.core.app.LocaleManagerCompat;
|
||||||
@ -346,5 +348,25 @@ public class UtilsModule extends ReactContextBaseJavaModule {
|
|||||||
// });
|
// });
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
@ReactMethod
|
||||||
|
public void getWindowSize(Promise promise) {
|
||||||
|
WritableMap params = Arguments.createMap();
|
||||||
|
|
||||||
|
Activity currentActivity = reactContext.getCurrentActivity();
|
||||||
|
if (currentActivity == null) {
|
||||||
|
params.putInt("width", 0);
|
||||||
|
params.putInt("height", 0);
|
||||||
|
promise.resolve(params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 获取当前应用可用区域大小
|
||||||
|
Window window = currentActivity.getWindow();
|
||||||
|
View decorView = window.getDecorView();
|
||||||
|
int width = decorView.getMeasuredWidth();
|
||||||
|
int height = decorView.getMeasuredHeight();
|
||||||
|
params.putInt("width", width);
|
||||||
|
params.putInt("height", height);
|
||||||
|
promise.resolve(params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
- 通过歌曲菜单添加不喜欢歌曲时需要二次确认防止手抖
|
- 通过歌曲菜单添加不喜欢歌曲时需要二次确认防止手抖
|
||||||
- 减慢歌词详情页歌词滚动速度
|
- 减慢歌词详情页歌词滚动速度
|
||||||
|
- 更改应用窗口大小获取方式,尝试解决在某些设备上的背景、弹出菜单显示问题
|
||||||
|
|
||||||
### 修复
|
### 修复
|
||||||
|
|
||||||
|
132
src/app.ts
132
src/app.ts
@ -2,82 +2,82 @@ import '@/utils/errorHandle'
|
|||||||
import { init as initLog } from '@/utils/log'
|
import { init as initLog } from '@/utils/log'
|
||||||
import { bootLog, getBootLog } from '@/utils/bootLog'
|
import { bootLog, getBootLog } from '@/utils/bootLog'
|
||||||
import '@/config/globalData'
|
import '@/config/globalData'
|
||||||
import { init as initNavigation, navigations } from '@/navigation'
|
|
||||||
import { getFontSize } from '@/utils/data'
|
import { getFontSize } from '@/utils/data'
|
||||||
import { Alert } from 'react-native'
|
import { Alert } from 'react-native'
|
||||||
import { exitApp } from './utils/nativeModules/utils'
|
import { exitApp } from './utils/nativeModules/utils'
|
||||||
|
import { windowSizeTools } from './utils/windowSizeTools'
|
||||||
|
import { listenLaunchEvent } from './navigation/regLaunchedEvent'
|
||||||
|
|
||||||
console.log('starting app...')
|
console.log('starting app...')
|
||||||
let isInited = false
|
listenLaunchEvent()
|
||||||
let handlePushedHomeScreen: () => void | Promise<void>
|
|
||||||
|
|
||||||
const tryGetBootLog = () => {
|
void Promise.all([getFontSize(), windowSizeTools.init()]).then(async([fontSize]) => {
|
||||||
try {
|
global.lx.fontSize = fontSize
|
||||||
return getBootLog()
|
|
||||||
} catch (err) {
|
|
||||||
return 'Get boot log failed.'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleInit = async() => {
|
|
||||||
if (isInited) return
|
|
||||||
void initLog()
|
|
||||||
global.lx.fontSize = await getFontSize()
|
|
||||||
bootLog('Font size setting loaded.')
|
bootLog('Font size setting loaded.')
|
||||||
const { default: init } = await import('@/core/init')
|
|
||||||
try {
|
let isInited = false
|
||||||
handlePushedHomeScreen = await init()
|
let handlePushedHomeScreen: () => void | Promise<void>
|
||||||
} catch (err: any) {
|
|
||||||
Alert.alert('初始化失败 (Init Failed)', `Boot Log:\n${tryGetBootLog()}\n\n${(err.stack ?? err.message) as string}`, [
|
const tryGetBootLog = () => {
|
||||||
{
|
try {
|
||||||
text: 'Exit',
|
return getBootLog()
|
||||||
onPress() {
|
} catch (err) {
|
||||||
exitApp()
|
return 'Get boot log failed.'
|
||||||
},
|
}
|
||||||
},
|
|
||||||
], {
|
|
||||||
cancelable: false,
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
isInited ||= true
|
|
||||||
}
|
|
||||||
|
|
||||||
initNavigation(async() => {
|
const handleInit = async() => {
|
||||||
await handleInit()
|
if (isInited) return
|
||||||
if (!isInited) return
|
void initLog()
|
||||||
// import('@/utils/nativeModules/cryptoTest')
|
const { default: init } = await import('@/core/init')
|
||||||
|
try {
|
||||||
await navigations.pushHomeScreen().then(() => {
|
handlePushedHomeScreen = await init()
|
||||||
void handlePushedHomeScreen()
|
} catch (err: any) {
|
||||||
}).catch((err: any) => {
|
Alert.alert('初始化失败 (Init Failed)', `Boot Log:\n${tryGetBootLog()}\n\n${(err.stack ?? err.message) as string}`, [
|
||||||
Alert.alert('Error', err.message, [
|
{
|
||||||
{
|
text: 'Exit',
|
||||||
text: 'Exit',
|
onPress() {
|
||||||
onPress() {
|
exitApp()
|
||||||
exitApp()
|
},
|
||||||
},
|
},
|
||||||
},
|
], {
|
||||||
], {
|
cancelable: false,
|
||||||
cancelable: false,
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
isInited ||= true
|
||||||
|
}
|
||||||
|
const { init: initNavigation, navigations } = await import('@/navigation')
|
||||||
|
|
||||||
|
initNavigation(async() => {
|
||||||
|
await handleInit()
|
||||||
|
if (!isInited) return
|
||||||
|
// import('@/utils/nativeModules/cryptoTest')
|
||||||
|
|
||||||
|
await navigations.pushHomeScreen().then(() => {
|
||||||
|
void handlePushedHomeScreen()
|
||||||
|
}).catch((err: any) => {
|
||||||
|
Alert.alert('Error', err.message, [
|
||||||
|
{
|
||||||
|
text: 'Exit',
|
||||||
|
onPress() {
|
||||||
|
exitApp()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
], {
|
||||||
|
cancelable: false,
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
}).catch((err) => {
|
||||||
|
Alert.alert('初始化失败 (Init Failed)', `Boot Log:\n\n${(err.stack ?? err.message) as string}`, [
|
||||||
|
{
|
||||||
|
text: 'Exit',
|
||||||
|
onPress() {
|
||||||
|
exitApp()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
], {
|
||||||
|
cancelable: false,
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// const createProxy = () => {
|
|
||||||
// return new Proxy(function() {}, {
|
|
||||||
// get: (_target, prop, receiver) => {
|
|
||||||
// let propName = prop.toString()
|
|
||||||
// console.log('proxy get', propName)
|
|
||||||
// return createProxy()
|
|
||||||
// },
|
|
||||||
// // eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
||||||
// apply: (target, thisArg, argumentsList) => {
|
|
||||||
// console.log('proxy apply')
|
|
||||||
// return '56'
|
|
||||||
// },
|
|
||||||
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
// const proxy = createProxy()
|
|
||||||
// console.log(proxy.aaa())
|
|
||||||
|
@ -5,7 +5,7 @@ import Text from '@/components/common/Text'
|
|||||||
import { useMyList } from '@/store/list/hook'
|
import { useMyList } from '@/store/list/hook'
|
||||||
import ListItem, { styles as listStyles } from './ListItem'
|
import ListItem, { styles as listStyles } from './ListItem'
|
||||||
import CreateUserList from './CreateUserList'
|
import CreateUserList from './CreateUserList'
|
||||||
import { useDimensions } from '@/utils/hooks'
|
import { useWindowSize } from '@/utils/hooks'
|
||||||
import { useTheme } from '@/store/theme/hook'
|
import { useTheme } from '@/store/theme/hook'
|
||||||
import { useI18n } from '@/lang'
|
import { useI18n } from '@/lang'
|
||||||
import { createStyle } from '@/utils/tools'
|
import { createStyle } from '@/utils/tools'
|
||||||
@ -54,14 +54,14 @@ export default ({ musicInfo, onPress }: {
|
|||||||
musicInfo: LX.Music.MusicInfo
|
musicInfo: LX.Music.MusicInfo
|
||||||
onPress: (listInfo: LX.List.MyListInfo) => void
|
onPress: (listInfo: LX.List.MyListInfo) => void
|
||||||
}) => {
|
}) => {
|
||||||
const { window } = useDimensions()
|
const windowSize = useWindowSize()
|
||||||
const allList = useMyList()
|
const allList = useMyList()
|
||||||
const itemWidth = useMemo(() => {
|
const itemWidth = useMemo(() => {
|
||||||
let w = Math.floor(window.width * 0.9 - PADDING)
|
let w = Math.floor(windowSize.width * 0.9 - PADDING)
|
||||||
let n = Math.floor(w / MIN_WIDTH)
|
let n = Math.floor(w / MIN_WIDTH)
|
||||||
if (n > 10) n = 10
|
if (n > 10) n = 10
|
||||||
return Math.floor((w - 1) / n)
|
return Math.floor((w - 1) / n)
|
||||||
}, [window])
|
}, [windowSize])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ScrollView style={{ flexGrow: 0 }}>
|
<ScrollView style={{ flexGrow: 0 }}>
|
||||||
|
@ -5,7 +5,7 @@ import Text from '@/components/common/Text'
|
|||||||
import { useMyList } from '@/store/list/hook'
|
import { useMyList } from '@/store/list/hook'
|
||||||
import ListItem, { styles as listStyles } from './ListItem'
|
import ListItem, { styles as listStyles } from './ListItem'
|
||||||
import CreateUserList from '../MusicAddModal/CreateUserList'
|
import CreateUserList from '../MusicAddModal/CreateUserList'
|
||||||
import { useDimensions } from '@/utils/hooks'
|
import { useWindowSize } from '@/utils/hooks'
|
||||||
import { useTheme } from '@/store/theme/hook'
|
import { useTheme } from '@/store/theme/hook'
|
||||||
import { useI18n } from '@/lang'
|
import { useI18n } from '@/lang'
|
||||||
import { createStyle } from '@/utils/tools'
|
import { createStyle } from '@/utils/tools'
|
||||||
@ -52,14 +52,14 @@ export default ({ listId, onPress }: {
|
|||||||
listId: string
|
listId: string
|
||||||
onPress: (listInfo: LX.List.MyListInfo) => void
|
onPress: (listInfo: LX.List.MyListInfo) => void
|
||||||
}) => {
|
}) => {
|
||||||
const { window } = useDimensions()
|
const windowSize = useWindowSize()
|
||||||
const allList = useMyList().filter(l => l.id != listId)
|
const allList = useMyList().filter(l => l.id != listId)
|
||||||
const itemWidth = useMemo(() => {
|
const itemWidth = useMemo(() => {
|
||||||
let w = Math.floor(window.width * 0.9 - PADDING)
|
let w = Math.floor(windowSize.width * 0.9 - PADDING)
|
||||||
let n = Math.floor(w / MIN_WIDTH)
|
let n = Math.floor(w / MIN_WIDTH)
|
||||||
if (n > 10) n = 10
|
if (n > 10) n = 10
|
||||||
return Math.floor((w - 1) / n)
|
return Math.floor((w - 1) / n)
|
||||||
}, [window])
|
}, [windowSize])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ScrollView style={{ flexGrow: 0 }}>
|
<ScrollView style={{ flexGrow: 0 }}>
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { useEffect, useState } from 'react'
|
// import { useEffect, useState } from 'react'
|
||||||
import { Dimensions, View, type LayoutChangeEvent } from 'react-native'
|
import { View } from 'react-native'
|
||||||
import { useTheme } from '@/store/theme/hook'
|
import { useTheme } from '@/store/theme/hook'
|
||||||
import ImageBackground from '@/components/common/ImageBackground'
|
import ImageBackground from '@/components/common/ImageBackground'
|
||||||
// import { useDimensions } from '@/utils/hooks'
|
import { useWindowSize } from '@/utils/hooks'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
children: React.ReactNode
|
children: React.ReactNode
|
||||||
@ -11,31 +11,31 @@ interface Props {
|
|||||||
|
|
||||||
export default ({ children }: Props) => {
|
export default ({ children }: Props) => {
|
||||||
const theme = useTheme()
|
const theme = useTheme()
|
||||||
// const { window } = useDimensions()
|
const windowSize = useWindowSize()
|
||||||
const [wh, setWH] = useState<{ width: number | string, height: number | string }>({ width: '100%', height: Dimensions.get('screen').height })
|
// const [wh, setWH] = useState<{ width: number | string, height: number | string }>({ width: '100%', height: Dimensions.get('screen').height })
|
||||||
|
|
||||||
// 固定宽高度 防止弹窗键盘时大小改变导致背景被缩放
|
// 固定宽高度 防止弹窗键盘时大小改变导致背景被缩放
|
||||||
useEffect(() => {
|
// useEffect(() => {
|
||||||
const onChange = () => {
|
// const onChange = () => {
|
||||||
setWH({ width: '100%', height: '100%' })
|
// setWH({ width: '100%', height: '100%' })
|
||||||
}
|
// }
|
||||||
|
|
||||||
const changeEvent = Dimensions.addEventListener('change', onChange)
|
// const changeEvent = Dimensions.addEventListener('change', onChange)
|
||||||
return () => {
|
// return () => {
|
||||||
changeEvent.remove()
|
// changeEvent.remove()
|
||||||
}
|
// }
|
||||||
}, [])
|
// }, [])
|
||||||
const handleLayout = (e: LayoutChangeEvent) => {
|
// const handleLayout = (e: LayoutChangeEvent) => {
|
||||||
// console.log('handleLayout', e.nativeEvent)
|
// // console.log('handleLayout', e.nativeEvent)
|
||||||
// console.log(Dimensions.get('screen'))
|
// // console.log(Dimensions.get('screen'))
|
||||||
setWH({ width: e.nativeEvent.layout.width, height: Dimensions.get('screen').height })
|
// setWH({ width: e.nativeEvent.layout.width, height: Dimensions.get('screen').height })
|
||||||
}
|
// }
|
||||||
// console.log('render page content')
|
// console.log('render page content')
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={{ flex: 1, overflow: 'hidden' }} onLayout={handleLayout}>
|
<View style={{ flex: 1, overflow: 'hidden' }}>
|
||||||
<ImageBackground
|
<ImageBackground
|
||||||
style={{ position: 'absolute', left: 0, top: 0, height: wh.height, width: wh.width, backgroundColor: theme['c-content-background'] }}
|
style={{ position: 'absolute', left: 0, top: 0, height: windowSize.height, width: windowSize.width, backgroundColor: theme['c-content-background'] }}
|
||||||
source={theme['bg-image']}
|
source={theme['bg-image']}
|
||||||
resizeMode="cover"
|
resizeMode="cover"
|
||||||
>
|
>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { useMemo, useRef, useImperativeHandle, forwardRef, useState } from 'react'
|
import { useMemo, useRef, useImperativeHandle, forwardRef, useState } from 'react'
|
||||||
import { View, TouchableWithoutFeedback } from 'react-native'
|
import { View, TouchableWithoutFeedback } from 'react-native'
|
||||||
import { useDimensions } from '@/utils/hooks'
|
import { useWindowSize } from '@/utils/hooks'
|
||||||
|
|
||||||
import Modal, { type ModalType } from '@/components/common/Modal'
|
import Modal, { type ModalType } from '@/components/common/Modal'
|
||||||
import { createStyle } from '@/utils/tools'
|
import { createStyle } from '@/utils/tools'
|
||||||
@ -42,8 +42,8 @@ const Panel = ({
|
|||||||
onHide: () => void
|
onHide: () => void
|
||||||
children: React.ReactNode | React.ReactNode[]
|
children: React.ReactNode | React.ReactNode[]
|
||||||
}) => {
|
}) => {
|
||||||
// const dimensions = useDimensions()
|
// const dimensions = useWindowSize()
|
||||||
const { window: windowSize } = useDimensions()
|
const windowSize = useWindowSize()
|
||||||
// const theme = useGetter('common', 'theme')
|
// const theme = useGetter('common', 'theme')
|
||||||
// const fadeAnim = useRef(new Animated.Value(0)).current
|
// const fadeAnim = useRef(new Animated.Value(0)).current
|
||||||
// console.log(buttonPosition)
|
// console.log(buttonPosition)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { useImperativeHandle, forwardRef, useMemo, useRef, useState, type Ref } from 'react'
|
import { useImperativeHandle, forwardRef, useMemo, useRef, useState, type Ref } from 'react'
|
||||||
import { View, Animated, TouchableHighlight } from 'react-native'
|
import { View, Animated, TouchableHighlight } from 'react-native'
|
||||||
import { useDimensions } from '@/utils/hooks'
|
import { useWindowSize } from '@/utils/hooks'
|
||||||
|
|
||||||
import Modal, { type ModalType } from './Modal'
|
import Modal, { type ModalType } from './Modal'
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ const Menu = ({
|
|||||||
center = false,
|
center = false,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const theme = useTheme()
|
const theme = useTheme()
|
||||||
const { window: windowSize } = useDimensions()
|
const windowSize = useWindowSize()
|
||||||
// const fadeAnim = useRef(new Animated.Value(0)).current
|
// const fadeAnim = useRef(new Animated.Value(0)).current
|
||||||
// console.log(buttonPosition)
|
// console.log(buttonPosition)
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import { useImperativeHandle, forwardRef, useState, useMemo } from 'react'
|
import { useImperativeHandle, forwardRef, useState, useMemo } from 'react'
|
||||||
import { Modal, TouchableWithoutFeedback, View, type ModalProps as _ModalProps } from 'react-native'
|
import { Modal, TouchableWithoutFeedback, View, type ModalProps as _ModalProps } from 'react-native'
|
||||||
import StatusBar from './StatusBar'
|
import StatusBar from './StatusBar'
|
||||||
// import { useDimensions } from '@/utils/hooks'
|
// import { useWindowSize } from '@/utils/hooks'
|
||||||
|
|
||||||
// const styles = createStyle({
|
// const styles = createStyle({
|
||||||
// container: {
|
// container: {
|
||||||
@ -54,7 +54,7 @@ export default forwardRef<ModalType, ModalProps>(({
|
|||||||
...props
|
...props
|
||||||
}: ModalProps, ref) => {
|
}: ModalProps, ref) => {
|
||||||
const [visible, setVisible] = useState(false)
|
const [visible, setVisible] = useState(false)
|
||||||
// const { window: windowSize } = useDimensions()
|
// const { window: windowSize } = useWindowSize()
|
||||||
const handleRequestClose = () => {
|
const handleRequestClose = () => {
|
||||||
if (keyHide) {
|
if (keyHide) {
|
||||||
setVisible(false)
|
setVisible(false)
|
||||||
|
@ -51,7 +51,7 @@ const useI18n = () => {
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return useCallback((key: keyof Message, val?: TranslateValues): string => {
|
return useCallback((key: keyof Message, val?: TranslateValues): string => {
|
||||||
return i18n.getMessage(key, val)
|
return i18n?.getMessage(key, val) ?? ''
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [locale])
|
}, [locale])
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { View } from 'react-native'
|
import { View } from 'react-native'
|
||||||
import { useTheme } from '@/store/theme/hook'
|
import { useTheme } from '@/store/theme/hook'
|
||||||
import { createStyle } from '@/utils/tools'
|
import { createStyle } from '@/utils/tools'
|
||||||
// import { useDimensions } from '@/utils/hooks'
|
// import { useWindowSize } from '@/utils/hooks'
|
||||||
const HEADER_HEIGHT = 20
|
const HEADER_HEIGHT = 20
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
@ -4,6 +4,7 @@ import * as navigations from './navigation'
|
|||||||
|
|
||||||
import registerScreens from './registerScreens'
|
import registerScreens from './registerScreens'
|
||||||
import { removeComponentId } from '@/core/common'
|
import { removeComponentId } from '@/core/common'
|
||||||
|
import { onAppLaunched } from './regLaunchedEvent'
|
||||||
|
|
||||||
let unRegisterEvent: ReturnType<ReturnType<typeof Navigation.events>['registerScreenPoppedListener']>
|
let unRegisterEvent: ReturnType<ReturnType<typeof Navigation.events>['registerScreenPoppedListener']>
|
||||||
|
|
||||||
@ -23,7 +24,7 @@ const init = (callback: () => void | Promise<void>) => {
|
|||||||
unRegisterEvent = Navigation.events().registerScreenPoppedListener(({ componentId }) => {
|
unRegisterEvent = Navigation.events().registerScreenPoppedListener(({ componentId }) => {
|
||||||
removeComponentId(componentId)
|
removeComponentId(componentId)
|
||||||
})
|
})
|
||||||
Navigation.events().registerAppLaunchedListener(() => {
|
onAppLaunched(() => {
|
||||||
console.log('Register app launched listener')
|
console.log('Register app launched listener')
|
||||||
void callback()
|
void callback()
|
||||||
})
|
})
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Navigation } from 'react-native-navigation'
|
import { Navigation } from 'react-native-navigation'
|
||||||
import { Dimensions, InteractionManager } from 'react-native'
|
import { InteractionManager } from 'react-native'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
HOME_SCREEN,
|
HOME_SCREEN,
|
||||||
@ -12,6 +12,7 @@ import {
|
|||||||
import themeState from '@/store/theme/state'
|
import themeState from '@/store/theme/state'
|
||||||
import { NAV_SHEAR_NATIVE_IDS } from '@/config/constant'
|
import { NAV_SHEAR_NATIVE_IDS } from '@/config/constant'
|
||||||
import { getStatusBarStyle } from './utils'
|
import { getStatusBarStyle } from './utils'
|
||||||
|
import { windowSizeTools } from '@/utils/windowSizeTools'
|
||||||
|
|
||||||
// const store = getStore()
|
// const store = getStore()
|
||||||
// const getTheme = () => getter('common', 'theme')(store.getState())
|
// const getTheme = () => getter('common', 'theme')(store.getState())
|
||||||
@ -187,7 +188,7 @@ export function pushPlayDetailScreen(componentId: string) {
|
|||||||
],
|
],
|
||||||
// content: {
|
// content: {
|
||||||
// translationX: {
|
// translationX: {
|
||||||
// from: Dimensions.get('window').width,
|
// from: windowSizeTools.getSize().width,
|
||||||
// to: 0,
|
// to: 0,
|
||||||
// duration: 300,
|
// duration: 300,
|
||||||
// },
|
// },
|
||||||
@ -197,7 +198,7 @@ export function pushPlayDetailScreen(componentId: string) {
|
|||||||
content: {
|
content: {
|
||||||
translationX: {
|
translationX: {
|
||||||
from: 0,
|
from: 0,
|
||||||
to: Dimensions.get('window').width,
|
to: windowSizeTools.getSize().width,
|
||||||
duration: 300,
|
duration: 300,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -371,7 +372,7 @@ export function pushCommentScreen(componentId: string) {
|
|||||||
push: {
|
push: {
|
||||||
content: {
|
content: {
|
||||||
translationX: {
|
translationX: {
|
||||||
from: Dimensions.get('window').width,
|
from: windowSizeTools.getSize().width,
|
||||||
to: 0,
|
to: 0,
|
||||||
duration: 300,
|
duration: 300,
|
||||||
},
|
},
|
||||||
@ -381,7 +382,7 @@ export function pushCommentScreen(componentId: string) {
|
|||||||
content: {
|
content: {
|
||||||
translationX: {
|
translationX: {
|
||||||
from: 0,
|
from: 0,
|
||||||
to: Dimensions.get('window').width,
|
to: windowSizeTools.getSize().width,
|
||||||
duration: 300,
|
duration: 300,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -455,7 +456,7 @@ export function pushCommentScreen(componentId: string) {
|
|||||||
// push: {
|
// push: {
|
||||||
// content: {
|
// content: {
|
||||||
// translationX: {
|
// translationX: {
|
||||||
// from: Dimensions.get('window').width,
|
// from: windowSizeTools.getSize().width,
|
||||||
// to: 0,
|
// to: 0,
|
||||||
// duration: 300,
|
// duration: 300,
|
||||||
// },
|
// },
|
||||||
@ -465,7 +466,7 @@ export function pushCommentScreen(componentId: string) {
|
|||||||
// content: {
|
// content: {
|
||||||
// translationX: {
|
// translationX: {
|
||||||
// from: 0,
|
// from: 0,
|
||||||
// to: Dimensions.get('window').width,
|
// to: windowSizeTools.getSize().width,
|
||||||
// duration: 300,
|
// duration: 300,
|
||||||
// },
|
// },
|
||||||
// },
|
// },
|
||||||
|
24
src/navigation/regLaunchedEvent.ts
Normal file
24
src/navigation/regLaunchedEvent.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import { Navigation } from 'react-native-navigation'
|
||||||
|
|
||||||
|
let launched = false
|
||||||
|
const handlers: Array<() => void> = []
|
||||||
|
|
||||||
|
|
||||||
|
export const listenLaunchEvent = () => {
|
||||||
|
Navigation.events().registerAppLaunchedListener(() => {
|
||||||
|
// console.log('Register app launched listener', launched)
|
||||||
|
launched = true
|
||||||
|
setImmediate(() => {
|
||||||
|
for (const handler of handlers) handler()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export const onAppLaunched = (handler: () => void) => {
|
||||||
|
handlers.push(handler)
|
||||||
|
if (launched) {
|
||||||
|
setImmediate(() => {
|
||||||
|
handler()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,12 @@
|
|||||||
import { useDimensions } from '@/utils/hooks'
|
import { useWindowSize } from '@/utils/hooks'
|
||||||
import Vertical from './Vertical'
|
import Vertical from './Vertical'
|
||||||
import Horizontal from './Horizontal'
|
import Horizontal from './Horizontal'
|
||||||
// import { AppColors } from '@/theme'
|
// import { AppColors } from '@/theme'
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const { window } = useDimensions()
|
const windowSize = useWindowSize()
|
||||||
|
|
||||||
return window.height > window.width
|
return windowSize.height > windowSize.width
|
||||||
? <Vertical />
|
? <Vertical />
|
||||||
: <Horizontal />
|
: <Horizontal />
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { useDimensions } from '@/utils/hooks'
|
import { useWindowSize } from '@/utils/hooks'
|
||||||
import Vertical from './Vertical'
|
import Vertical from './Vertical'
|
||||||
import Horizontal from './Horizontal'
|
import Horizontal from './Horizontal'
|
||||||
// import { AppColors } from '@/theme'
|
// import { AppColors } from '@/theme'
|
||||||
@ -6,9 +6,9 @@ import Horizontal from './Horizontal'
|
|||||||
export type { SettingScreenIds } from './Main'
|
export type { SettingScreenIds } from './Main'
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const { window } = useDimensions()
|
const windowSize = useWindowSize()
|
||||||
|
|
||||||
return window.height > window.width
|
return windowSize.height > windowSize.width
|
||||||
? <Vertical />
|
? <Vertical />
|
||||||
: <Horizontal />
|
: <Horizontal />
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { useEffect } from 'react'
|
import { useEffect } from 'react'
|
||||||
import { useDimensions } from '@/utils/hooks'
|
import { useWindowSize } from '@/utils/hooks'
|
||||||
import PageContent from '@/components/PageContent'
|
import PageContent from '@/components/PageContent'
|
||||||
import { setComponentId } from '@/core/common'
|
import { setComponentId } from '@/core/common'
|
||||||
import { COMPONENT_IDS } from '@/config/constant'
|
import { COMPONENT_IDS } from '@/config/constant'
|
||||||
@ -12,7 +12,7 @@ interface Props {
|
|||||||
|
|
||||||
|
|
||||||
export default ({ componentId }: Props) => {
|
export default ({ componentId }: Props) => {
|
||||||
const { window } = useDimensions()
|
const windowSize = useWindowSize()
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setComponentId(COMPONENT_IDS.home, componentId)
|
setComponentId(COMPONENT_IDS.home, componentId)
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
@ -21,7 +21,7 @@ export default ({ componentId }: Props) => {
|
|||||||
return (
|
return (
|
||||||
<PageContent>
|
<PageContent>
|
||||||
{
|
{
|
||||||
window.height > window.width
|
windowSize.height > windowSize.width
|
||||||
? <Vertical />
|
? <Vertical />
|
||||||
: <Horizontal />
|
: <Horizontal />
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import { useTheme } from '@/store/theme/hook'
|
|||||||
import { BorderRadius } from '@/theme'
|
import { BorderRadius } from '@/theme'
|
||||||
import Text from '@/components/common/Text'
|
import Text from '@/components/common/Text'
|
||||||
import { usePlayerMusicInfo } from '@/store/player/hook'
|
import { usePlayerMusicInfo } from '@/store/player/hook'
|
||||||
import { useDimensions } from '@/utils/hooks'
|
import { useWindowSize } from '@/utils/hooks'
|
||||||
import { useNavigationComponentDidAppear } from '@/navigation'
|
import { useNavigationComponentDidAppear } from '@/navigation'
|
||||||
import { NAV_SHEAR_NATIVE_IDS } from '@/config/constant'
|
import { NAV_SHEAR_NATIVE_IDS } from '@/config/constant'
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ const EmptyPic = memo(({ width }: { width: number }) => {
|
|||||||
|
|
||||||
export default memo(({ componentId }: { componentId: string }) => {
|
export default memo(({ componentId }: { componentId: string }) => {
|
||||||
const musicInfo = usePlayerMusicInfo()
|
const musicInfo = usePlayerMusicInfo()
|
||||||
const { window: { width: winWidth, height: winHeight } } = useDimensions()
|
const { width: winWidth, height: winHeight } = useWindowSize()
|
||||||
|
|
||||||
const [animated, setAnimated] = useState(false)
|
const [animated, setAnimated] = useState(false)
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import { createStyle } from '@/utils/tools'
|
|||||||
import { usePlayerMusicInfo } from '@/store/player/hook'
|
import { usePlayerMusicInfo } from '@/store/player/hook'
|
||||||
import { useTheme } from '@/store/theme/hook'
|
import { useTheme } from '@/store/theme/hook'
|
||||||
import { BorderRadius } from '@/theme'
|
import { BorderRadius } from '@/theme'
|
||||||
import { useDimensions } from '@/utils/hooks'
|
import { useWindowSize } from '@/utils/hooks'
|
||||||
import Text from '@/components/common/Text'
|
import Text from '@/components/common/Text'
|
||||||
import { NAV_SHEAR_NATIVE_IDS } from '@/config/constant'
|
import { NAV_SHEAR_NATIVE_IDS } from '@/config/constant'
|
||||||
import { useNavigationComponentDidAppear } from '@/navigation'
|
import { useNavigationComponentDidAppear } from '@/navigation'
|
||||||
@ -23,7 +23,7 @@ const EmptyPic = memo(({ width }: { width: number }) => {
|
|||||||
|
|
||||||
export default ({ componentId }: { componentId: string }) => {
|
export default ({ componentId }: { componentId: string }) => {
|
||||||
const musicInfo = usePlayerMusicInfo()
|
const musicInfo = usePlayerMusicInfo()
|
||||||
const { window } = useDimensions()
|
const windowSize = useWindowSize()
|
||||||
|
|
||||||
const [animated, setAnimated] = useState(false)
|
const [animated, setAnimated] = useState(false)
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ export default ({ componentId }: { componentId: string }) => {
|
|||||||
})
|
})
|
||||||
// console.log('render pic')
|
// console.log('render pic')
|
||||||
|
|
||||||
const imgWidth = window.width * 0.8
|
const imgWidth = windowSize.width * 0.8
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { useEffect } from 'react'
|
import { useEffect } from 'react'
|
||||||
// import { View, StyleSheet } from 'react-native'
|
// import { View, StyleSheet } from 'react-native'
|
||||||
import { useDimensions } from '@/utils/hooks'
|
import { useWindowSize } from '@/utils/hooks'
|
||||||
|
|
||||||
import Vertical from './Vertical'
|
import Vertical from './Vertical'
|
||||||
import Horizontal from './Horizontal'
|
import Horizontal from './Horizontal'
|
||||||
@ -10,7 +10,7 @@ import { setComponentId } from '@/core/common'
|
|||||||
import { COMPONENT_IDS } from '@/config/constant'
|
import { COMPONENT_IDS } from '@/config/constant'
|
||||||
|
|
||||||
export default ({ componentId }: { componentId: string }) => {
|
export default ({ componentId }: { componentId: string }) => {
|
||||||
const { window } = useDimensions()
|
const windowSize = useWindowSize()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setComponentId(COMPONENT_IDS.playDetail, componentId)
|
setComponentId(COMPONENT_IDS.playDetail, componentId)
|
||||||
@ -21,7 +21,7 @@ export default ({ componentId }: { componentId: string }) => {
|
|||||||
<PageContent>
|
<PageContent>
|
||||||
<StatusBar />
|
<StatusBar />
|
||||||
{
|
{
|
||||||
window.height > window.width
|
windowSize.height > windowSize.width
|
||||||
? <Vertical componentId={componentId} />
|
? <Vertical componentId={componentId} />
|
||||||
: <Horizontal componentId={componentId} />
|
: <Horizontal componentId={componentId} />
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
export { default as useLayout } from './useLayout'
|
export { default as useLayout } from './useLayout'
|
||||||
export { default as useKeyboard } from './useKeyboard'
|
export { default as useKeyboard } from './useKeyboard'
|
||||||
export { default as useDimensions } from './useDimensions'
|
export { default as useWindowSize } from './useWindowSize'
|
||||||
export { default as useDeviceOrientation } from './useDeviceOrientation'
|
export { default as useDeviceOrientation } from './useDeviceOrientation'
|
||||||
|
|
||||||
export { default as usePlayTime } from './usePlayTime'
|
export { default as usePlayTime } from './usePlayTime'
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { useEffect, useState, useCallback } from 'react'
|
import { useEffect, useState, useCallback } from 'react'
|
||||||
import { Dimensions } from 'react-native'
|
import { windowSizeTools } from '../windowSizeTools'
|
||||||
|
|
||||||
const screen = Dimensions.get('screen')
|
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const isOrientationPortrait = ({
|
const isOrientationPortrait = ({
|
||||||
@ -13,20 +12,21 @@ export default () => {
|
|||||||
height,
|
height,
|
||||||
}) => width >= height
|
}) => width >= height
|
||||||
|
|
||||||
|
const size = windowSizeTools.getSize()
|
||||||
const [orientation, setOrientation] = useState({
|
const [orientation, setOrientation] = useState({
|
||||||
portrait: isOrientationPortrait(screen),
|
portrait: isOrientationPortrait(size),
|
||||||
landscape: isOrientationLandscape(screen),
|
landscape: isOrientationLandscape(size),
|
||||||
})
|
})
|
||||||
|
|
||||||
const onChange = useCallback(({ screen: scr }) => {
|
const onChange = useCallback((size) => {
|
||||||
setOrientation({
|
setOrientation({
|
||||||
portrait: isOrientationPortrait(scr),
|
portrait: isOrientationPortrait(size),
|
||||||
landscape: isOrientationLandscape(scr),
|
landscape: isOrientationLandscape(size),
|
||||||
})
|
})
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const changeEvent = Dimensions.addEventListener('change', onChange)
|
const changeEvent = windowSizeTools.onSizeChanged(onChange)
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
changeEvent.remove()
|
changeEvent.remove()
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
import { useEffect, useState } from 'react'
|
|
||||||
import { Dimensions } from 'react-native'
|
|
||||||
import { getWindowSise } from '@/utils/tools'
|
|
||||||
|
|
||||||
export default () => {
|
|
||||||
const [dimensions, setDimensions] = useState({
|
|
||||||
window: getWindowSise(),
|
|
||||||
screen: Dimensions.get('screen'),
|
|
||||||
})
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const onChange = ({ window, screen }) => {
|
|
||||||
setDimensions({ window: getWindowSise(window), screen })
|
|
||||||
}
|
|
||||||
|
|
||||||
const changeEvent = Dimensions.addEventListener('change', onChange)
|
|
||||||
return () => changeEvent.remove()
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
return dimensions
|
|
||||||
}
|
|
19
src/utils/hooks/useWindowSize.ts
Normal file
19
src/utils/hooks/useWindowSize.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { useEffect, useState } from 'react'
|
||||||
|
import { type SizeHandler, windowSizeTools } from '@/utils/windowSizeTools'
|
||||||
|
|
||||||
|
export default () => {
|
||||||
|
const [size, setSize] = useState(windowSizeTools.getSize())
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const onChange: SizeHandler = (size) => {
|
||||||
|
setSize(size)
|
||||||
|
}
|
||||||
|
|
||||||
|
const remove = windowSizeTools.onSizeChanged(onChange)
|
||||||
|
return () => {
|
||||||
|
remove()
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return size
|
||||||
|
}
|
@ -55,3 +55,19 @@ export const onScreenStateChange = (callback: (state: 'ON' | 'OFF') => void): ()
|
|||||||
eventListener.remove()
|
eventListener.remove()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getWindowSize = async(): Promise<{ width: number, height: number }> => {
|
||||||
|
return UtilsModule.getWindowSize()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const onWindowSizeChange = (callback: (size: { width: number, height: number }) => void): () => void => {
|
||||||
|
UtilsModule.listenWindowSizeChanged()
|
||||||
|
const eventEmitter = new NativeEventEmitter(UtilsModule)
|
||||||
|
const eventListener = eventEmitter.addListener('screen-size-changed', event => {
|
||||||
|
callback(event)
|
||||||
|
})
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
eventListener.remove()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -5,15 +5,18 @@
|
|||||||
* width:375
|
* width:375
|
||||||
* height:667
|
* height:667
|
||||||
*/
|
*/
|
||||||
import { Dimensions, PixelRatio } from 'react-native'
|
import { PixelRatio } from 'react-native'
|
||||||
|
import { windowSizeTools } from './windowSizeTools'
|
||||||
|
|
||||||
// 高保真的宽度和高度
|
// 高保真的宽度和高度
|
||||||
const designWidth = 375.0
|
const designWidth = 375.0
|
||||||
const designHeight = 667.0
|
const designHeight = 667.0
|
||||||
|
|
||||||
// 获取屏幕的dp
|
// 获取屏幕的dp
|
||||||
let screenW = Dimensions.get('window').width
|
const size = windowSizeTools.getSize()
|
||||||
let screenH = Dimensions.get('window').height
|
// console.log('size', size)
|
||||||
|
let screenW = size.width
|
||||||
|
let screenH = size.height
|
||||||
if (screenW > screenH) {
|
if (screenW > screenH) {
|
||||||
const temp = screenW
|
const temp = screenW
|
||||||
screenW = screenH
|
screenW = screenH
|
||||||
|
@ -29,29 +29,29 @@ export const osVer = Platform.constants.Release as string
|
|||||||
|
|
||||||
export const isActive = () => AppState.currentState == 'active'
|
export const isActive = () => AppState.currentState == 'active'
|
||||||
|
|
||||||
|
|
||||||
// fix https://github.com/facebook/react-native/issues/4934
|
// fix https://github.com/facebook/react-native/issues/4934
|
||||||
export const getWindowSise = (windowDimensions?: ReturnType<(typeof Dimensions)['get']>) => {
|
// export const getWindowSise = (windowDimensions?: ReturnType<(typeof Dimensions)['get']>) => {
|
||||||
windowDimensions ??= Dimensions.get('window')
|
// return windowSizeTools.getSize()
|
||||||
// if (Platform.OS === 'ios') return windowDimensions
|
// // windowDimensions ??= Dimensions.get('window')
|
||||||
return windowDimensions
|
// // if (Platform.OS === 'ios') return windowDimensions
|
||||||
// const windowSize = {
|
// // return windowDimensions
|
||||||
// width: ExtraDimensions.getRealWindowWidth(),
|
// // const windowSize = {
|
||||||
// height: ExtraDimensions.getRealWindowHeight(),
|
// // width: ExtraDimensions.getRealWindowWidth(),
|
||||||
// }
|
// // height: ExtraDimensions.getRealWindowHeight(),
|
||||||
// if (
|
// // }
|
||||||
// (windowDimensions.height > windowDimensions.width && windowSize.height < windowSize.width) ||
|
// // if (
|
||||||
// (windowDimensions.width > windowDimensions.height && windowSize.width < windowSize.height)
|
// // (windowDimensions.height > windowDimensions.width && windowSize.height < windowSize.width) ||
|
||||||
// ) {
|
// // (windowDimensions.width > windowDimensions.height && windowSize.width < windowSize.height)
|
||||||
// windowSize.height = windowSize.width
|
// // ) {
|
||||||
// }
|
// // windowSize.height = windowSize.width
|
||||||
// windowSize.width = windowDimensions.width
|
// // }
|
||||||
|
// // windowSize.width = windowDimensions.width
|
||||||
|
|
||||||
// if (ExtraDimensions.isSoftMenuBarEnabled()) {
|
// // if (ExtraDimensions.isSoftMenuBarEnabled()) {
|
||||||
// windowSize.height -= ExtraDimensions.getSoftMenuBarHeight()
|
// // windowSize.height -= ExtraDimensions.getSoftMenuBarHeight()
|
||||||
// }
|
// // }
|
||||||
// return windowSize
|
// // return windowSize
|
||||||
}
|
// }
|
||||||
|
|
||||||
export const checkStoragePermissions = async() => PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE)
|
export const checkStoragePermissions = async() => PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE)
|
||||||
|
|
||||||
|
48
src/utils/windowSizeTools.ts
Normal file
48
src/utils/windowSizeTools.ts
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import { Dimensions } from 'react-native'
|
||||||
|
import { getWindowSize } from './nativeModules/utils'
|
||||||
|
|
||||||
|
export type SizeHandler = (size: { width: number, height: number }) => void
|
||||||
|
export const windowSizeTools = {
|
||||||
|
size: {
|
||||||
|
width: 0,
|
||||||
|
height: 0,
|
||||||
|
},
|
||||||
|
listeners: [] as SizeHandler[],
|
||||||
|
getSize() {
|
||||||
|
return this.size
|
||||||
|
},
|
||||||
|
onSizeChanged(handler: SizeHandler) {
|
||||||
|
this.listeners.push(handler)
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
this.listeners.splice(this.listeners.indexOf(handler), 1)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async init() {
|
||||||
|
Dimensions.addEventListener('change', () => {
|
||||||
|
void getWindowSize().then((size) => {
|
||||||
|
if (!size.width) return
|
||||||
|
const scale = Dimensions.get('screen').scale
|
||||||
|
size.width = Math.trunc(size.width / scale)
|
||||||
|
size.height = Math.trunc(size.height / scale)
|
||||||
|
this.size = size
|
||||||
|
for (const handler of this.listeners) handler(size)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
const size = await getWindowSize()
|
||||||
|
if (size.width) {
|
||||||
|
const scale = Dimensions.get('screen').scale
|
||||||
|
size.width = Math.trunc(size.width / scale)
|
||||||
|
size.height = Math.trunc(size.height / scale)
|
||||||
|
this.size = size
|
||||||
|
} else {
|
||||||
|
const window = Dimensions.get('window')
|
||||||
|
this.size = {
|
||||||
|
width: window.width,
|
||||||
|
height: window.height,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log('init windowSizeTools')
|
||||||
|
return size
|
||||||
|
},
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user