Modal va Pressable

Ba'zi kontent asosiy ekran ustida vaqtincha ochilishi kerak — masalan, yangi maqsad kiritish formasi. Buning uchun Modal. Tugmalar uchun esa zamonaviy yechim — Pressable.

Modal — asoslar

import { Modal, View, Button } from 'react-native'; function GoalModal({ visible, onClose }) { return ( <Modal visible={visible} animationType="slide"> <View style={styles.centered}> <Text>Yangi maqsad</Text> {/* form */} <Button title="Yopish" onPress={onClose} /> </View> </Modal> ); }
  • visible
    — boolean, ko'rsatish/yashirish
  • animationType
    :
    slide
    ,
    fade
    ,
    none

Modal butun ekran yoki markaziy dialog bo'lishi mumkin — layout sizning dizayningizga bog'liq.

Modal state

const [modalVisible, setModalVisible] = useState(false); <Button title="Ochish" onPress={() => setModalVisible(true)} /> <GoalModal visible={modalVisible} onClose={() => setModalVisible(false)} />

Ota komponent modal ochiq/yopiq holatini boshqaradi.

Overlay (qorong'u fon)

Modal ichida ikkinchi

View
— yarim shaffof fon:

<Modal visible={visible} transparent animationType="fade"> <View style={styles.overlay}> <View style={styles.dialog}> {/* kontent */} </View> </View> </Modal> const styles = StyleSheet.create({ overlay: { flex: 1, backgroundColor: 'rgba(0,0,0,0.5)', justifyContent: 'center', alignItems: 'center', }, dialog: { width: '80%', backgroundColor: 'white', padding: 20, borderRadius: 8, }, });

Pressable

TouchableOpacity
o'rniga zamonaviy API:

import { Pressable, Text } from 'react-native'; <Pressable onPress={handlePress} style={({ pressed }) => [ styles.button, pressed && styles.pressed, ]} android_ripple={{ color: '#ccc' }} > <Text>Bosing</Text> </Pressable>
  • pressed
    — bosilgan holat (iOS da opacity o'zgartirish)
  • android_ripple
    — Material ripple (faqat Android)

Pressable vs Button

ButtonPressable
Tez prototipTo'liq custom dizayn
Cheklangan stilIstalgan UI

Production ilovalarda ko'pincha custom

Pressable
+
Text
.

Xulosa

  • Modal — vaqtincha ekran/form,
    visible
    bilan boshqariladi
  • transparent
    + overlay — dialog ko'rinishi
  • Pressable — bosish feedback iOS va Android uchun
  • Modal ochiq/yopiq state ota komponentda

Keyingi darsda styling chuqurroq: shadow, global ranglar, UI polish.