9.3.2.1 모달 만들기

    react-native에서 모달을 만들 때는 주로 Modal이라는 컴포넌트를 사용합니다. 이 컴포넌트를 사용하지 않아도 직접 구현할 수 있지만, 이 컴포넌트를 사용하면 더욱 간편하게 모달을 구현할 수 있습니다.

    components/UploadModeModal.js

    import React from 'react';
    import {StyleSheet, Modal, View, Pressable, Text} from 'react-native';
    import Icon from 'react-native-vector-icons/MaterialIcons';
    
    function UploadModeModal({visible, onClose}) {
      return (
        <Modal
          visible={visible}
          transparent={true}
          animationType="fade"
          onRequestClose={onClose}>
          <Pressable style={styles.background} onPress={onClose}>
            <View style={styles.whiteBox}>
              <Pressable
                style={styles.actionButton}
                android_ripple={{color: '#eee'}}>
                <Icon
                  name="camera-alt"
                  color="#757575"
                  size={24}
                  style={styles.icon}
                />
                <Text style={styles.actionText}>카메라로 촬영하기</Text>
              </Pressable>
              <Pressable
                style={styles.actionButton}
                android_ripple={{color: '#eee'}}>
                <Icon name="photo" color="#757575" size={24} style={styles.icon} />
                <Text style={styles.actionText}>사진 선택하기</Text>
              </Pressable>
            </View>
          </Pressable>
        </Modal>
      );
    }
    
    const styles = StyleSheet.create({
      background: {
        backgroundColor: 'rgba(0,0,0,0.6)',
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
      },
      whiteBox: {
        width: 300,
        backgroundColor: 'white',
        borderRadius: 4,
        elevation: 2,
      },
      actionButton: {
        padding: 16,
        flexDirection: 'row',
        alignItems: 'center',
      },
      icon: {
        marginRight: 8,
      },
      text: {
        fontSize: 16,
      },
    });
    
    export default UploadModeModal;
    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.