Build cross-platform mobile apps with React Native and Expo
# React Native Development Guide for Google Antigravity
Create high-quality cross-platform mobile applications using React Native and Expo with Google Antigravity IDE.
## Expo Project Setup
```typescript
// app.config.ts
import { ExpoConfig, ConfigContext } from "expo/config";
export default ({ config }: ConfigContext): ExpoConfig => ({
...config,
name: "MyApp",
slug: "my-app",
version: "1.0.0",
orientation: "portrait",
icon: "./assets/icon.png",
userInterfaceStyle: "automatic",
splash: {
image: "./assets/splash.png",
resizeMode: "contain",
backgroundColor: "#ffffff"
},
assetBundlePatterns: ["**/*"],
ios: {
supportsTablet: true,
bundleIdentifier: "com.example.myapp",
config: {
usesNonExemptEncryption: false
}
},
android: {
adaptiveIcon: {
foregroundImage: "./assets/adaptive-icon.png",
backgroundColor: "#ffffff"
},
package: "com.example.myapp"
},
plugins: [
"expo-router",
["expo-camera", { cameraPermission: "Allow camera access" }],
["expo-location", { locationAlwaysAndWhenInUsePermission: "Allow location access" }]
],
experiments: {
typedRoutes: true
}
});
```
## Navigation with Expo Router
```typescript
// app/_layout.tsx
import { Stack } from "expo-router";
import { ThemeProvider, DarkTheme, DefaultTheme } from "@react-navigation/native";
import { useColorScheme } from "react-native";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
const queryClient = new QueryClient();
export default function RootLayout() {
const colorScheme = useColorScheme();
return (
<QueryClientProvider client={queryClient}>
<ThemeProvider value={colorScheme === "dark" ? DarkTheme : DefaultTheme}>
<Stack>
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
<Stack.Screen name="modal" options={{ presentation: "modal" }} />
</Stack>
</ThemeProvider>
</QueryClientProvider>
);
}
// app/(tabs)/_layout.tsx
import { Tabs } from "expo-router";
import { Ionicons } from "@expo/vector-icons";
export default function TabLayout() {
return (
<Tabs screenOptions={{ tabBarActiveTintColor: "#007AFF" }}>
<Tabs.Screen
name="index"
options={{
title: "Home",
tabBarIcon: ({ color, size }) => (
<Ionicons name="home" size={size} color={color} />
)
}}
/>
<Tabs.Screen
name="explore"
options={{
title: "Explore",
tabBarIcon: ({ color, size }) => (
<Ionicons name="compass" size={size} color={color} />
)
}}
/>
<Tabs.Screen
name="profile"
options={{
title: "Profile",
tabBarIcon: ({ color, size }) => (
<Ionicons name="person" size={size} color={color} />
)
}}
/>
</Tabs>
);
}
```
## Custom Components
```typescript
// components/Button.tsx
import { Pressable, Text, StyleSheet, ActivityIndicator } from "react-native";
import Animated, { useSharedValue, useAnimatedStyle, withSpring } from "react-native-reanimated";
interface ButtonProps {
title: string;
onPress: () => void;
variant?: "primary" | "secondary" | "outline";
loading?: boolean;
disabled?: boolean;
}
const AnimatedPressable = Animated.createAnimatedComponent(Pressable);
export function Button({ title, onPress, variant = "primary", loading, disabled }: ButtonProps) {
const scale = useSharedValue(1);
const animatedStyle = useAnimatedStyle(() => ({
transform: [{ scale: scale.value }]
}));
const handlePressIn = () => {
scale.value = withSpring(0.95);
};
const handlePressOut = () => {
scale.value = withSpring(1);
};
return (
<AnimatedPressable
style={[styles.button, styles[variant], animatedStyle, disabled && styles.disabled]}
onPress={onPress}
onPressIn={handlePressIn}
onPressOut={handlePressOut}
disabled={disabled || loading}
>
{loading ? (
<ActivityIndicator color={variant === "outline" ? "#007AFF" : "#fff"} />
) : (
<Text style={[styles.text, styles[`${variant}Text`]]}>{title}</Text>
)}
</AnimatedPressable>
);
}
const styles = StyleSheet.create({
button: {
paddingVertical: 12,
paddingHorizontal: 24,
borderRadius: 8,
alignItems: "center",
justifyContent: "center",
minHeight: 48
},
primary: {
backgroundColor: "#007AFF"
},
secondary: {
backgroundColor: "#5856D6"
},
outline: {
backgroundColor: "transparent",
borderWidth: 2,
borderColor: "#007AFF"
},
disabled: {
opacity: 0.5
},
text: {
fontSize: 16,
fontWeight: "600"
},
primaryText: {
color: "#fff"
},
secondaryText: {
color: "#fff"
},
outlineText: {
color: "#007AFF"
}
});
```
## Data Fetching Hook
```typescript
// hooks/useApi.ts
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
import * as SecureStore from "expo-secure-store";
const API_URL = process.env.EXPO_PUBLIC_API_URL;
async function fetchWithAuth(url: string, options: RequestInit = {}) {
const token = await SecureStore.getItemAsync("auth_token");
const response = await fetch(`${API_URL}${url}`, {
...options,
headers: {
"Content-Type": "application/json",
...(token && { Authorization: `Bearer ${token}` }),
...options.headers
}
});
if (!response.ok) {
throw new Error(await response.text());
}
return response.json();
}
export function useUser() {
return useQuery({
queryKey: ["user"],
queryFn: () => fetchWithAuth("/user")
});
}
export function useUpdateProfile() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: (data: { name: string; bio: string }) =>
fetchWithAuth("/user/profile", {
method: "PATCH",
body: JSON.stringify(data)
}),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["user"] });
}
});
}
```
## Best Practices
1. **Use Expo Router** for file-based navigation
2. **Implement gesture handling** with react-native-gesture-handler
3. **Use Reanimated** for performant animations
4. **Store sensitive data** with SecureStore
5. **Implement offline support** with React Query
6. **Test on real devices** regularly
7. **Optimize images** and bundle size
Google Antigravity provides intelligent React Native code suggestions and helps optimize mobile performance.This react-native prompt is ideal for developers working on:
By using this prompt, you can save hours of manual coding and ensure best practices are followed from the start. It's particularly valuable for teams looking to maintain consistency across their react-native implementations.
Yes! All prompts on Antigravity AI Directory are free to use for both personal and commercial projects. No attribution required, though it's always appreciated.
This prompt works excellently with Claude, ChatGPT, Cursor, GitHub Copilot, and other modern AI coding assistants. For best results, use models with large context windows.
You can modify the prompt by adding specific requirements, constraints, or preferences. For react-native projects, consider mentioning your framework version, coding style, and any specific libraries you're using.