1import React from 'react'; 2import {StyleSheet, View} from 'react-native'; 3import rpx from '@/utils/rpx'; 4import {TouchableOpacity} from 'react-native-gesture-handler'; 5import ThemeText from '@/components/base/themeText'; 6import Divider from '@/components/base/divider'; 7 8interface IPanelHeaderProps { 9 title: string; 10 cancelText?: string; 11 okText?: string; 12 onCancel?: () => void; 13 onOk?: () => void; 14 hideButtons?: boolean; 15 hideDivider?: boolean; 16} 17export default function PanelHeader(props: IPanelHeaderProps) { 18 const { 19 title, 20 cancelText, 21 okText, 22 onOk, 23 onCancel, 24 hideButtons, 25 hideDivider, 26 } = props; 27 28 return ( 29 <> 30 <View style={styles.header}> 31 {hideButtons ? null : ( 32 <TouchableOpacity style={styles.button} onPress={onCancel}> 33 <ThemeText fontWeight="medium"> 34 {cancelText || '取消'} 35 </ThemeText> 36 </TouchableOpacity> 37 )} 38 <ThemeText 39 style={styles.title} 40 fontWeight="bold" 41 fontSize="title" 42 numberOfLines={1}> 43 {title} 44 </ThemeText> 45 {hideButtons ? null : ( 46 <TouchableOpacity 47 style={[styles.button, styles.rightButton]} 48 onPress={onOk}> 49 <ThemeText fontWeight="medium" fontColor="primary"> 50 {okText || '确认'} 51 </ThemeText> 52 </TouchableOpacity> 53 )} 54 </View> 55 {hideDivider ? null : <Divider />} 56 </> 57 ); 58} 59 60const styles = StyleSheet.create({ 61 header: { 62 width: '100%', 63 flexDirection: 'row', 64 alignItems: 'center', 65 paddingHorizontal: rpx(24), 66 height: rpx(100), 67 }, 68 button: { 69 width: rpx(120), 70 height: '100%', 71 justifyContent: 'center', 72 }, 73 rightButton: { 74 alignItems: 'flex-end', 75 }, 76 title: { 77 flex: 1, 78 textAlign: 'center', 79 }, 80}); 81