react-native#TouchableOpacity TypeScript Examples
The following examples show how to use
react-native#TouchableOpacity.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DropList.tsx From frontatish with MIT License | 7 votes |
DropList = (props: DropListProps) => {
const { items, active, onChange, itemStyle } = props;
const Colors = useColors();
const styles = getStyles(Colors);
const renderItem = ({ item, index }: { item: DropItem; index: number }) => {
return (
<TouchableOpacity onPress={() => onChange(index)}>
<View
style={{
backgroundColor: active === index ? Colors.font_6 : Colors.white,
padding: 16,
}}
>
<Text style={{ color: Colors.font_2, ...itemStyle }}>
{item?.label ?? item}
</Text>
</View>
{index < items.length - 1 && <Line />}
</TouchableOpacity>
);
};
return (
<View style={styles.listContainer}>
<FlatList
data={items}
// contentContainerStyle={styles.listContainer}
renderItem={renderItem}
keyExtractor={(item) => item?.label ?? item}
persistentScrollbar
/>
</View>
);
}
Example #2
Source File: IconButton.tsx From vsinder with Apache License 2.0 | 7 votes |
IconButton: React.FC<
TouchableOpacityProps & { secondary?: boolean; size?: number }
> = ({ children, secondary, style, size = 40, ...props }) => {
const [{ buttonBackground, buttonSecondaryBackground }] = useContext(
ThemeContext
);
return (
<TouchableOpacity
style={[
{
width: size,
height: size,
borderRadius: size / 2,
backgroundColor: secondary
? buttonSecondaryBackground
: buttonBackground,
alignItems: "center",
justifyContent: "center",
},
style,
]}
{...props}
>
{children}
</TouchableOpacity>
);
}
Example #3
Source File: TouchableIcon.tsx From mobile with Apache License 2.0 | 6 votes |
TouchableIcon = ({iconName, iconSize, containerSize = 56, label, onPress}: TouchableIconProps) => {
const accessibilityProps = {
accessibilityRole: 'button' as 'button',
accessibilityLabel: label,
};
const content = (
<Box width={containerSize} height={containerSize} justifyContent="center" alignItems="center">
<Icon name={iconName} size={iconSize} />
</Box>
);
if (Platform.OS === 'android') {
return (
<Ripple
rippleSize={containerSize}
rippleContainerBorderRadius={containerSize}
rippleCentered
onPress={onPress}
{...accessibilityProps}
>
{content}
</Ripple>
);
}
return (
<TouchableOpacity onPress={onPress} {...accessibilityProps}>
{content}
</TouchableOpacity>
);
}
Example #4
Source File: FlutterwaveCheckout.spec.tsx From flutterwave-react-native with MIT License | 6 votes |
describe('<FlutterwaveCheckoutError />', () => {
it('has a retry button if hasLink prop is true', () => {
// create test renderer
const TestRenderer = renderer.create(
<FlutterwaveCheckoutError hasLink onTryAgain={() => {}} />
);
// simulate animation timeframes
timeTravel();
// font retry button
const RetryButton = TestRenderer.root.findAllByType(TouchableOpacity)
// run assertions
expect(RetryButton).toHaveLength(1);
});
it('does not have a retry button if hasLink prop is false', () => {
// create test renderer
const TestRenderer = renderer.create(
<FlutterwaveCheckoutError hasLink={false} onTryAgain={() => {}} />
);
// simulate animation timeframes
timeTravel();
// font retry button
const RetryButton = TestRenderer.root.findAllByType(TouchableOpacity)
// run assertions
expect(RetryButton).toHaveLength(0);
});
});
Example #5
Source File: PrimaryButton.tsx From jmix-frontend with Apache License 2.0 | 6 votes |
PrimaryButton: FunctionComponent<PrimaryButtonProps> = ({ onPress, loading, style, disabled, children }) => {
return (
<View style={style}>
<TouchableOpacity style={[
styles.button,
disabled && {opacity: 0.5}
]}
onPress={onPress}
disabled={disabled}
>
{loading ? (
<ActivityIndicator color={colors.textInverted}/>
) : (
<Text style={styles.text}>{children}</Text>
)}
</TouchableOpacity>
</View>
);
}
Example #6
Source File: BackArrow.tsx From companion-kit with MIT License | 6 votes |
export default function BackButton(props: Props) {
const onPress = props.onPress;
return (
<TouchableOpacity style={[styles.backBtn, props.style]} onPress={onPress}>
<Images.backIcon width={28} height={14} />
</TouchableOpacity>
);
}
Example #7
Source File: Touchable.tsx From react-native-design-kit with MIT License | 6 votes |
export default function Touchable({
refView,
touchableType = 'opacity',
activeOpacity = 0.75,
style,
children,
...props
}: TouchableProps) {
switch (touchableType) {
case 'opacity':
return (
<TouchableOpacity
{...props}
style={style}
activeOpacity={activeOpacity}>
{children}
</TouchableOpacity>
);
case 'highlight':
return (
<TouchableHighlight {...props} activeOpacity={activeOpacity}>
<View ref={refView} style={style}>
{children}
</View>
</TouchableHighlight>
);
default:
return (
<TouchableWithoutFeedback {...props}>
<View ref={refView} style={style}>
{children}
</View>
</TouchableWithoutFeedback>
);
}
}
Example #8
Source File: index.tsx From SpotifyClone with MIT License | 6 votes |
AlbumHeader = (props: AlbumHeaderProps) => {
const { album } = props;
return (
<View style={styles.container}>
<Image source={{ uri: album.imageUri}} style={styles.image} />
<Text style={styles.name}>{album.name}</Text>
<View style={styles.creatorContainer}>
<Text style={styles.creator}>By {album.by}</Text>
<Text style={styles.likes}>{album.numberOfLikes} Likes</Text>
</View>
<TouchableOpacity>
<View style={styles.button}>
<Text style={styles.buttonText}>PLAY</Text>
</View>
</TouchableOpacity>
</View>
)
}
Example #9
Source File: index.tsx From TwitterClone with MIT License | 6 votes |
FleetView = (props: FleetViewProps) => {
const { user, fleet, goToNextFleet, goToPrevFleet } = props;
return (
<View style={styles.container}>
{fleet.image && <Image source={{ uri: fleet.image}} style={styles.image}/>}
<Text style={styles.text}>{fleet.text}</Text>
<View style={styles.userHeaderContainer}>
<ProfilePicture image={user.image} size={70} />
<View style={styles.userNames}>
<Text style={styles.name}>{user.name}</Text>
<View style={{flexDirection: 'row'}}>
<Text style={styles.username}>
@{user.username}
</Text>
<Text style={styles.time}>
{moment(fleet.createdAt).fromNow()}
</Text>
</View>
</View>
</View>
<View style={styles.buttonContainer}>
<TouchableOpacity style={{flex: 1}} onPress={() => goToPrevFleet()} />
<TouchableOpacity style={{flex: 1}} onPress={() => goToNextFleet()} />
</View>
</View>
)
}
Example #10
Source File: RunButton.tsx From SQL-Play with GNU Affero General Public License v3.0 | 6 votes |
RunButton: FC<Props> = ({runQuery}) => {
return (
<TouchableOpacity
testID={ids.runBtn}
accessibilityLabel="run button"
accessibilityHint="runs the command which is typed in input box"
onPress={runQuery}
style={styles.runBtn}
>
<Icon
name="send"
size={25}
style={{transform: [{translateX: 2}]}}
color="#Fff"
/>
</TouchableOpacity>
);
}
Example #11
Source File: icon.tsx From THUInfo with MIT License | 6 votes |
HomeIcon = ({
title,
onPress,
children,
}: {
title: keyof typeof zh;
onPress: (event: GestureResponderEvent) => void;
children: ReactElement;
}) => {
const themeName = useColorScheme();
const theme = themes(themeName);
return (
<TouchableOpacity
style={{
marginTop: 12,
alignItems: "center",
flexGrow: 0,
flexShrink: 0,
flexBasis: "20%",
}}
onPress={onPress}>
{children}
<Text
style={{color: theme.colors.text, marginTop: 8}}
ellipsizeMode="tail"
numberOfLines={1}>
{getStr(title)}
</Text>
</TouchableOpacity>
);
}
Example #12
Source File: TabBarAdvancedButton.tsx From clipped-tabbar with BSD 3-Clause "New" or "Revised" License | 6 votes |
TabBarAdvancedButton: React.FC<Props> = ({ bgColor, ...props }) => ( <View style={styles.container} pointerEvents="box-none" > <TabBg color={bgColor} style={styles.background} /> <TouchableOpacity style={styles.button} onPress={props.onPress} > <Icon name="rocket" style={styles.buttonIcon} /> </TouchableOpacity> </View> )
Example #13
Source File: Button.tsx From react-native-network-logger with MIT License | 6 votes |
Button: React.FC<Props> = ({ children, fullWidth, style, onPress }) => {
const styles = useThemedStyles(themedStyles);
return (
<TouchableOpacity
accessibilityRole="button"
onPress={onPress}
style={style}
>
<Text style={[styles.button, fullWidth && styles.fullWidth]}>
{children}
</Text>
</TouchableOpacity>
);
}
Example #14
Source File: index.tsx From sdc-ide with MIT License | 6 votes |
export function Button(props: Props) {
const { variant = 'primary', title, style, children, onPress, disabled: originalDisabled, ...other } = props;
const [isLoading, setIsLoading] = React.useState(false);
const disabled = originalDisabled || isLoading;
const disabledStyle = disabled
? s[`${variant}ButtonDisabled` as 'primaryButtonDisabled' | 'secondaryButtonDisabled']
: {};
return (
<TouchableOpacity
style={[s.button, s[`${variant}Button` as 'primaryButton' | 'secondaryButton'], disabledStyle, style]}
onPress={async () => {
setIsLoading(true);
await onPress();
setIsLoading(false);
}}
disabled={disabled}
{...other}
>
{children}
{title ? (
<Text
style={[s.buttonText, s[`${variant}ButtonText` as 'primaryButtonText' | 'secondaryButtonText']]}
numberOfLines={1}
>
{title}
</Text>
) : null}
</TouchableOpacity>
);
}
Example #15
Source File: CheckboxWithLabel.tsx From vsinder with Apache License 2.0 | 6 votes |
CheckboxWithLabel: React.FC<MyCheckboxProps> = ({
label,
onPress,
checked,
big,
}) => {
return (
<TouchableOpacity style={{ flexDirection: "row" }} onPress={onPress}>
<Checkbox selected={checked} />
<MyText style={{ marginLeft: 4, fontSize: big ? 16 : undefined }}>
{label}
</MyText>
</TouchableOpacity>
);
}
Example #16
Source File: CheckboxWithLabel.tsx From vsinder-app with Apache License 2.0 | 6 votes |
CheckboxWithLabel: React.FC<MyCheckboxProps> = ({
label,
onPress,
checked,
}) => {
return (
<TouchableOpacity style={{ flexDirection: "row" }} onPress={onPress}>
<Checkbox selected={checked} />
<MyText style={{ marginLeft: 4, flex: 1 }}>{label}</MyText>
</TouchableOpacity>
);
}
Example #17
Source File: ButtonPrimary.tsx From BitcoinWalletMobile with MIT License | 6 votes |
ButtonPrimary: React.FC<ButtonPrimaryProps> = (props) => {
const languageSelector = (state: WalletState) => state.language
const language = useSelector(languageSelector)
return (
<View style={styles.buttonContainer}>
<TouchableOpacity style={styles.buttonPrimary} onPress={props.action}>
{props.text == getTranslated(language).send &&
<Image style={styles.icon} source={require('../assets/images/send-button.png')} />
}
{props.text == getTranslated(language).receive &&
<Image style={styles.icon} source={require('../assets/images/received-button.png')} />
}
<Text style={styles.buttonText}>{props.text}</Text>
</TouchableOpacity>
</View>
)
}
Example #18
Source File: BackButton.tsx From SQUID with MIT License | 6 votes |
BackButton = ({
onPress,
backIcon = 'arrow-left',
}: {
onPress?: any
backIcon?: string
}) => {
const navigation = useNavigation()
return (
<TouchableOpacity
style={{ flexDirection: 'row', alignItems: 'center' }}
onPress={onPress ? onPress : () => navigation.pop()}
hitSlop={{ top: 10, left: 20, right: 20, bottom: 10 }}
>
<Icon name={backIcon} size={32} color={COLORS.BLACK_3} />
<Text
style={{
color: COLORS.BLACK_3,
fontFamily: FONT_BOLD,
marginLeft: 12,
fontSize: FONT_SIZES[500],
}}
>
{I18n.t('back')}
</Text>
</TouchableOpacity>
)
}
Example #19
Source File: TouchableIcon.tsx From mobile with Apache License 2.0 | 6 votes |
TouchableIcon = ({iconName, iconSize, containerSize = 66, label, onPress}: TouchableIconProps) => {
const accessibilityProps = {
accessibilityRole: 'button' as 'button',
accessibilityLabel: label,
};
const content = (
<Box width={containerSize} height={containerSize} justifyContent="center" alignItems="center">
<Icon name={iconName} size={iconSize} />
</Box>
);
if (Platform.OS === 'android') {
return (
<Ripple onPress={onPress} {...accessibilityProps}>
{content}
</Ripple>
);
}
return (
<TouchableOpacity activeOpacity={0.6} onPress={onPress} {...accessibilityProps}>
{content}
</TouchableOpacity>
);
}
Example #20
Source File: App.tsx From react-native-ios-context-menu with MIT License | 6 votes |
export function HomeScreen(props) {
const renderItem: ListRenderItem<ExampleListItem> = ({ item }) => (
React.createElement(item.component, {
index: item.id,
style: styles.exampleListItem
})
);
return (
<SafeAreaView>
{false && (
<TouchableOpacity
onPress={() => {
props.navigation.navigate('Test');
}}
>
<Text>
Push
</Text>
</TouchableOpacity>
)}
<FlatList
contentContainerStyle={styles.scrollContentContainer}
data={EXAMPLE_ITEMS}
renderItem={renderItem}
keyExtractor={(item) => `item-${item.id}`}
/>
</SafeAreaView>
);
}
Example #21
Source File: App.tsx From react-native-jigsaw with MIT License | 6 votes |
function Example({ title, children }: ExampleProps) {
const navigation = useNavigation();
return (
<ScreenContainer
hasSafeArea={true}
hasTopSafeArea={true}
hasBottomSafeArea={true}
scrollable={false}
>
<View style={exampleStyles.headerStyle}>
<TouchableOpacity
style={exampleStyles.menuButtonStyle}
onPress={() => navigation.dispatch(DrawerActions.toggleDrawer())}
>
<Image
style={exampleStyles.menuButtonImageStyle}
source={require("./assets/images/hamburger.png")}
/>
</TouchableOpacity>
<Text style={[exampleStyles.headerTextStyle]}>{title}</Text>
</View>
<ScreenContainer scrollable={true} hasSafeArea={false}>
{children}
</ScreenContainer>
</ScreenContainer>
);
}
Example #22
Source File: ButtonWorker.tsx From react-native-encrypted-storage with MIT License | 6 votes |
ButtonWorker: FC<ButtonWorkerProps> = (props) => {
const { title, onPress, children } = props;
const [working, setWorking] = useState<boolean>(false);
function onButtonPress() {
if (working) {
return;
}
setWorking(true);
onPress?.(() => setWorking(false));
}
return (
<TouchableOpacity
disabled={working}
activeOpacity={0.6}
onPress={onButtonPress}
style={ButtonWorkerStyle.button}
>
{working ? (
<ActivityIndicator color={ButtonWorkerStyle.text.color} />
) : title ? (
<Text style={ButtonWorkerStyle.text}>{title}</Text>
) : (
children
)}
</TouchableOpacity>
);
}
Example #23
Source File: Button.tsx From react-native-typescript-starter with MIT License | 6 votes |
Button : FC<ButtonProps> = props => {
const { effect = 'none', style, children, ...rest } = props;
const computeType = (touchableEffect : string) => {
switch (touchableEffect) {
case 'opacity':
return TouchableOpacity;
case 'highlight':
return TouchableHighlight;
case 'native':
return TouchableNativeFeedback;
case 'none':
default:
return TouchableWithoutFeedback;
}
}
const Touchable = computeType(effect);
return (
<Touchable style={[{ borderRadius : 6, padding : 10 }, style]} {...rest}>
{children}
</Touchable>
);
}
Example #24
Source File: index.tsx From selftrace with MIT License | 6 votes |
export default function Header() {
return (
<View style={styles.container}>
<TouchableOpacity
onPress={() => Router.push('/map')}
activeOpacity={0.5}
style={styles.logoContainer}>
<Image style={styles.logo} source={logoSource} resizeMode="cover" />
</TouchableOpacity>
<TabNavigator />
</View>
);
}
Example #25
Source File: BtnTemplate.tsx From ReactNative-UIKit with MIT License | 5 votes |
BtnTemplate: React.FC<BtnTemplateInterface> = (props) => {
const {disabled = false} = props;
const {styleProps} = useContext(PropsContext);
const {BtnTemplateStyles, theme, iconSize, customIcon} = styleProps || {};
const imageRef = React.useRef(null);
// This fixes the tint issue in safari browser
useImageDelay(imageRef, 10, '', props?.color || '');
return (
<TouchableOpacity
style={styleProps?.BtnTemplateContainer}
disabled={disabled}
onPress={props.onPress}>
<View
style={[
{...styles.controlBtn, ...(BtnTemplateStyles as object)},
props.style as object,
]}>
<Image
ref={Platform.OS === 'web' ? imageRef : undefined}
style={{
width: iconSize || 25,
height: iconSize || 25,
opacity: disabled ? 0.4 : 1,
tintColor: disabled ? 'grey' : props.color || theme || '#fff',
}}
resizeMode={'contain'}
source={{
uri: props.name
? customIcon?.[props.name]
? customIcon[props.name]
: icons[props.name]
: props.icon,
}}
/>
</View>
<Text
style={{
textAlign: 'center',
marginTop: 5,
color: disabled ? 'grey' : props.color || theme || '#fff',
opacity: disabled ? 0.4 : 1,
}}>
{props.btnText}
</Text>
</TouchableOpacity>
);
}
Example #26
Source File: Button.tsx From mobile with Apache License 2.0 | 5 votes |
Button = ({
text,
onPress,
variant,
color: buttonColorName,
disabled,
loading,
externalLink,
}: ButtonProps) => {
const [i18n] = useI18n();
const theme = useTheme<Theme>();
const variantProps = theme.buttonVariants[variant];
const disabledProps = disabled ? variantProps.disabled || {} : {};
const themedStyles = {...variantProps, ...disabledProps};
const {fontSize, fontWeight, fontFamily, color, borderWidth, height} = (themedStyles as unknown) as TextStyle &
ViewStyle;
const textColor = themedStyles.textColor;
const buttonColor = buttonColorName && theme.colors[buttonColorName];
const onPressHandler = loading ? () => {} : onPress;
const externalLinkProps = externalLink
? {
accessibilityLabel: text,
accessibilityHint: i18n.translate('Home.ExternalLinkHint'),
accessibilityRole: 'link' as AccessibilityRole,
}
: {};
const externalArrowIcon = textColor === palette.white ? 'icon-external-arrow-light' : 'icon-external-arrow';
const content = (
<Box
borderRadius={4}
alignItems="center"
justifyContent="center"
style={{backgroundColor: color, minHeight: height, borderWidth, borderColor: buttonColor}}
paddingHorizontal="m"
flexDirection="row"
>
{loading ? (
<ActivityIndicator color={textColor} size="large" />
) : (
<>
<Text style={{...styles.content, color: textColor || buttonColor, fontWeight, fontFamily, fontSize}}>
{text}
</Text>
{externalLink && <Icon name={externalArrowIcon} />}
</>
)}
</Box>
);
const accessibilityProps = {
accessibilityRole: 'button' as 'button',
accessibilityState: {disabled},
...externalLinkProps,
};
if (Platform.OS === 'android') {
return (
<Ripple rippleContainerBorderRadius={4} onPress={onPressHandler} {...accessibilityProps}>
{content}
</Ripple>
);
}
return (
<TouchableOpacity onPress={onPressHandler} style={styles.stretch} disabled={disabled} {...accessibilityProps}>
{content}
</TouchableOpacity>
);
}
Example #27
Source File: index.tsx From NLW-1.0 with MIT License | 5 votes |
Detail: React.FC = () => {
const [data, setData] = useState<Data>({} as Data);
const navigation = useNavigation();
const route = useRoute();
const routeParams = route.params as Params;
useEffect(() => {
async function loadPoint() {
const response = await api.get(`/points/${routeParams.point_id}`);
setData(response.data);
}
loadPoint();
}, []);
function handleNavigateBack() {
navigation.goBack();
}
function handleComposeMail() {
MailComposer.composeAsync({
subject: "Interesse na coleta de resíduos",
recipients: [data.point.email],
});
}
function handleWhatsApp() {
Linking.openURL(
`whatsapp://send?phone=${data.point.whatsapp}&text=Tenho interesse na coleta de resíduos`
);
}
if (!data.point) {
return null;
}
return (
<SafeAreaView style={{ flex: 1 }}>
<View style={styles.container}>
<TouchableOpacity onPress={handleNavigateBack}>
<Icon name="arrow-left" size={20} color="#34cb79" />
</TouchableOpacity>
<Image
style={styles.pointImage}
source={{
uri: data.point.image_url,
}}
/>
<Text style={styles.pointName}>{data.point.name}</Text>
<Text style={styles.pointItems}>
{data.items.map((item) => item.title).join(",")}
</Text>
<View style={styles.address}>
<Text style={styles.addressTitle}>Endereço</Text>
<Text style={styles.addressContent}>
{data.point.city}, {data.point.uf}
</Text>
</View>
</View>
<View style={styles.footer}>
<RectButton style={styles.button} onPress={() => handleWhatsApp()}>
<FontAwesome name="whatsapp" size={20} color="#fff" />
<Text style={styles.buttonText}>Whatsapp</Text>
</RectButton>
<RectButton style={styles.button} onPress={() => handleComposeMail()}>
<Icon name="mail" size={20} color="#fff" />
<Text style={styles.buttonText}>E-mail</Text>
</RectButton>
</View>
</SafeAreaView>
);
}
Example #28
Source File: cart.spec.tsx From rocketseat-gostack-11-desafios with MIT License | 5 votes |
TestComponent: React.FC = () => {
const { products, addToCart, increment, decrement } = useCart();
function handleAddToCart(): void {
addToCart({
id: '1234',
title: 'Test product',
image_url: 'test',
price: 1000,
quantity: 0,
});
}
function handleIncrement(): void {
increment('1234');
}
function handleDecrement(): void {
decrement('1234');
}
return (
<>
<TouchableOpacity testID="add-to-cart" onPress={handleAddToCart}>
Add to cart
</TouchableOpacity>
<TouchableOpacity testID="increment" onPress={handleIncrement}>
Increment
</TouchableOpacity>
<TouchableOpacity testID="decrement" onPress={handleDecrement}>
Decrement
</TouchableOpacity>
{products.map(product => (
<View key={product.id}>
<Text>{product.title}</Text>
<Text>{product.quantity}</Text>
</View>
))}
</>
);
}
Example #29
Source File: PayWithFlutterwave.spec.tsx From flutterwave-react-native with MIT License | 5 votes |
CustomButton = ({onPress, disabled}) => (
<TouchableOpacity
testID={CustomBtnTestID}
onPress={onPress}
disabled={disabled}>
<Text>{disabled ? 'Please wait...' : 'Pay'}</Text>
</TouchableOpacity>
)