https://github.com/ssi02014/react-native-tutorial
https://github.com/ssi02014/react-native-tutorial
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/ssi02014/react-native-tutorial
- Owner: ssi02014
- Created: 2021-04-05T17:32:49.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-04-07T05:41:57.000Z (over 4 years ago)
- Last Synced: 2024-12-30T06:44:58.279Z (9 months ago)
- Language: JavaScript
- Size: 226 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ป React-Native-Tutorial
### React-Native-Tutorial ์ ์ฅ์
## ๐จ๐ปโ๐ป React-native ๋ด์ฅ ์ปดํฌ๋ํธ
๐ https://reactnative.dev/docs/components-and-apis### ๐ Basic Components
- View: UI ๊ตฌ์ถ์ ์ํ ๊ฐ์ฅ ๊ธฐ๋ณธ์ ์ธ ๊ตฌ์ฑ ์์
- Text: ํ ์คํธ๋ฅผ ํ์ํ๊ธฐ์ํ ๊ตฌ์ฑ ์์
- Image: ์ด๋ฏธ์ง๋ฅผ ํ์ํ๊ธฐ์ํ ๊ตฌ์ฑ ์์
- TextInput: ํค๋ณด๋๋ฅผ ํตํด ์ฑ์ ํ ์คํธ๋ฅผ ์ ๋ ฅํ๊ธฐ ์ํ ๊ตฌ์ฑ ์์
- ScrollView: ์ฌ๋ฌ ๊ตฌ์ฑ ์์ ๋ฐ ๋ณด๊ธฐ๋ฅผ ํธ์คํ ํ ์ ์๋ ์คํฌ๋กค ์ปจํ ์ด๋
- StyleSheet: CSS ์คํ์ผ ์ํธ์ ์ ์ฌํ ์ถ์ํ ๊ณ์ธต์ ์ ๊ณต
### ๐ User Interface
- Button: ๋ชจ๋ ํ๋ซํผ์์ ๋ ๋๋ง๋์ด์ผ ํ๋ ํฐ์น๋ฅผ ์ฒ๋ฆฌํ๊ธฐ ์ํ ๊ธฐ๋ณธ ๋ฒํผ ๊ตฌ์ฑ ์์
- Switch: Boolean ์ ๋ ฅ์ ๋ ๋๋งํ๋ค
### ๐ List Views
- FlatList: ์คํฌ๋กค ๊ฐ๋ฅํ ๋ชฉ๋ก์ ๋ ๋๋งํ๋ ๊ตฌ์ฑ ์์
- SectionList: FlatList์ ์ ์ฌํ์ง๋ง Section ๋ชฉ๋ก์ ์ฌ์ฉ๋๋ค.
### ๐ Android Components and APIs
- BackHandler: ๋ค๋ก ํ์์ ์ํ ํ๋์จ์ด ๋ฒํผ ๋๋ฆ์ ๊ฐ์ง
- DrawerLayoutAndroid: DrawerLayoutAndroid์์ ๋ ๋๋งํ๋ค.
- PermissionsAndroid: Android M์ ๋์ ๋ ๊ถํ ๋ชจ๋ธ์ ๋ํ ์์ธ์ค๋ฅผ ์ ๊ณต
- ToastAndroid: Android Toast ์๋ฆผ์ ๋ง๋ ๋ค.
### ๐ iOS components and APIs
- ActionsSheetIOS: iOS ์์ ์ํธ๋ฅผ ํ์ํ๊ฑฐ๋ ์ํธ๋ฅผ ๊ณต์ ํ๋ API
### ๐ Others
- ActivityIndicator: ์ํ ๋ก๋ฉ ํ์๊ธฐ๋ฅผ ํ์ํ๋ค.
- Alert: ์ง์ ๋ ์ ๋ชฉ๊ณผ ๋ฉ์์ง๊ฐ ์๋ ๊ฒฝ๊ณ ๋ํ ์์๋ฅผ ์คํํ๋ค.
- Animated: ์ ๋๋ฉ์ด์ ์ ๋ง๋ค๊ธฐ ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ด๋ค.
- Dimensions: ์ฅ์น ํฌ๊ธฐ๋ฅผ ๊ฐ์ ธ์ค๊ธฐ ์ํ ์ธํฐํ์ด์ค๋ฅผ ์ ๊ณตํ๋ค.
- KeyboardAvoidingView: ๊ฐ์ ํค๋ณด๋์์ ์๋์ผ๋ก ๋ฒ์ด๋๋ ๋ณด๊ธฐ๋ฅผ ์ ๊ณตํ๋ค.
- Linking: ์์ ๋ฐ ๋ฐ์ ์ฑ ๋งํฌ์ ์ํธ ์์ฉํ ์ ์๋ ์ธํฐํ์ด์ค๋ฅผ ์ ๊ณตํ๋ค.
- Modal: Modal ์ฝํ ์ธ ๋ฅผ ํ์ํ๋ ๊ฐ๋จํ ๋ฐฉ๋ฒ์ ์ ๊ณตํ๋ค.
- PixelRatio: ์ฅ์น ํฝ์ ๋ฐ๋์ ๋ํ ์ก์ธ์ค๋ฅผ ์ ๊ณตํ๋ค.
- RefreshControl: ScrollView pull, refresh ๊ธฐ๋ฅ์ ์ถ๊ฐํ๋๋ฐ ์ฌ์ฉ๋๋ค.
- StatusBar: ์ฑ ์ํ ํ์ ์ค์ ์ ์ดํ๋ ๊ตฌ์ฑ์์์ด๋ค.
## ๐จ๐ปโ๐ป prop-types ๋ผ์ด๋ธ๋ฌ๋ฆฌ
- props๋ฅผ ์ ๋ฌ ํ ๋, ์๋ชป๋ ํ์ ์ ์ ๋ฌํ์ ๋ ๊ฒฝ๊ณ ๋ฉ์์ง๋ฅผ ๋ณด๋ด์ฃผ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ```javascript
MyButton.propTypes = {
//title์ string์ด์ฌ์ผ ํ๋ฉฐ, ํ์๋ก ์ ๋ ฅํด์ผ ํ๋ค.
//onPress๋ผ๋ ํจ์๊ฐ ํ์์ ์ผ๋ก ์ ๋ ฅํด์ผ ํ๋ค.
title: PropTypes.string.isRequired,
onPress: PropTypes.func.isRequired,
};```
## ๐จ๐ปโ๐ป JSX์์ if๋ฌธ ์ฌ์ฉ
- JSX๋ ์ฆ์ ์คํ ํจ์๋ก ์์ฑํด์ผ์ง if๋ฌธ์ ์ฌ์ฉํ ์ ์๋ค.```javascript
{(() => {
if(name === 'Minjae') return 'My name is Minjae';
else return 'My First React Native';
})()}
```
## ๐จ๐ปโ๐ป press ์ด๋ฒคํธ
- onPressIn: ํฐ์น๊ฐ ์์๋ ๋ ํธ์ถ
- onPressOut: ํฐ์น๊ฐ ํด์ฒด๋ ๋ ํธ์ถ
- onPress: ํฐ์น๊ฐ ํด์ฒด ๋ ๋ onPressOut ์ดํ ํธ์ถ
- onLongPress: ํฐ์น๊ฐ ์ผ์ ์๊ฐ ์ด์ ์ง์๋๋ฉด ํธ์ถ
```javascript
```## ๐จ๐ปโ๐ป change ์ด๋ฒคํธ
- ๋ณํ๋ฅผ ๊ฐ์งํ๋ change ์ด๋ฒคํธ๋ TextInput ์ปดํฌ๋ํธ์์ ๋ง์ด ์ฌ์ฉ๋๋ค.
- event๊ฐ์ฒด์ **nativeEvent.text** ๋ฅผ ์ฌ์ฉํด์ text ๊ฐ์ ์ ๋ฌํ ์ ์๋ค.
- onChangeText: ์ปดํฌ๋ํธ์ ํ ์คํธ๊ฐ ๋ณ๊ฒฝ๋ ๋, ๋ณ๊ฒฝ ๋ ํ ์คํธ์ ๋ฌธ์์ด๋ง ์ธ์๋ก ์ ๋ฌํ๋ฉฐ ํธ์ถ๋๋ค.
```javascript
const _onChange = e => {
setText(e.nativeEvent.text);
}const _onChangeText = text => {
setText(text);
}
```## ๐จ๐ปโ๐ป Pressable ์ปดํฌ๋ํธ
- ๊ธฐ์กด์ TouchableOpacity ์ปดํฌ๋ํธ๋ฅผ ๋์ฒดํ๋ Pressable ์ปดํฌ๋ํธ.
- HitReact: ๋ฒํผ ๋ชจ์๋ณด๋ค ์ฝ๊ฐ ๋จ์ด์ง ๋ถ๋ถ๊น์ง ์ด๋ฒคํธ๊ฐ ๋ฐ์ํ ์ ์๊ฒ ํด์ฃผ๋ pressable์ ๊ธฐ๋ฅ
- PressRect: ๋ฒํผ์ ๋๋ฅธ ์ํ์์ ์ผ๋ง๋ ๋ฉ์ด์ ธ์ผ ์ ํจ ๋ฒ์์์ ๋ฒ์ด๋ฌ๋ค๊ณ ํ๋จ ํ ์ ์๊ฒ ํ๋ ๊ธฐ๋ฅ
```javascript
import { Text, Pressable } from 'react-native';
{props.title}
```## ๐จ๐ปโ๐ป ํด๋์ค ์คํ์ผ๋ง(์ฌ๋ฌ๊ฐ ์คํ์ผ๋ง ์ ์ฉ)
- ํด๋์ค ์คํ์ผ๋ง์ ์ปดํฌ๋ํธ์ ํ๊ทธ์ ์ง์ ์ ๋ ฅํ๋ ๋ฐฉ์์ด ์๋, ์คํ์ผ์ํธ์ ์ ์๋ ์คํ์ผ์ ์ฌ์ฉํ๋ ๋ฐฉ์์ด๋ค.```javascript
//์ฌ๋ฌ๊ฐ์ ์คํ์ผ ์ ์ฉ1, ๋ค์ ์ค๋ ์คํ์ผ์ด ์์ ์๋ ์คํ์ผ์ ๋ฎ์
Class Style-Error//์ฌ๋ฌ๊ฐ์ ์คํ์ผ ์ ์ฉ2
Class Style-Text
```## ๐จ๐ปโ๐ป Platform
- Platform ๋ชจ๋์ ํตํด์ ๊ฐ ํ๋ซํผ๋ง๋ค ๋ค๋ฅธ ์ฝ๋๊ฐ ์ ์ฉ๋๋๋ก ์ฝ๋๋ฅผ ์์ฑํ ์ ์๋ค.
- iOS์์ shadow๋ shadowColor(์), shadowOffset(๊ฑฐ๋ฆฌ), shadowOpacity(๋ถํฌ๋ช ๋), shadowRadius(ํ๋ฆ ๋ฐ๊ฒฝ) ๋ฑ์ ์คํ์ผ ์์ฑ์ด ์กด์ฌํฉ๋๋ค.
- Android์์๋ elevation ์ด๋ผ๋ ์์ฑ์ด ์์ต๋๋ค.
```javascript
const styles = StyleSheet.create({
shadow: {
...Platform.select({
ios: {
shadowColor: '#000',
shadowOffset: {
width: 10,
height: 10,
},
shadowOpacity: 0.5,
shadowRadius: 10,
},
android: {
elevation: 20,
}
}),
},
});
```## ๐จ๐ปโ๐ป ์คํ์ผ๋ ์ปดํฌ๋ํธ(Styled-components) ๋ผ์ด๋ธ๋ฌ๋ฆฌ
๐ https://styled-components.com/### ๐ ๊ธฐ๋ณธ์ ์ธ Styled-components
- ๋ฆฌ์กํธ ๋ค์ดํฐ๋ธ์ ์คํ์ผ์์ ์น ํ๋ก๊ทธ๋๋ฐ๊ณผ์ ์ฐจ์ด๋ก ์ดํ ๋ถํธํจ์ ํด์์์ผ ์ฃผ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
- **styled.[์ปดํฌ๋ํธ ์ด๋ฆ]** ํํ ๋ค์ ๋ฐฑํฑ(`)์ ์ฌ์ฉํ์ฌ ๋ง๋ ๋ฌธ์์ด์ ๋ถ์ด๊ณ ๊ทธ ์์ ์คํ์ผ์ ์ง์ ํ๋ฉด ๋๋ค. ์ด๋ฌํ ๋ฌธ๋ฒ์ **ํ๊ทธ๋ ํ ํ๋ฆฟ ๋ฆฌํฐ๋ด(Tagged Template Literals)** ์ด๋ผ๊ณ ๋ถ๋ฅธ๋ค.```javascript
//์คํ์ผ ์ ์ฉ ์์
const Container = styled.View`
flex: 1;
background-color: #fff;
align-items: center;
justify-content: center;
`;
```### ๐ Styled-components์ props ์ฌ์ฉํ๊ธฐ
- Styled-components ์์๋ ์คํ์ผ์ ์์ฑํ๋ ๋ฒกํฐ ์์์ props์ ์ ๊ทผํ ์ ์๋ค๋ ์ฅ์ ์ด ์์ต๋๋ค. ์ด ์ฅ์ ์ ์ด์ฉํด ์คํ์ผ์ ์์ฑํ๋ ๊ณณ์์ ์กฐ๊ฑด์ ๋ฐ๋ผ ์คํ์ผ์ ๋ณ๊ฒฝํ ์ ์์ต๋๋ค.
```javascript
const ButtonContainer = styled.TouchableOpacity`
background-color: ${props => props.title === 'Minjae' ? '#3498db' : '#9b59b6'};
border-radius: 15px;
padding: 15px 40px;
margin: 10px 0px;
justify-content: center;
`;const Button = ({ title }) => {
return (
{title}
);
};
```### ๐ Styled-components์ attrs ์ฌ์ฉํ๊ธฐ
- attrs๋ Styled-components์์ ์์ฑ์ ์ค์ ํ ๋ ์ฌ์ฉํ๋ค.
```javascript
//components/Input.js
const StyledInput = styled.TextInput.attrs(props => ({
placeholder: 'Enter a text...',
placeholderTextColor: props.borderColor,
}))`
(...)
border-color: ${props => props.borderColor};
`;const Input = ({borderColor}) => {
return (
)
}//App.js
```