/
Muip
/
ProBody
Обзор
Документация
Войти
/
Muip
/
ProBody
Код
Запросы
0
Задачи
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
components/AButton.tsx
71 строка
2 KB
chmerev
new
14 авг 2024, 12:02
14 авг 2024, 12:02
595f266
Код
Авторство
О чём код?
import * as React from 'react'; import { View, Text, StyleSheet, TouchableOpacity, TouchableOpacityProps, ActivityIndicator, StyleProp, TextStyle, ViewStyle, } from 'react-native'; import Colors from '../constants/Colors'; import AppStyle from '../constants/AppStyle'; interface AButtonProps extends TouchableOpacityProps { text?: string; loading?: boolean; style?: StyleProp<ViewStyle>, textStyle?: StyleProp<TextStyle> onPress?: (() => void) | (() => Promise<void>); children?: React.ReactNode; disabled?: boolean; } const AButton: React.FC<AButtonProps> = (props) => { const { text, style, loading, textStyle } = props; let newStyle = {} as ViewStyle; if (props.disabled) { newStyle = styles.disabled; } return <TouchableOpacity disabled={props.disabled == true} {...props} style={[styles.button, style, newStyle]} onPress={props.onPress} > {text && <Text style={[styles.text, textStyle]}>{text}</Text>} {loading && <View style={styles.loading}> <ActivityIndicator size="small" color={Colors.background} /> </View> } {props.children} </TouchableOpacity > } export default AButton; const styles = StyleSheet.create({ loading: { position: 'absolute', alignSelf: 'center', right: 10 }, button: { backgroundColor: Colors.accent, borderRadius: 40, fontFamily: AppStyle.fontFamily, width: '100%', height: 60, alignItems: 'center', justifyContent: 'center', paddingHorizontal: 20 }, text: { fontSize: 18, color: Colors.background, fontFamily: AppStyle.fontFamilyBold, }, disabled: { opacity: 0.5, } });