React Native core komponentlar

React Native da UI komponentlar dan quriladi. Web da

<div>
va CSS ishlatganingiz kabi, bu yerda
<View>
,
<Text>
va JavaScript obyektlari ko'rinishidagi stillar ishlatiladi.

View — asosiy konteyner

View
eng ko'p ishlatiladigan komponent. Boshqa komponentlarni o'rab, layout yaratadi.

import { 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>
ga o'xshaydi, lekin
<View>
ichiga to'g'ridan-to'g'ri matn yozib bo'lmaydi — buning uchun
<Text>
kerak.

Text — matn

Barcha ko'rinadigan matn

<Text>
ichida bo'lishi shart:

import { Text } from 'react-native'; <Text style={{ fontSize: 18, fontWeight: 'bold' }}> Assalomu alaykum </Text>

<Text>
ichidagi
<Text>
nested bo'lishi mumkin — ichki qism boshqa stil oladi (masalan, qisman qalin yoki rangli).

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' }}

width
va
height
berish unutmang — aks holda rasm ko'rinmasligi mumkin.

TextInput — 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 }} /> ); }

value
+
onChangeText
— controlled input: state matnning yagona manbai.

StyleSheet 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

WebReact Native
div
View
p
,
span
Text
img
Image
input
TextInput
CSS faylStyleSheet obyekti
px
,
%
,
em
asosan raqam (density-independent pixels)

CSS dagi

display: grid
yoki murakkab selectorlar yo'q. Layout asosan Flexbox bilan qilinadi.

Muhim cheklovlar

  • Faqat bitta
    StyleSheet
    xususiyati, masalan
    fontSize
    — camelCase
  • className
    yo'q
  • Ba'zi CSS xususiyatlari platformaga bog'liq (keyinroq shadow haqida gapiramiz)

Xulosa

  • View
    — konteyner,
    Text
    — matn,
    Image
    — rasm,
    TextInput
    — kiritish
  • Stil obyekt sifatida, odatda
    StyleSheet.create
    bilan
  • Web DOM o'rniga native komponentlar — bu React Native ning asosi

Keyingi darsda layout ning yuragi — Flexbox — ni chuqur o'rganamiz.