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