import * as React from 'react'; import { useMemo } from 'react'; import { StyleSheet, TextStyle, View } from 'react-native'; import { TouchableRipple, Text } from 'react-native-paper'; import { PromptButtonSpec } from './types'; import { ThemeStyle, themeStyle } from '../global-style'; import Icon from '../Icon'; interface Props { themeId: number; buttonSpec: PromptButtonSpec; } const useStyles = (theme: ThemeStyle) => { return useMemo(() => { const buttonText: TextStyle = { color: theme.color4, textAlign: 'center', }; return StyleSheet.create({ buttonContainer: { // This applies the borderRadius to the TouchableRipple's parent, which // seems necessary on Android. borderRadius: theme.borderRadius, overflow: 'hidden', }, button: { borderRadius: theme.borderRadius, padding: 10, }, buttonContent: { display: 'flex', flexDirection: 'row', justifyContent: 'center', alignItems: 'baseline', }, buttonText, icon: { ...buttonText, marginRight: 8, }, }); }, [theme]); }; const PromptButton: React.FC = props => { const theme = themeStyle(props.themeId); const styles = useStyles(theme); const { checked, text, iconChecked, onPress } = props.buttonSpec; const isCheckbox = (checked ?? null) !== null; const icon = checked ? ( <> ) : null; return ( {icon} {text} ); }; export default PromptButton;