Program-Me-Rev
Program-Me-Rev

Reputation: 6624

How to make a container / wrapper View Clickable in React

What is the equivalent for linearLayout.setClickable(true); (Android) in React Native below :

<View style={{ flexDirection: 'row', }} ><Text>Hello World!<Text /><View />  

I would like to make the <View /> container / wrapper clickable.

Thank you all.

Upvotes: 1

Views: 1035

Answers (3)

Tim
Tim

Reputation: 10719

Just wrap your container in a Touchable.

For example:

<TouchableOpacity onPress={() => console.log('onPress')}>
  <View style={{ flexDirection: 'row', }} >
    <Text>Hello World! </Text>
  </View>  
</TouchableOpacity>

Btw. In your example the closing tags were wrong, I corrected them in my example.

Upvotes: 1

warmachine
warmachine

Reputation: 376

import { Text, View, TouchableOpacity } from "react-native";

 <TouchableOpacity onPress={() => pressHandler()}>
      <View style={{ flexDirection: 'row', }} ><Text>Hello World!<Text /><View /> 
    </TouchableOpacity>
  );

wrap those inside TouchableOpacity or any other Touch wrappers

Upvotes: 1

Alexander
Alexander

Reputation: 1390

Wrap View in TouchableOpacity

<TouchableOpacity onPress={handler}> 
   <View style={{ flexDirection: 'row', }} >
      <Text>Hello World!<Text />
   <View />  
</TouchableOpacity>

Upvotes: 1

Related Questions