react-native app 만들기
brwe 설치 후 node와 watchman 설치
brew install nodebrew install watchman
react-native-cli 설치
npm install -g react-native-cli
설치법 및 ios 실행법
react-native install project-Namereact-native run-ios
react-native 역시 react 와 마찬가지로 컴포넌트 단위로 뷰를 짜주어야한다.
오직 root 컴포넌트만 AppRegistry를 사용할 수 있다.
기본 프레임
// index.ios.js - place ode in here for ios// import a library to help create a component;;;;// 컴포넌트를 만들자//OLD// const App = () =>{// return(// <Text>Some Text</Text>// );// };//Newconst App =//다이렉트 선언도 가능//flex:1은 화면 전체를 뜻합니다.<View style=flex:1>//헤더와 AlbumList를 가져와 뷰에 쀼러줍니다.<Header headerText="Albums" /><AlbumList /></View>;//render it to device//앨범에다가 App을 실행해 !//albums와 project이름을 일치시켜야한다. 그 후 렌더링할 method 이름을 선언하여준다.AppRegistry;
헤더만들기
header.js
// Import Libraries for making a component;//뷰는 포지션과 스타일을 관장한다. div 같은 느낌;// make a compontnt//props = property ,data rendring 등의 용도로 활용const Header = {const textStyle viewStyle = styles;return<View style=viewStyle><Text style=textStyle>propsheaderText</Text></View>};//스타일을 아래와 같이 선언한다.const styles =viewStyle:backgroundColor:'#f8f8f8'//가운데정렬justifyContent: 'center'//중앙정렬alignItems:'center'height:60//맨 위 간격을 만들어 모바일의 시간 부분을 가리지 않도록paddingTop:15shadowColor: '#000'shadowOffset:width:0 height:2shadowOpacity: 02elevation:2position:'relative'textStyle:fontSize: 20}//당장 렌더를 언하지 않을수도 있기에 일단은 쪼개어 놓는다.//make the compontnt able to other paort of the app;
리스트 화면
// Import Libraries for making a component;//뷰는 포지션과 스타일을 관장한다. div 같은 느낌;;;// make a compontnt//컴포넌트도 가져오야합니다.// import component//class based componentstate = albums: ;{// ASYNC HTTP Request to get albums from the API.// eslint-disable-next-lineaxios;}{//map is array helper//array 개수만큼 실행되게 됩니다.//albums가 들어간 만큼 title이 출력됩니다.//대소문자 구분return thisstatealbums;}{console;return<ScrollView>this</ScrollView>;};};;
디테일 화면
;;;;const AlbumDetail = {const titleartistthumbnail_imageimage url = album;constthumbnailStylethumbnailContainerStyleheaderContentStyleheaderTextStyleimageStyle} = styles;return<Card><CardSection><View style=thumbnailContainerStyle><Imagestyle=thumbnailStylesource=uri: thumbnail_image/></View><View style=headerContentStyle><Text style=headerTextStyle>title</Text><Text>artist</Text></View></CardSection><CardSection><Imagestyle=imageStylesource=uri:image/></CardSection><CardSection><Button onPress=Linking>buy it</Button></CardSection></Card>};const styles =headerContentStyle:flexDirection:'column'justifyContent:'space-around'thumbnailStyle:height:50width:50headerTextStyle:fontSize:18thumbnailContainerStyle:justifyContent:'center'alignItems:'center'marginLeft:10marginRight:10imageStyle:height:300flex:1width:null;;
card.js
;;const Card = {return<View style=stylescontainerStyle>/*하위 내용 보여주기*/propschildren</View>;};const styles=containerStyle:borderWidth:1borderRadius:2borderColor:'#ddd'borderBottomWidth:0shadowColor:'#000'shadowOffset:width:0 height:2shadowOpacity:01shadowRadius:2elevation:1marginLeft:5marginRight:5marginTop:10};
cardsection.js
;;//카드 섹션은 단지 데코를 위한 내용const CardSection = {return<View style=stylecontainerStyle>propschildren</View>;};const style=containerStyle:borderBottomWidth:1padding:5backgroundColor:'#fff'justifyContent:'flex-start'//one line by onelineflexDirection:'row'borderColor: '#ddd'position: 'relative'};