React Native core komponentlar
React Native da UI komponentlar dan quriladi. Web da
<div><View><Text>View — asosiy konteyner
Viewimport { View, StyleSheet } from 'react-native'; function Card() { return ( <View style={styles.card}> <View style={styles.inner}> {/* boshqa komponentlar */} </View> </View> ); } const styles = StyleSheet.create({ card: { padding: 16, backgroundColor: '#f5f5f5', borderRadius: 8, }, inner: { marginTop: 8, }, });
Web dagi
<div><View><Text>Text — matn
Barcha ko'rinadigan matn
<Text>import { Text } from 'react-native'; <Text style={{ fontSize: 18, fontWeight: 'bold' }}> Assalomu alaykum </Text>
<Text><Text>Image — rasm
import { Image } from 'react-native'; <Image source={require('./assets/logo.png')} style={{ width: 100, height: 100 }} />
- Lokal rasm:
require('./path.png') - Tarmoqdan:
source={{ uri: 'https://example.com/img.jpg' }}
widthheightTextInput — foydalanuvchi kiritishi
import { useState } from 'react'; import { TextInput } from 'react-native'; function NameInput() { const [name, setName] = useState(''); return ( <TextInput placeholder="Ismingiz" value={name} onChangeText={setName} style={{ borderWidth: 1, padding: 10 }} /> ); }
valueonChangeTextStyleSheet vs inline style
Inline — tez sinov uchun:
<View style={{ padding: 10, backgroundColor: 'white' }} />
StyleSheet.create — production uchun tavsiya:
const styles = StyleSheet.create({ container: { flex: 1, padding: 20 }, });
Afzalliklari: kod tartibli, xatolarni tezroq topish, biroz yaxshiroq performance.
Bir nechta stil birlashtirish:
<View style={[styles.box, styles.highlighted]} />
Web bilan taqqoslash
| Web | React Native |
|---|---|
div | View |
pspan | Text |
img | Image |
input | TextInput |
| CSS fayl | StyleSheet obyekti |
px%em | asosan raqam (density-independent pixels) |
CSS dagi
display: gridMuhim cheklovlar
- Faqat bitta xususiyati, masalan
StyleSheet— camelCasefontSize - yo'q
className - Ba'zi CSS xususiyatlari platformaga bog'liq (keyinroq shadow haqida gapiramiz)
Xulosa
- — konteyner,
View— matn,Text— rasm,Image— kiritishTextInput - Stil obyekt sifatida, odatda bilan
StyleSheet.create - Web DOM o'rniga native komponentlar — bu React Native ning asosi
Keyingi darsda layout ning yuragi — Flexbox — ni chuqur o'rganamiz.