React Native - Botões
Neste capítulo, mostraremos os componentes tocáveis no react Native. Nós os chamamos de 'tocáveis' porque oferecem animações integradas e podemos usar oonPress suporte para manipulação de eventos de toque.
O Facebook oferece o Buttoncomponente, que pode ser usado como um botão genérico. Considere o seguinte exemplo para entender o mesmo.
App.js
import React, { Component } from 'react'
import { Button } from 'react-native'
const App = () => {
   const handlePress = () => false
   return (
      <Button
         onPress = {handlePress}
         title = "Red button!"
         color = "red"
      />
   )
}
export default AppSe o padrão Button componente não atende às suas necessidades, você pode usar um dos seguintes componentes.
 
                Opacidade tocável
Este elemento mudará a opacidade de um elemento quando tocado.
App.js
import React from 'react'
import { TouchableOpacity, StyleSheet, View, Text } from 'react-native'
const App = () => {
   return (
      <View style = {styles.container}>
         <TouchableOpacity>
            <Text style = {styles.text}>
               Button
            </Text>
         </TouchableOpacity>
      </View>
   )
}
export default App
const styles = StyleSheet.create ({
   container: {
      alignItems: 'center',
   },
   text: {
      borderWidth: 1,
      padding: 25,
      borderColor: 'black',
      backgroundColor: 'red'
   }
}) 
                Destaque de toque
Quando um usuário pressiona o elemento, ele fica mais escuro e a cor subjacente aparece.
App.js
import React from 'react'
import { View, TouchableHighlight, Text, StyleSheet } from 'react-native'
const App = (props) => {
   return (
      <View style = {styles.container}>
         <TouchableHighlight>
            <Text style = {styles.text}>
               Button
            </Text>
         </TouchableHighlight>
      </View>
   )
}
export default App
const styles = StyleSheet.create ({
   container: {
      alignItems: 'center',
   },
   text: {
      borderWidth: 1,
      padding: 25,
      borderColor: 'black',
      backgroundColor: 'red'
   }
})Feedback nativo tocável
Isso simulará a animação da tinta quando o elemento for pressionado.
App.js
import React from 'react'
import { View, TouchableNativeFeedback, Text, StyleSheet } from 'react-native'
const Home = (props) => {
   return (
      <View style = {styles.container}>
         <TouchableNativeFeedback>
            <Text style = {styles.text}>
               Button
            </Text>
         </TouchableNativeFeedback>
      </View>
   )
}
export default Home
const styles = StyleSheet.create ({
   container: {
      alignItems: 'center',
   },
   text: {
      borderWidth: 1,
      padding: 25,
      borderColor: 'black',
      backgroundColor: 'red'
   }
})Tocável sem feedback
Isso deve ser usado quando você deseja manipular o evento de toque sem qualquer animação. Normalmente, este componente não é muito usado.
<TouchableWithoutFeedback>
   <Text>
      Button
   </Text>
</TouchableWithoutFeedback>