xref: /MusicFree/src/components/base/button.tsx (revision 756bc302d40f6f21e72cdfca8580b52a8341d658)
1*756bc302S猫头猫import {
2*756bc302S猫头猫    GestureResponderEvent,
3*756bc302S猫头猫    StyleProp,
4*756bc302S猫头猫    StyleSheet,
5*756bc302S猫头猫    TouchableOpacity,
6*756bc302S猫头猫    ViewStyle,
7*756bc302S猫头猫} from 'react-native';
8*756bc302S猫头猫import useColors from '@/hooks/useColors.ts';
9*756bc302S猫头猫import ThemeText from '@/components/base/themeText.tsx';
1019dc08ecS猫头猫import React from 'react';
11*756bc302S猫头猫import rpx from '@/utils/rpx.ts';
1219dc08ecS猫头猫
13*756bc302S猫头猫export function Button(props: {
14*756bc302S猫头猫    type?: 'normal' | 'primary';
15*756bc302S猫头猫    text: string;
16*756bc302S猫头猫    style?: StyleProp<ViewStyle>;
17*756bc302S猫头猫    onPress?: (evt: GestureResponderEvent) => void;
18*756bc302S猫头猫}) {
19*756bc302S猫头猫    const {type = 'normal', text, style, onPress} = props;
20*756bc302S猫头猫    const colors = useColors();
21*756bc302S猫头猫
2219dc08ecS猫头猫    return (
23*756bc302S猫头猫        <TouchableOpacity
24*756bc302S猫头猫            activeOpacity={0.6}
253b870a26S猫头猫            onPress={onPress}
26*756bc302S猫头猫            style={[
27*756bc302S猫头猫                styles.bottomBtn,
28*756bc302S猫头猫                {
29*756bc302S猫头猫                    backgroundColor:
30*756bc302S猫头猫                        type === 'normal' ? colors.placeholder : colors.primary,
31*756bc302S猫头猫                },
32*756bc302S猫头猫                style,
33*756bc302S猫头猫            ]}>
34*756bc302S猫头猫            <ThemeText color={type === 'normal' ? undefined : 'white'}>
35*756bc302S猫头猫                {text}
36*756bc302S猫头猫            </ThemeText>
37*756bc302S猫头猫        </TouchableOpacity>
3819dc08ecS猫头猫    );
3919dc08ecS猫头猫}
40*756bc302S猫头猫
41*756bc302S猫头猫const styles = StyleSheet.create({
42*756bc302S猫头猫    bottomBtn: {
43*756bc302S猫头猫        borderRadius: rpx(8),
44*756bc302S猫头猫        flexShrink: 0,
45*756bc302S猫头猫        justifyContent: 'center',
46*756bc302S猫头猫        alignItems: 'center',
47*756bc302S猫头猫        height: rpx(72),
48*756bc302S猫头猫    },
49*756bc302S猫头猫});
50