๊ฐœ๋ฐœ ๊ณต๋ถ€/๋ฐ๋ธŒ์ฝ”์Šค TIL

[ํด๋ผ์šฐ๋”ฉ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์—”์ง€๋‹ˆ์–ด๋ง TIL] 240318, 240319 - React Native ์‹ฌํ™” ์ปดํฌ๋„ŒํŠธ

๊ฐ€์šค์ด 2024. 3. 19. 17:32

Intro


์˜ค๋Š˜์€ ์–ด์ œ์— ์ด์–ด ๋ฆฌ์•กํŠธ ๋„ค์ดํ‹ฐ๋ธŒ์˜ ๋” ๋‹ค์–‘ํ•œ ์ปดํฌ๋„ŒํŠธ๋“ค์„ ์•Œ์•„๋ณด๊ณ  ์‹ค์Šตํ•ด ๋ณด์•˜๋‹ค.

 

 

 

์˜ค๋Š˜ ํ•™์Šตํ•œ ๋‚ด์šฉ


FlatList

: ๋Œ€์šฉ๋Ÿ‰ ๋ฐ์ดํ„ฐ๋ฅผ ํ•œ ๋ฒˆ์— ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ์ปดํฌ๋„ŒํŠธ

๋‹จ์ ์œผ๋กœ๋Š” ๋™์  ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ์— ๋ Œ๋”๋ง์ด ๋งŽ์ด ํ•„์š”ํ•˜๊ณ  ๋ถ€๋ชจ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋ Œ๋”๋ง ๋  ๋•Œ FlatList๋„ ๋ฆฌ๋ Œ๋”๋ง ๋œ๋‹ค๋Š” ์ ์ด ์žˆ๋‹ค.

๊ทธ๋ž˜์„œ ๋ณดํ†ต useCallback์œผ๋กœ ์ฒ˜๋ฆฌํ•œ๋‹ค.

<FlatList
  data={dummy_data}
  renderItem={({item, index}) =>
    <TestTemplate data={item} />
  }
  keyExtractor={item => item.id}
  ListHeaderComponent={() => (
    <View style={styles.chatDayWrapper}>
       <Text style={styles.chatDay}>2022๋…„ 2์›” 7์ผ</Text>
   </View>
  )}
  showsVerticalScrollIndicator={false}
/>

 

 

 


โœ… iOS ์‹œ๋ฎฌ๋ ˆ์ดํ„ฐ์—์„œ ๋ฆฌ์•กํŠธ ๋„ค์ดํ‹ฐ๋ธŒ ๋””๋ฒ„๊น… ์—ฌ๋Š” ๋ฒ•
โ–ซ๏ธ Flipper ์„ค์น˜ (
โ–ซ๏ธ ์‹œ๋ฎฌ๋ ˆ์ดํ„ฐ์—์„œ Cmd โŒ˜+ D→ open debugger

 

 

 

์ธํ„ฐ๋ ‰์…˜์„ ์œ„ํ•œ Animated

: ์—๋‹ˆ๋ฉ”์ด์…˜ API

 

Props

  • useNativeDriver: ์‚ฌ์šฉ ์‹œ ์„ฑ๋Šฅ์ด ์˜ฌ๋ผ๊ฐ
  • toValue
  • duration: ์ˆซ์ž(ms) ๋™์•ˆ ๋ณ€ํ•จ

Func

  • timing
  • spring
  • ...

 


React Navigation

 

Getting started | React Navigation

What follows within the Fundamentals section of this documentation is a tour of the most important aspects of React Navigation. It should cover enough for you to know how to build your typical small mobile application, and give you the background that you

reactnavigation.org

 

  • ์„ค์น˜ํ•˜๊ธฐ
npm install @react-navigation/native
npm install react-native-screens react-native-safe-area-context

 

  • ํ•„์š”ํ•œ Navigators ์„ค์น˜
npm install @react-navigation/stack
npm install @react-navigation/bottom-tabs

...

 

  • pod install
cd ios
npx pod-install

 

  • ์‚ฌ์šฉํ•˜๊ธฐ

: ํŽ˜์ด์ง€์˜ props๋กœ navigation ๊ฐ€์ ธ์˜ค๊ฑฐ๋‚˜ useNavigation ์‚ฌ์šฉ

import React from 'react';
import { View } from 'react-native';

const Test = ({ navigation }) => {
  return <View></View>
}

export default Test
import {useNavigation} from '@react-navigation/native';

const Test = () => {
  const navigation = useNavigation();
  ...
}

 

 

 

 


Modal

: react naitve์— modal ๊ธฐ๋ณธ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์žˆ์œผ๋‚˜ ์ปค์Šคํ…€์ด ๋ฒˆ๊ฑฐ๋กœ์›Œ ์ž˜ ์‚ฌ์šฉํ•˜์ง€ ์•Š์Œ

์ฃผ๋กœ ์•„๋ž˜์˜ react-native-modal์„ ์‚ฌ์šฉ

 

GitHub - react-native-modal/react-native-modal: An enhanced, animated, customizable Modal for React Native.

An enhanced, animated, customizable Modal for React Native. - react-native-modal/react-native-modal

github.com

import React from 'react';
import {View, TouchableOpacity, Text, StyleSheet} from 'react-native';
import Modal from 'react-native-modal';

const AlertModal = ({
  isVisible,
  okText,
  noText,
  headerTitle,
  onPressOk,
  onPressNo,
}) => {
  return (
    <Modal
      useNativeDriver
      animationOut="zoomIn"
      animationOut="fadeOut"
      animationInTiming={200}
      animationOutTiming={200}
      isVisible={isVisible}
      backdropOpacity={0.6}
      style={styles.modalContainer}>
      <View style={styles.modalBox}>
        <View style={styles.modalHeader}>
          <Text>{headerTitle}</Text>
        </View>
        <View style={styles.modalButtonContainer}>
          <TouchableOpacity onPress={onPressNo} style={styles.modalButton}>
            <Text>{noText}</Text>
          </TouchableOpacity>
          <TouchableOpacity onPress={onPressOk} style={styles.modalButton}>
            <Text>{okText}</Text>
          </TouchableOpacity>
        </View>
      </View>
    </Modal>
  );
};

const styles = StyleSheet.create({
  modalContainer: {
    margin: 0,
    justifyContent: 'center',
    alignItems: 'center',
  },
  modalBox: {
    width: 320,
    borderRadius: 8,
    backgroundColor: '#fff',
    paddingTop: 10,
  },
  modalHeader: {
    minHeight: 40,
    justifyContent: 'center',
    alignItems: 'center',
  },
  modalButtonContainer: {
    flexDirection: 'row',
    borderStyle: 'solid',
    borderColor: '#c3c3c3',
    borderTopWidth: 0.5,
  },
  modalButton: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    height: 50,
  },
});

export default AlertModal;

 

 

 

 


๊ทธ ์™ธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

Calendar

https://github.com/wix/react-native-calendars

 

GitHub - wix/react-native-calendars: React Native Calendar Components ๐Ÿ—“๏ธ ๐Ÿ“†

React Native Calendar Components ๐Ÿ—“๏ธ ๐Ÿ“† . Contribute to wix/react-native-calendars development by creating an account on GitHub.

github.com

 

Slider

https://github.com/meliorence/react-native-snap-carousel

 

GitHub - meliorence/react-native-snap-carousel: Swiper/carousel component for React Native featuring previews, multiple layouts,

Swiper/carousel component for React Native featuring previews, multiple layouts, parallax images, performant handling of huge numbers of items, and more. Compatible with Android & iOS. - melior...

github.com

 

 

 

 

๋งˆ๋ฌด๋ฆฌ


๊ธฐ๋ณธ ์ปดํฌ๋„ŒํŠธ๋ณด๋‹ค ์•ฝ๊ฐ„ ์–ด๋ ค์›Œ์ ธ์„œ ๊ณ„์† ๋งŒ๋“ค์–ด๋ณด๊ณ  ์ต์ˆ™ํ•ด์ ธ์•ผ๊ฒ ๋‹ค.