2020-09-07 13:12:41 +05:00
|
|
|
import React from 'react';
|
2020-09-09 11:10:35 +05:00
|
|
|
import {ActivityIndicator, StyleSheet, Text} from 'react-native';
|
|
|
|
|
import {ph, pv, SIZE, WEIGHT} from '../../common/common';
|
2020-09-07 13:12:41 +05:00
|
|
|
import {useTracked} from '../../provider';
|
2020-09-09 11:10:35 +05:00
|
|
|
import {PressableButton} from '../PressableButton';
|
|
|
|
|
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
|
2020-09-07 13:12:41 +05:00
|
|
|
|
|
|
|
|
export const Button = ({
|
2020-09-09 11:10:35 +05:00
|
|
|
height = 40,
|
2020-09-07 13:12:41 +05:00
|
|
|
width = '48%',
|
|
|
|
|
onPress = () => {},
|
|
|
|
|
loading = false,
|
|
|
|
|
grayed,
|
2020-09-09 11:10:35 +05:00
|
|
|
title = '',
|
|
|
|
|
icon,
|
|
|
|
|
color = 'accent',
|
2020-09-07 13:12:41 +05:00
|
|
|
}) => {
|
|
|
|
|
const [state, dispatch] = useTracked();
|
|
|
|
|
const {colors, tags, premiumUser} = state;
|
2020-09-09 11:10:35 +05:00
|
|
|
const usedColor = 'accent' ? colors.accent : color;
|
2020-09-07 13:12:41 +05:00
|
|
|
|
|
|
|
|
return (
|
2020-09-09 11:10:35 +05:00
|
|
|
<PressableButton
|
2020-09-07 13:12:41 +05:00
|
|
|
onPress={onPress}
|
2020-09-09 11:10:35 +05:00
|
|
|
color={grayed ? colors.nav : usedColor}
|
|
|
|
|
selectedColor={grayed ? colors.nav : usedColor}
|
|
|
|
|
alpha={grayed ? (!colors.night ? -0.04 : 0.04) : -0.1}
|
|
|
|
|
customStyle={{
|
|
|
|
|
height: height,
|
|
|
|
|
width: width? width : null,
|
|
|
|
|
paddingVertical: pv,
|
|
|
|
|
paddingHorizontal: ph,
|
|
|
|
|
borderRadius: 5,
|
|
|
|
|
alignSelf: 'center',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
}}>
|
|
|
|
|
{loading ? <ActivityIndicator color={usedColor} /> : null}
|
|
|
|
|
{icon && !loading ? (
|
|
|
|
|
<Icon
|
|
|
|
|
name={icon}
|
|
|
|
|
style={{
|
|
|
|
|
marginRight: 5,
|
|
|
|
|
}}
|
|
|
|
|
color={grayed ? colors.icon : 'white'}
|
|
|
|
|
size={SIZE.lg}
|
|
|
|
|
/>
|
|
|
|
|
) : null}
|
2020-09-07 13:12:41 +05:00
|
|
|
<Text
|
|
|
|
|
style={[styles.buttonText, {color: grayed ? colors.icon : 'white'}]}>
|
|
|
|
|
{title}
|
|
|
|
|
</Text>
|
2020-09-09 11:10:35 +05:00
|
|
|
</PressableButton>
|
2020-09-07 13:12:41 +05:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
|
activityText: {
|
|
|
|
|
fontSize: SIZE.sm,
|
|
|
|
|
textAlign: 'center',
|
|
|
|
|
},
|
|
|
|
|
activityContainer: {
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
},
|
|
|
|
|
buttonText: {
|
|
|
|
|
fontFamily: WEIGHT.medium,
|
|
|
|
|
color: 'white',
|
|
|
|
|
fontSize: SIZE.sm,
|
|
|
|
|
marginLeft: 5,
|
|
|
|
|
},
|
|
|
|
|
});
|