React-Native expo에서 FAB 버튼 만들기

2024. 11. 28. 20:05·Mobile/React Native

React-Native expo에서 FAB 버튼 만들기

FAB 버튼이란?

우측 하단에 있는 조그마한 버튼을 일반적으로 "Floating Action Button" (FAB) 이라고 칭한다.

추가 이동같은 간단한 작업할때 주로 사용.

FAB 버튼 코드

import { Alert, StyleSheet, Text, TouchableOpacity } from 'react-native';

const FAB: React.FC<Props> = () => {
  const AddLocationListAlert = () => {
    Alert.prompt(//제목 , // 내용 , [
      {
        text: 'Cancel',
        onPress: () => {
            // 취소시 작동하는것
        },
        style: 'cancel',
      },
      {
        text: 'OK',
        onPress: (text) => {
          // ok 누를시 작동하는 것!
        },
      },
    ]);
  };

  return (
    <TouchableOpacity style={styles.fab} onPress={AddLocationListAlert}>
      <Text style={styles.fabText}>+</Text>
    </TouchableOpacity>
  );
};

const styles = StyleSheet.create({
  fab: {
    position: 'absolute',
    bottom: 25,
    right: 25,
    backgroundColor: '#6200ee',
    width: 56,
    height: 56,
    borderRadius: 28,
    justifyContent: 'center',
    alignItems: 'center',
    shadowColor: '#000',
    shadowOpacity: 0.2,
    shadowOffset: { width: 0, height: 2 },
    shadowRadius: 2,
    elevation: 5,
  },
  fabText: {
    color: 'white',
    fontSize: 24,
    fontWeight: 'bold',
  },
});

export default FAB;

FAB 버튼에 Prompt를 이용해 구현해봤다.

구현 샘플

반응형

'Mobile > React Native' 카테고리의 다른 글

npx pod-install ios 를 해주는 이유  (4) 2025.01.03
[React-Native CLI] React Native Encrypted Storage 사용하기  (1) 2025.01.03
React-Native 에서 TextInput 사용해보기  (1) 2024.11.17
React-Native expo 시작하기 (새버전)  (2) 2024.11.15
React-Native 커스텀 폰트 설치하기  (1) 2024.11.14
'Mobile/React Native' 카테고리의 다른 글
  • npx pod-install ios 를 해주는 이유
  • [React-Native CLI] React Native Encrypted Storage 사용하기
  • React-Native 에서 TextInput 사용해보기
  • React-Native expo 시작하기 (새버전)
WHITE_FROST
WHITE_FROST
개발공부리뷰블로그
  • WHITE_FROST
    하얀하얀IT
    WHITE_FROST
  • 전체
    오늘
    어제
    • 분류 전체보기 (138)
      • Infra (5)
      • Project & Troubleshooting (14)
        • Troubleshooting (7)
        • Dev Tools (4)
      • Frontend (30)
        • Next.js (9)
        • React (13)
        • TypeScript (2)
        • JavaScript (6)
      • Mobile (17)
        • React Native (16)
        • Android (1)
      • Backend & Data (7)
        • Database (3)
        • Java (1)
        • Python (2)
        • Design Pattern (1)
      • AI (7)
        • Models & API (1)
        • AI Notes (6)
        • AI Tools (0)
        • Local AI (0)
        • Concepts (0)
      • Problem Solving (52)
        • Algorithm Notes (6)
        • Algorithm Practice (46)
      • Growth Log (9)
        • Study Log (6)
        • Tips (0)
        • Etc (3)
  • 블로그 메뉴

    • 홈
    • 태그
    • 미디어로그
    • 위치로그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    알고리즘
    Expo
    프로그래머스
    javascript
    Python
    java
    hooks
    React-Native cli
    React Hooks
    Claude
    error
    D2
    Next.js
    백준
    react-native
    코테
    boj
    리액트네이티브
    mongodb cloud
    Ai
    d1
    티스토리챌린지
    SWEA
    오블완
    ReactHook
    reactnative
    ios
    react
    코딩테스트
    react-native-maps
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.5
WHITE_FROST
React-Native expo에서 FAB 버튼 만들기
상단으로

티스토리툴바