6.3.1 FloatingWriteButton 만들기

    FloatingWriteButtonFeedsScreen의 우측 모서리에 나타나는 둥근 버튼입니다. 프로젝트 루트 디렉터리에 components 디렉터리를 만들고, 그 안에 다음 파일을 작성하세요.

    components/FloatingWriteButton.js

    import React from 'react';
    import {Platform, Pressable, StyleSheet, View} from 'react-native';
    import Icon from 'react-native-vector-icons/MaterialIcons';
    
    function FloatingWriteButton() {
      return (
        <View style={styles.wrapper}>
          <Pressable
            style={({pressed}) => [
              styles.button,
              Platform.OS === 'ios' && {
                opacity: pressed ? 0.6 : 1,
              },
            ]}
            android_ripple={{color: 'white'}}>
            <Icon name="add" size={24} style={styles.icon} />
          </Pressable>
        </View>
      );
    }
    
    const styles = StyleSheet.create({
      wrapper: {
        position: 'absolute',
        bottom: 16,
        right: 16,
        width: 56,
        height: 56,
        borderRadius: 28,
        // iOS 전용 그림자 설정
        shadowColor: '#4d4d4d',
        shadowOffset: {width: 0, height: 4},
        shadowOpacity: 0.3,
        shadowRadius: 4,
        // 안드로이드 전용 그림자 설정
        elevation: 5,
        // 안드로이드에서 물결 효과가 영역 밖으로 나가지 않도록 설정
        // iOS에서는 overflow hidden일 경우 그림자가 보여지지 않음
        overflow: Platform.select({android: 'hidden'}),
      },
      button: {
        width: 56,
        height: 56,
        borderRadius: 28,
        backgroundColor: '#009688',
        justifyContent: 'center',
        alignItems: 'center',
      },
      icon: {
        color: 'white',
      },
    });
    
    export default FloatingWriteButton;
    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.