TaeHee Kim
Software Engineer / Bassist
로토
웹 개발자가 시도해본
스마트스터디
앱 개발에 숟가락 얹을 수 있겠는데..?
개발자의 욕심은 끝이 없고
같은 코딩을 반복한다
Bridge
Native Code
JS Runtime Environment
React Native Code
iOS or Android OS
React Native Build
node.js 로 컴파일 및 js bundle publish
Node Server
127.0.0.1:8001/index.platform.bundle.js
JS Runtime
iOS or Android Native Project
Native Project의 JS Runtime에서는
publish된 JS Bundle을 참조
npm install -g react-native
react-native init HelloRN
cd HelloRN
react-native run-ios // ios
react-native run-android // android
mac + iOS는 쉽게 시작 할 수 있음
mac + Android는 Android SDK setting 필요
windows 에선 Android 개발만 가능
다시 컴파일 할 필요가 없다!
UI를 빠르게 개발할 수 있다!
import { Platform, View, Text } from 'react-native';
const Panel = () => (
<View style={{paddingTop: Platform.OS === 'ios' ? 20 : 0}}>
<Text>SmartStudy!</Text>
</View>
);
Platform module의 OS 파라메터 이용
// app/Hello/index.ios.js
const Hello = () => (
<View style={{paddingTop:20}}>
<Text>안녕?iOS!!</Text>
</View>
);
export default Hello;
// app/Hello/index.android.js
const Hello = () => (
<View>
<Text>안녕?안드로이드!!</Text>
</View>
);
export default Hello;
index.{platform}.js
// platform에 따라 index.js가 로딩됨
import Hello from './app/Hello';
const App = () => (
<View>
<Hello />
</View>
);
export App;
App.js
public class ToastModule extends ReactContextBaseJavaModule{
private static final String DURATION_SHORT_KEY = "SHORT";
private static final String DURATION_LONG_KEY = "LONG";
public ToastModule(ReactApplicationContext reactContext) {
super(reactContext);
}
@Override
public String getName() {
return "ToastExample";
}
@Override
public Map<String, Object> getConstants() {
final Map<String, Object> constants = new HashMap<>();
constants.put(DURATION_SHORT_KEY, Toast.LENGTH_SHORT);
constants.put(DURATION_LONG_KEY, Toast.LENGTH_LONG);
return constants;
}
@ReactMethod
public void show(String message, int duration) {
Toast.makeText(getReactApplicationContext(), "NATIVE MESSAGE : " + message, duration).show();
}
}
public class ToastModulePackage implements ReactPackage{
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
modules.add(new ToastModule(reactContext));
return modules;
}
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new ToastModulePackage()
);
}
import React from 'react';
import { View, Text, Button, NativeModules } from 'react-native';
const { ToastExample } = NativeModules;
const Hello = () => (
<View>
<Text>안녕?안드로이드!!</Text>
<Button text="누질러봐" onPress={() => ToastExample.show('눌렀니?', ToastExample.LONG)} />
</View>
);
export default Hello;
// code push cli install
npm install -g code-push-cli
// register
// 브라우저가 열리며 계정을 연동하는 과정을 거침
// 계정 연동 후 발급된 토큰을 console에 붙여넣음
code-push register
// 앱 등록
// code-push app add <ProjectName> <Platform> react-native
code-push app add HelloRN android react-native
// 앱에 code-push 모듈 설치
npm install --save react-native-code-push@latest
react-native link react-native-code-push
code-push release-react HelloRN android
By TaeHee Kim
react-native에 대한 간략한 설명과 웹 개발자 시점으로 시도해본 react-native에 대한 짤막한 회고