Apps móviles con React
React Native y Expo te permiten crear apps iOS y Android con React.
Expo vs React Native CLI
| Aspecto | Expo | RN CLI |
|---|---|---|
| Setup | Fácil | Complejo |
| Build | En la nube | Local |
| Native modules | Limitado | Total |
| Ideal para | 90% de apps | Casos especiales |
Instalación Expo
npx create-expo-app mi-app
cd mi-app
npx expo start
Escanea el QR con la app Expo Go.
Componentes móviles
import { View, Text, TouchableOpacity, StyleSheet } from 'react-native'
export default function App() {
return (
<View style={styles.container}>
<Text style={styles.title}>Hola Móvil!</Text>
<TouchableOpacity style={styles.button}>
<Text style={styles.buttonText}>Presionar</Text>
</TouchableOpacity>
</View>
)
}
const styles = StyleSheet.create({
container: { flex: 1, justifyContent: 'center', alignItems: 'center' },
title: { fontSize: 24, fontWeight: 'bold' },
button: { backgroundColor: '#3b82f6', padding: 12, borderRadius: 8 },
buttonText: { color: 'white' },
})
Navegación
import { createStackNavigator } from '@react-navigation/stack'
const Stack = createStackNavigator()
function App() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Details" component={DetailsScreen} />
</Stack.Navigator>
</NavigationContainer>
)
}