사진 크기를 조정한 마크다운이 적용이 안돼 가독성이 최악이다...
깃헙에 잘 정리되어있다!
// npm보다 가볍고 빠르게 자바스크립트 패키지 관리 자바스크립트 패키지 매니저 툴
npm install -g yarn
sudo npm install -g expo-cli
// npm : 노트 패키지 매니저 명령 실행
// -g : 컴퓨터 전역적 설치
// expo-cli : 설치할 패키지 이름
expo login --username "Expo 사이트 가입당시 입력 name"
패스워드 입력
expo init 폴더명
blank 타입 앱 선택
cd 폴더명
expo start (Expo 서버 On) <> command + c (Expo 서버 Off)
시뮬레이터 : 가상의 휴대폰을 컴퓨터에 띄워놓는 것
expo start --android
expo start --ios
assets : 앱이 동작되고 서비스되는데에 기본적으로 가지고 있는 이미지 및 아이콘 파일을 담는 폴더
node_modules : 라이브러리 저장 장소
App.js : 리액트 네이티브 앱이 시작되는 출발선 및 진입점
app.json : 앱의 이름, 출시 버전, 아이콘, 스플래시 스크린, 광고 설정 등 앱이 가지는 기본 정보 설정 파일
// 리액트, 리액트 네이티브, 엑스포 라이브러리에서 꺼내 사용할 기능들을
// 이렇게 앞으로도 상단에 선언한다음 가져다 사용
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
// App.js는 App 함수를 내보내기 하고 있는 자바스크립트 파일
// 이 함수는 무언가?를 반환하고 있는데 결국 화면을 반환
export default function App() {
// 화면을 반환
// HTML 태그 같이 생긴 이 문법은 JSX라 불리우며 실제 화면을 그리는 문법
// 경고창 없애기
console.disableYellowBox = true;
return (
<View style={styles.container}>
<Text>Open up App.js to start working on your app!</Text>
<StatusBar style="auto" />
</View>
);
}
// styles 변수 이름 답게 화면을 그려주는, JSX문법을 꾸며주는 내용
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
export default function App() {
return (
<View style={styles.container}>
<Text>Open up App.js to start working on your app!</Text>
<StatusBar style="auto" />
</View>
);
}
export default function App() {
return (
//<View>는 결국 두번째 줄 밑에 </View>로 닫히면서 본인 영역을 갖는다
<View style={styles.container}>
<Text>Open up App.js to start working on your app!</Text>
//statusBar는 본인 스스로 닫는 태그이므로 다음과 같이 사용이 가능합니다.
<StatusBar style="auto" />
</View>
);
}
//App.js가 렌더링 하고 엘리먼트는 결국
//Text와 StatusBar엘리먼트를 감싸고 있는 View
export default function App() {
return (
<View style={styles.container}>
<Text>Open up App.js to start working on your app!</Text>
<StatusBar style="auto" />
</View>
);
}
//JSX밖에서의 주석
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
//JSX밖에서의 주석
export default function App() {
//JSX밖에서의 주석
return (
//JSX 밖에서의 주석
<View style={styles.container}>
{/*
JSX 문법 안에서의 주석
*/}
<Text>Open up App.js to start working on your app!</Text>
<StatusBar style="auto" />
</View>
);
}
View
화면의 영역(레이아웃)을 잡아주는 엘리먼트
View 엘리먼트로 원하는 대로 화면 분할 가능 (StyleSheet와 같이 사용)
Text
앱에 글을 작성하기 위해 사용하는 엘리먼트
ScrollView
앱 화면을 벗어나는 영역의 경우 ScrollView 엘리먼트로 감싸면 스크롤이 가능
import React from 'react';
import { ScrollView, StyleSheet, Text, View } from 'react-native';
export default function App() {
console.disableYellowBox = true;
return (
<ScrollView style={styles.container}>
<View style={styles.textContainer}>
<Text style={styles.textStyle}>Text Container</Text>
</View>
...
</ScrollView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
},
textContainer: {
height:100,
borderColor:'#000',
borderWidth:1,
borderRadius:10,
margin:10
},
textStyle: {
textAlign:"center"
}
});
Button
onPress속성에 함수 연결(바인딩)
연결한 함수 구현부를 JSX 밖에서 구현하여 바인딩 가능
TouchableOpacity
임의의 영역과 디자인에 버튼 기능을 달고 싶을 때 주로 사용
Image
이미지 삽입 방식 2가지
1. assets 폴더의 이미지를 가져오기 {import}
2. 외부 이미지 링크 넣기 {url}
import React from 'react';
import { Alert, Button, ScrollView, StyleSheet, Text, TouchableOpacity, Image, View } from 'react-native';
import favicon from "./assets/favicon.png"
export default function App() {
console.disableYellowBox = true;
const customAlert = () => {
Alert.alert("outside of JSX function")
}
return (
<ScrollView style={styles.container}>
<View style={styles.textContainer}>
<Text style={styles.textStyle}>Text Container</Text>
<Button
style={styles.buttonStyle}
title="Button"
color="#FFAA4C"
onPress={function(){
Alert.alert('popup alert')
}}
/>
<Button
style={styles.buttonStyle}
title="Button"
color="#5089C6"
onPress={()=>{
Alert.alert('popup alert')
}}
/>
<Button
style={styles.buttonStyle}
title="Button"
color="#B980F0"
onPress={() => {customAlert()}}
/>
<Button
style={styles.buttonStyle}
title="Button"
color="#F8E2CF"
onPress={customAlert}
/>
</View>
<TouchableOpacity
style={styles.textContainer}
onPress={customAlert}>
<Text style={styles.textStyle}>Text</Text>
</TouchableOpacity>
<View style={styles.textContainer}>
<Image
source={favicon}
resizeMode={"repeat"}
style={styles.imageStyle}
/>
</View>
<View style={styles.textContainer}>
<Image
source={{uri:'https://user-images.githubusercontent.com/60697742/127253669-56304aa4-b412-4312-9b9a-95d9d9118fcc.jpg'}}
resizeMode={"cover"}
style={styles.imageStyle}
/>
</View>
</ScrollView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
},
textContainer: {
height:180,
borderColor:'#000',
borderWidth:1,
borderRadius:10,
margin:50
},
textStyle: {
textAlign:"center"
},
imageStyle: {
width:"100%",
height:"100%",
alignItems:"center",
justifyContent:"center"
}
});
styles 속성에 styles 객체 container 키 연결
<View style={styles.container}>
StyleSheet 문법
const styles = StyleSheet.create({
container: {
//영역을 잡는 속성입니다. 따로 자세히 다룹니다.
//flex: 1은 전체 화면을 가져간다는 뜻입니다
flex: 1,
//영역의 배경 색을 결정합니다
backgroundColor: '#fff',
//아래 두 속성은 영역 안의 컨텐츠들의 배치를 결정합니다.
//flex를 자세히 다룰때 같이 자세히 다룹니다
justifyContent:"center",
alignContent:"center"
},
textContainer: {
//영역의 바깥 공간 이격을 뜻합니다(하단 이미지 참조)
margin:10,
//영역 안의 컨텐츠 이격 공간을 뜻합니다(하단 이미지 참조)
padding: 10,
//테두리의 구부러짐을 결정합니다. 지금 보면 조금 둥글죠?
borderRadius:10,
//테두리의 두께를 결정합니다
borderWidth:2,
//테두리 색을 결정합니다
borderColor:"#000",
//테구리 스타일을 결정합니다. 실선은 solid 입니다
borderStyle:"dotted",
},
textStyle: {
//글자 색을 결정합니다. rgb, 값 이름, 색상코드 모두 가능합니다
color:"red",
//글자의 크기를 결정합니다
fontSize:20,
//글자의 두께를 결정합니다
fontWeight:"700",
//가로기준으로 글자의 위치를 결정합니다
textAlign:"center"
}
});
flex : 영역을 차지하는 속성. 위치한 곳의 영역을 flex 합 비율대로 가져간다.
flexDirection : 자리잡은 영역의 방향
justifyContent : flexDirection과 동일한 방향으로 정렬하는 속성
column row
center flex-end space-around
flex-start space-between
row-space-around row-space-between
alignItems : Flex Direction과 수작 방향(반대 방향)으로 정렬
flexDirection을 column으로 했을 때 alignItems는 반대 축 row 기준으로 정렬
strech 속성은 해당 축의 크기를 지정하지 않으면 자동으로 영역 전체 차지
center flex flex-start flex-end
stretch-column stretch-row
기본 함수 골격
export default function App() {
console.disableYellowBox = true;
//return 구문 밖에서는 슬래시 두개 방식으로 주석
return ()
}
const styles = StyleSheet.create({})
라이브러리 임포트
import React from 'react';
import main from './assets/main.png';
import { StyleSheet, Text, View, Image, TouchableOpacity, ScrollView} from 'react-native';
<View style={styles.textContainer1}>
{
tip.map((content, i) => {
return (
<View style={styles.textContainer2} key={i}>
<Image style={styles.cardImage} source={{url:content.image}} />
<View style={styles.cardText}>
<Text style={styles.cardTitle}>{content.title}</Text>
<Text style={styles.cardDescription} numberOfLines={3}>{content.desc}</Text>
<Text style={styles.cardDate}>{content.date}</Text>
</View>
</View>
)
})
}
</View>
<View style={styles.textContainer1}>
{
tip.map((content, i) => {
return i % 2 == 0 ? (
<View style={styles.textContainer2} key={i}>
<Image style={styles.cardImage} source={{url:content.image}} />
<View style={styles.cardText}>
<Text style={styles.cardTitle}>{content.title}</Text>
<Text style={styles.cardDescription} numberOfLines={3}>{content.desc}</Text>
<Text style={styles.cardDate}>{content.date}</Text>
</View>
</View>
) : (
<View style={styles.textContainer3} key={i}>
<Image style={styles.cardImage} source={{url:content.image}} />
<View style={styles.cardText}>
<Text style={styles.cardTitle}>{content.title}</Text>
<Text style={styles.cardDescription} numberOfLines={3}>{content.desc}</Text>
<Text style={styles.cardDate}>{content.date}</Text>
</View>
</View>
)
})
}
</View>