mirror of
https://github.com/ikun0014/lx-music-mobile.git
synced 2025-07-05 21:58:56 +08:00
修改竖屏设置菜单UI布局
This commit is contained in:
parent
b9677bb7db
commit
46d982ee4e
@ -7,7 +7,7 @@ import { useTheme } from '@/store/theme/hook'
|
|||||||
import { createStyle } from '@/utils/tools'
|
import { createStyle } from '@/utils/tools'
|
||||||
import Text from '@/components/common/Text'
|
import Text from '@/components/common/Text'
|
||||||
import { scaleSizeH } from '@/utils/pixelRatio'
|
import { scaleSizeH } from '@/utils/pixelRatio'
|
||||||
import { SETTING_SCREENS, type SettingScreenIds } from './Main'
|
import { SETTING_SCREENS, type SettingScreenIds } from '../Main'
|
||||||
import { useI18n } from '@/lang'
|
import { useI18n } from '@/lang'
|
||||||
|
|
||||||
type FlatListType = FlatListProps<SettingScreenIds>
|
type FlatListType = FlatListProps<SettingScreenIds>
|
@ -1,7 +1,7 @@
|
|||||||
import React, { useRef } from 'react'
|
import React, { useRef } from 'react'
|
||||||
import { ScrollView, View } from 'react-native'
|
import { ScrollView, View } from 'react-native'
|
||||||
import NavList from './NavList'
|
import NavList from './NavList'
|
||||||
import Main, { type MainType } from './Main'
|
import Main, { type MainType } from '../Main'
|
||||||
import { createStyle } from '@/utils/tools'
|
import { createStyle } from '@/utils/tools'
|
||||||
import { BorderWidths } from '@/theme'
|
import { BorderWidths } from '@/theme'
|
||||||
import { useTheme } from '@/store/theme/hook'
|
import { useTheme } from '@/store/theme/hook'
|
@ -1,35 +1,98 @@
|
|||||||
import React, { forwardRef, useImperativeHandle, useState } from 'react'
|
import React, { memo, useCallback, useState } from 'react'
|
||||||
import type { SettingScreenIds } from '../Main'
|
import { View, TouchableOpacity, ScrollView } from 'react-native'
|
||||||
|
|
||||||
import NavList from '../NavList'
|
import { useTheme } from '@/store/theme/hook'
|
||||||
|
import { createStyle } from '@/utils/tools'
|
||||||
export interface NavListTypeProps {
|
import Text from '@/components/common/Text'
|
||||||
onChangeId: (id: SettingScreenIds) => void
|
import { SETTING_SCREENS, type SettingScreenIds } from '../Main'
|
||||||
}
|
import { useI18n } from '@/lang'
|
||||||
export interface NavListTypeType {
|
import { BorderRadius, BorderWidths } from '@/theme'
|
||||||
show: () => void
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export default forwardRef<NavListTypeType, NavListTypeProps>(({ onChangeId }, ref) => {
|
const ListItem = memo(({ id, activeId, onPress }: {
|
||||||
const [visible, setVisible] = useState(false)
|
onPress: (item: SettingScreenIds) => void
|
||||||
|
activeId: string
|
||||||
|
id: SettingScreenIds
|
||||||
|
}) => {
|
||||||
|
const theme = useTheme()
|
||||||
|
const t = useI18n()
|
||||||
|
|
||||||
useImperativeHandle(ref, () => {
|
const active = activeId == id
|
||||||
let isInited = false
|
|
||||||
return {
|
const handlePress = () => {
|
||||||
show() {
|
onPress(id)
|
||||||
if (isInited) return
|
}
|
||||||
requestAnimationFrame(() => {
|
|
||||||
setVisible(true)
|
|
||||||
})
|
|
||||||
isInited = true
|
|
||||||
},
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
visible
|
<View style={{ ...styles.listItem, backgroundColor: active ? theme['c-primary-background-active'] : 'transparent' }}>
|
||||||
? <NavList onChangeId={onChangeId} />
|
<TouchableOpacity style={styles.listName} onPress={handlePress}>
|
||||||
: null
|
<Text numberOfLines={1} size={16} color={active ? theme['c-primary-font'] : theme['c-font']}>{t(`setting_${id}`)}</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}, (prevProps, nextProps) => {
|
||||||
|
return !!(prevProps.id === nextProps.id &&
|
||||||
|
prevProps.activeId != nextProps.id &&
|
||||||
|
nextProps.activeId != nextProps.id
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
export default ({ onChangeId }: {
|
||||||
|
onChangeId: (id: SettingScreenIds) => void
|
||||||
|
}) => {
|
||||||
|
const [activeId, setActiveId] = useState(global.lx.settingActiveId)
|
||||||
|
const theme = useTheme()
|
||||||
|
|
||||||
|
const handleChangeId = useCallback((id: SettingScreenIds) => {
|
||||||
|
onChangeId(id)
|
||||||
|
setActiveId(id)
|
||||||
|
global.lx.settingActiveId = id
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ScrollView style={{ ...styles.container, borderBottomColor: theme['c-border-background'] }} contentContainerStyle={styles.contentContainer} keyboardShouldPersistTaps={'always'}>
|
||||||
|
{
|
||||||
|
SETTING_SCREENS.map(id => <ListItem id={id} activeId={activeId} onPress={handleChangeId} />)
|
||||||
|
}
|
||||||
|
</ScrollView>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const styles = createStyle({
|
||||||
|
container: {
|
||||||
|
height: '20%',
|
||||||
|
flexGrow: 0,
|
||||||
|
flexShrink: 0,
|
||||||
|
borderBottomWidth: BorderWidths.normal,
|
||||||
|
},
|
||||||
|
contentContainer: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
flexWrap: 'wrap',
|
||||||
|
paddingHorizontal: 5,
|
||||||
|
// backgroundColor: 'rgba(0, 0, 0, 0.1)',
|
||||||
|
},
|
||||||
|
// listContainer: {
|
||||||
|
// // borderBottomWidth: BorderWidths.normal2,
|
||||||
|
// },
|
||||||
|
|
||||||
|
listItem: {
|
||||||
|
width: '33.33%',
|
||||||
|
height: 'auto',
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
paddingHorizontal: 5,
|
||||||
|
paddingVertical: 8,
|
||||||
|
borderRadius: BorderRadius.normal,
|
||||||
|
marginBottom: 5,
|
||||||
|
},
|
||||||
|
listName: {
|
||||||
|
// justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
flexGrow: 1,
|
||||||
|
flexShrink: 1,
|
||||||
|
// paddingLeft: 5,
|
||||||
|
// backgroundColor: 'rgba(0,0,0,0.1)',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
@ -1,70 +1,37 @@
|
|||||||
import React, { useCallback, useRef } from 'react'
|
import React, { useCallback, useRef } from 'react'
|
||||||
import { ScrollView, View, type DrawerLayoutAndroid } from 'react-native'
|
import { ScrollView, View, type DrawerLayoutAndroid } from 'react-native'
|
||||||
// import { getWindowSise, onDimensionChange } from '@/utils/tools'
|
// import { getWindowSise, onDimensionChange } from '@/utils/tools'
|
||||||
import NavList, { type NavListTypeType } from './NavList'
|
import NavList from './NavList'
|
||||||
import Header, { type HeaderType } from './Header'
|
|
||||||
import Main, { type SettingScreenIds, type MainType } from '../Main'
|
import Main, { type SettingScreenIds, type MainType } from '../Main'
|
||||||
import { useSettingValue } from '@/store/setting/hook'
|
|
||||||
import { COMPONENT_IDS } from '@/config/constant'
|
|
||||||
import DrawerLayoutFixed from '@/components/common/DrawerLayoutFixed'
|
|
||||||
import { scaleSizeW } from '@/utils/pixelRatio'
|
|
||||||
import { createStyle } from '@/utils/tools'
|
import { createStyle } from '@/utils/tools'
|
||||||
import { useTheme } from '@/store/theme/hook'
|
|
||||||
|
|
||||||
const MAX_WIDTH = scaleSizeW(300)
|
|
||||||
|
|
||||||
const Content = () => {
|
const Content = () => {
|
||||||
const drawer = useRef<DrawerLayoutAndroid>(null)
|
const drawer = useRef<DrawerLayoutAndroid>(null)
|
||||||
const navListRef = useRef<NavListTypeType>(null)
|
|
||||||
const headerRef = useRef<HeaderType>(null)
|
|
||||||
const mainRef = useRef<MainType>(null)
|
const mainRef = useRef<MainType>(null)
|
||||||
const drawerLayoutPosition = useSettingValue('common.drawerLayoutPosition')
|
|
||||||
const theme = useTheme()
|
|
||||||
|
|
||||||
const handleShowDrawer = useCallback(() => {
|
|
||||||
drawer.current?.openDrawer()
|
|
||||||
navListRef.current?.show()
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
const handleChangeId = useCallback((id: SettingScreenIds) => {
|
const handleChangeId = useCallback((id: SettingScreenIds) => {
|
||||||
drawer.current?.closeDrawer()
|
drawer.current?.closeDrawer()
|
||||||
mainRef.current?.setActiveId(id)
|
mainRef.current?.setActiveId(id)
|
||||||
headerRef.current?.setActiveId(id)
|
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const navigationView = () => (
|
|
||||||
<View style={styles.nav}>
|
|
||||||
<NavList ref={navListRef} onChangeId={handleChangeId} />
|
|
||||||
</View>
|
|
||||||
)
|
|
||||||
// console.log('render drawer content')
|
// console.log('render drawer content')
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DrawerLayoutFixed
|
<View style={styles.container}>
|
||||||
ref={drawer}
|
<NavList onChangeId={handleChangeId} />
|
||||||
widthPercentage={0.6}
|
|
||||||
widthPercentageMax={MAX_WIDTH}
|
|
||||||
visibleNavNames={[COMPONENT_IDS.home]}
|
|
||||||
// drawerWidth={width}
|
|
||||||
drawerPosition={drawerLayoutPosition}
|
|
||||||
renderNavigationView={navigationView}
|
|
||||||
drawerBackgroundColor={theme['c-content-background']}
|
|
||||||
style={{ elevation: 1 }}
|
|
||||||
>
|
|
||||||
<Header ref={headerRef} onShowNavBar={handleShowDrawer} />
|
|
||||||
<ScrollView contentContainerStyle={styles.main} keyboardShouldPersistTaps={'always'}>
|
<ScrollView contentContainerStyle={styles.main} keyboardShouldPersistTaps={'always'}>
|
||||||
<Main ref={mainRef} />
|
<Main ref={mainRef} />
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
{/* <View style={styles.container}>
|
</View>
|
||||||
</View> */}
|
|
||||||
</DrawerLayoutFixed>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const styles = createStyle({
|
const styles = createStyle({
|
||||||
nav: {
|
container: {
|
||||||
paddingTop: 10,
|
flex: 1,
|
||||||
paddingBottom: 10,
|
flexDirection: 'column',
|
||||||
},
|
},
|
||||||
main: {
|
main: {
|
||||||
paddingLeft: 15,
|
paddingLeft: 15,
|
||||||
|
@ -385,6 +385,7 @@ export const trasformeStyle = <T extends Style>(styles: T): T => {
|
|||||||
case 'marginBottom':
|
case 'marginBottom':
|
||||||
case 'paddingTop':
|
case 'paddingTop':
|
||||||
case 'paddingBottom':
|
case 'paddingBottom':
|
||||||
|
case 'paddingVertical':
|
||||||
newStyle[p] = scaleSizeH(v)
|
newStyle[p] = scaleSizeH(v)
|
||||||
break
|
break
|
||||||
case 'width':
|
case 'width':
|
||||||
@ -393,6 +394,7 @@ export const trasformeStyle = <T extends Style>(styles: T): T => {
|
|||||||
case 'marginRight':
|
case 'marginRight':
|
||||||
case 'paddingLeft':
|
case 'paddingLeft':
|
||||||
case 'paddingRight':
|
case 'paddingRight':
|
||||||
|
case 'paddingHorizontal':
|
||||||
newStyle[p] = scaleSizeW(v)
|
newStyle[p] = scaleSizeW(v)
|
||||||
break
|
break
|
||||||
case 'padding':
|
case 'padding':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user