71 lines
1.5 KiB
TypeScript

import React from 'react';
import { StyleSheet, Pressable, PressableProps } from 'react-native';
import { ThemedView } from '@/components/theme';
import { Colors } from '@/constants/Colors';
import { useColorScheme } from '@/hooks/useColorScheme';
const DEFAULT_WIDTH = 320;
const DEFAULT_HEIGHT = 68;
type ThemedButtonProps = PressableProps & {
width?: number;
height?: number;
containerStyle?: object;
buttonStyle?: object;
};
const ThemedButton: React.FC<ThemedButtonProps> = ({
width,
height,
children,
containerStyle,
buttonStyle,
style,
...restProps // This now includes onPress automatically
}) => {
const scheme = useColorScheme() ?? 'dark';
return (
<ThemedView
style={[
styles.buttonContainer,
{
width: width ?? DEFAULT_WIDTH,
height: height ?? DEFAULT_HEIGHT,
},
containerStyle,
]}
>
<Pressable
style={[
styles.button,
{ backgroundColor: Colors[scheme].text },
buttonStyle,
style,
]}
{...restProps} // This passes onPress and all other Pressable props
>
{children}
</Pressable>
</ThemedView>
);
};
export default ThemedButton;
const styles = StyleSheet.create({
buttonContainer: {
alignItems: 'center',
justifyContent: 'center',
padding: 3,
},
button: {
borderRadius: 10,
width: '100%',
height: '100%',
alignItems: 'center',
justifyContent: 'center',
flexDirection: 'row',
},
});