بناء أول تطبيق React Native: دليل خطوة بخطوة
تطوير التطبيقات

بناء أول تطبيق React Native: دليل خطوة بخطوة

React Native يسمح لك ببناء تطبيقات native للـ iOS و Android باستخدام React. ابدأ من الصفر.

م
مؤسس LahbabiGuide
3 دقائق قراءة
شارك:

لماذا React Native؟

React Native أداة من Meta (Facebook) لبناء تطبيقات الجوّال باستخدام React وJavaScript. تستخدمها Facebook و Instagram و Shopify و Tesla.

مزاياها:

  • مكوّنات native حقيقية (ليست webview)
  • JavaScript المعروف للجميع
  • Hot Reload فوري
  • مكتبة ضخمة من الـ packages

الإعداد السريع بـ Expo

Expo أبسط طريقة للبدء — لا تحتاج Android Studio ولا Xcode.

bash
npx create-expo-app my-app
cd my-app
npx expo start

افتح تطبيق Expo Go على هاتفك، اسكن الـ QR code، وتطبيقك يعمل فوراً.

أول شاشة

tsx
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View } from 'react-native';

export default function App() {
  return (
    <View style={styles.container}>
      <Text style={styles.title}>أهلاً بك</Text>
      <Text style={styles.subtitle}>أول تطبيق React Native</Text>
      <StatusBar style="auto" />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
  title: { fontSize: 28, fontWeight: 'bold' },
  subtitle: { fontSize: 16, color: '#666', marginTop: 8 },
});
إعلان

المكوّنات الأساسية

بدلاً من <div> و <p>، تستخدم:

| HTML | React Native | |------|-------------| | <div> | <View> | | <p>, <span> | <Text> | | <img> | <Image> | | <input> | <TextInput> | | <button> | <Pressable> أو <TouchableOpacity> | | <ul> | <FlatList> |

الأنماط (Styling)

مشابه CSS-in-JS:

tsx
<View
  style={{
    padding: 16,
    borderRadius: 12,
    backgroundColor: '#eef',
  }}
>
  <Text style={{ fontSize: 18, fontWeight: 'bold' }}>عنوان</Text>
</View>

ملاحظة: جميع القيم بالأرقام (بدون px). Layout افتراضياً Flexbox.

نموذج تسجيل بسيط

tsx
import { useState } from 'react';
import { View, Text, TextInput, Pressable, Alert } from 'react-native';

export default function Login() {
  const [email, setEmail] = useState('');
  const [password, setPassword] = useState('');

  async function handleLogin() {
    if (!email.includes('@')) {
      Alert.alert('خطأ', 'بريد إلكتروني غير صالح');
      return;
    }
    // منطق تسجيل الدخول...
    Alert.alert('نجح', 'مرحباً ' + email);
  }

  return (
    <View style={{ padding: 20, gap: 12 }}>
      <Text style={{ fontSize: 24, fontWeight: 'bold' }}>تسجيل الدخول</Text>
      <TextInput
        placeholder="البريد"
        value={email}
        onChangeText={setEmail}
        keyboardType="email-address"
        autoCapitalize="none"
        style={{ borderWidth: 1, borderRadius: 8, padding: 10 }}
      />
      <TextInput
        placeholder="كلمة السر"
        value={password}
        onChangeText={setPassword}
        secureTextEntry
        style={{ borderWidth: 1, borderRadius: 8, padding: 10 }}
      />
      <Pressable
        onPress={handleLogin}
        style={{ backgroundColor: '#6366f1', padding: 12, borderRadius: 8 }}
      >
        <Text style={{ color: 'white', textAlign: 'center' }}>دخول</Text>
      </Pressable>
    </View>
  );
}

التنقّل (Navigation)

أكثر مكتبة شهرة: React Navigation.

bash
npm install @react-navigation/native @react-navigation/native-stack
npx expo install react-native-screens react-native-safe-area-context
tsx
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';

const Stack = createNativeStackNavigator();

export default function App() {
  return (
    <NavigationContainer>
      <Stack.Navigator>
        <Stack.Screen name="Home" component={HomeScreen} />
        <Stack.Screen name="Details" component={DetailsScreen} />
      </Stack.Navigator>
    </NavigationContainer>
  );
}

// داخل الشاشة
function HomeScreen({ navigation }) {
  return (
    <Pressable onPress={() => navigation.navigate('Details', { id: 42 })}>
      <Text>انتقل للتفاصيل</Text>
    </Pressable>
  );
}

جلب البيانات من API

tsx
import { useEffect, useState } from 'react';
import { FlatList, Text, View } from 'react-native';

export default function PostsList() {
  const [posts, setPosts] = useState([]);
  const [loading, setLoading] = useState(true);

  useEffect(() => {
    fetch('https://jsonplaceholder.typicode.com/posts?_limit=10')
      .then(r => r.json())
      .then(data => {
        setPosts(data);
        setLoading(false);
      });
  }, []);

  if (loading) return <Text>جارٍ التحميل...</Text>;

  return (
    <FlatList
      data={posts}
      keyExtractor={(item) => String(item.id)}
      renderItem={({ item }) => (
        <View style={{ padding: 16, borderBottomWidth: 1 }}>
          <Text style={{ fontWeight: 'bold' }}>{item.title}</Text>
          <Text style={{ marginTop: 4 }}>{item.body}</Text>
        </View>
      )}
    />
  );
}

النشر (Publishing)

  • Expo Go: لتجربة المطوّر، يحتاج تطبيق Expo Go
  • EAS Build: يُنشئ APK/IPA للنشر
  • Google Play / App Store: تحتاج حساباً مطوّراً (25$ / 99$ سنوياً)

الأسئلة الشائعة

Expo vs Bare React Native؟

  • Expo: أسرع بداية، مكتبات محدّدة، محدودية في الـ native modules
  • Bare: تحكّم كامل، تحتاج Xcode/Android Studio

للمبتدئ: Expo دائماً.

هل أحتاج Mac لتطوير iOS؟

لـ EAS Build: لا — Expo يبني في السحابة. للاختبار على iOS: تحتاج Mac فعلاً.

React Native vs Flutter؟

اختر حسب خلفيتك. تعرف React؟ استخدم React Native. تبدأ من الصفر وتحبّ UI متقن؟ Flutter.

اقرأ أيضاً

مقالات ذات صلة