2026-03-24 14:21:31 +08:00
|
|
|
import React from 'react';
|
|
|
|
|
import { TouchableOpacity, StyleProp, ViewStyle, StyleSheet } from 'react-native';
|
|
|
|
|
import { MaterialCommunityIcons } from '@expo/vector-icons';
|
|
|
|
|
|
2026-04-25 00:39:40 +08:00
|
|
|
import { useAppColors } from '../../theme';
|
2026-03-24 14:21:31 +08:00
|
|
|
|
2026-04-25 00:39:40 +08:00
|
|
|
type AppBackButtonIcon = 'chevron-left' | 'arrow-left' | 'close';
|
2026-03-24 14:21:31 +08:00
|
|
|
|
|
|
|
|
interface AppBackButtonProps {
|
|
|
|
|
onPress: () => void;
|
|
|
|
|
icon?: AppBackButtonIcon;
|
|
|
|
|
style?: StyleProp<ViewStyle>;
|
|
|
|
|
iconColor?: string;
|
|
|
|
|
hitSlop?: number;
|
|
|
|
|
testID?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const AppBackButton: React.FC<AppBackButtonProps> = ({
|
|
|
|
|
onPress,
|
2026-04-25 00:39:40 +08:00
|
|
|
icon = 'chevron-left',
|
2026-03-24 14:21:31 +08:00
|
|
|
style,
|
2026-03-25 05:16:54 +08:00
|
|
|
iconColor: iconColorProp,
|
2026-03-24 14:21:31 +08:00
|
|
|
hitSlop = 8,
|
|
|
|
|
testID,
|
|
|
|
|
}) => {
|
2026-03-25 05:16:54 +08:00
|
|
|
const colors = useAppColors();
|
|
|
|
|
const iconColor = iconColorProp ?? colors.text.primary;
|
|
|
|
|
|
2026-03-24 14:21:31 +08:00
|
|
|
return (
|
|
|
|
|
<TouchableOpacity
|
|
|
|
|
onPress={onPress}
|
2026-04-25 00:39:40 +08:00
|
|
|
style={[styles.button, style]}
|
|
|
|
|
activeOpacity={0.6}
|
2026-03-24 14:21:31 +08:00
|
|
|
hitSlop={hitSlop}
|
|
|
|
|
testID={testID}
|
|
|
|
|
accessibilityRole="button"
|
|
|
|
|
accessibilityLabel={icon === 'close' ? '关闭' : '返回'}
|
|
|
|
|
>
|
2026-04-25 00:39:40 +08:00
|
|
|
<MaterialCommunityIcons name={icon} size={36} color={iconColor} />
|
2026-03-24 14:21:31 +08:00
|
|
|
</TouchableOpacity>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
|
button: {
|
2026-04-25 00:39:40 +08:00
|
|
|
width: 40,
|
|
|
|
|
height: 40,
|
2026-03-24 14:21:31 +08:00
|
|
|
alignItems: 'center',
|
|
|
|
|
justifyContent: 'center',
|
2026-04-25 00:39:40 +08:00
|
|
|
marginLeft: -12,
|
|
|
|
|
marginRight: 0,
|
|
|
|
|
padding: 0,
|
2026-05-03 22:01:43 +08:00
|
|
|
backgroundColor: 'transparent',
|
2026-03-24 14:21:31 +08:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default AppBackButton;
|