Upgrade to Pro — share decks privately, control downloads, hide ads and more …

React Nativeを触ってみた話

React Nativeを触ってみた話

Yuta Hiroto

October 10, 2015
Tweet

More Decks by Yuta Hiroto

Other Decks in Programming

Transcript

  1.  DSFBUFHJUJHOPSF DSFBUFXBUDINBODPOpH DSFBUFJOEFYJPTKT DSFBUFJOEFYBOESPJEKT DSFBUFJPTNBJOKTCVOEMF DSFBUFJPTBMU1SPKFDU"QQ%FMFHBUFI DSFBUFJPTBMU1SPKFDU"QQ%FMFHBUFN DSFBUFJPTBMU1SPKFDU#BTFMQSPK-BVODI4DSFFOYJC DSFBUFJPTBMU1SPKFDU*NBHFTYDBTTFUT"QQ*DPOBQQJDPOTFU$POUFOUTKTPO

    DSFBUFJPTBMU1SPKFDU*OGPQMJTU DSFBUFJPTBMU1SPKFDUNBJON DSFBUFJPTBMU1SPKFDU5FTUTBMU1SPKFDU5FTUTN DSFBUFJPTBMU1SPKFDU5FTUT*OGPQMJTU DSFBUFJPTBMU1SPKFDUYDPEFQSPKQSPKFDUQCYQSPK DSFBUFJPTBMU1SPKFDUYDPEFQSPKYDTIBSFEEBUBYDTDIFNFTBMU1SPKFDUYDTDIFNF DSFBUFBOESPJEBQQCVJMEHSBEMF DSFBUFBOESPJEBQQQSPHVBSESVMFTQSP DSFBUFBOESPJEBQQTSDNBJO"OESPJE.BOJGFTUYNM DSFBUFBOESPJEBQQTSDNBJOSFTWBMVFTTUSJOHTYNM DSFBUFBOESPJEBQQTSDNBJOSFTWBMVFTTUZMFTYNM DSFBUFBOESPJECVJMEHSBEMF DSFBUFBOESPJEHSBEMFQSPQFSUJFT DSFBUFBOESPJETFUUJOHTHSBEMF DSFBUFBOESPJEBQQTSDNBJOSFTNJQNBQIEQJJD@MBVODIFSQOH DSFBUFBOESPJEBQQTSDNBJOSFTNJQNBQNEQJJD@MBVODIFSQOH DSFBUFBOESPJEBQQTSDNBJOSFTNJQNBQYIEQJJD@MBVODIFSQOH DSFBUFBOESPJEBQQTSDNBJOSFTNJQNBQYYIEQJJD@MBVODIFSQOH DSFBUFBOESPJEHSBEMFXSBQQFSHSBEMFXSBQQFSKBS DSFBUFBOESPJEHSBEMFXSBQQFSHSBEMFXSBQQFSQSPQFSUJFT DSFBUFBOESPJEHSBEMFX DSFBUFBOESPJEHSBEMFXCBU DSFBUFBOESPJEBQQTSDNBJOKBWBDPNBMUQSPKFDU.BJO"DUJWJUZKBWB iOSͱAndroid༻ͷ
 ςϯϓϨʔτ͕ੜ੒͞ΕΔ Android͸9݄15೔ʹରԠ͞Εͨ
  2. var React = require('react-native'); var { TabBarIOS, NavigatorIOS } =

    React; var App = React.createClass({ render: function() { return ( <TabBarIOS> <TabBarIOS.Item title="React Native" selected={true}> <NavigatorIOS initialRoute={{ title: 'React Native' }} /> </TabBarIOS.Item> </TabBarIOS> ); }, });  var React = require('react-native'); var { DrawerLayoutAndroid, ProgressBarAndroid } = React; var App = React.createClass({ render: function() { return ( <DrawerLayoutAndroid renderNavigationView={() => <Text>React Native</Text>}> <ProgressBarAndroid /> </DrawerLayoutAndroid> ); }, }); iOS Android ಉ͡ίʔυͰ̎ͭΛΧόʔ͢Δͷ͸೉ͦ͠͏ɻɻɻ
  3. ඪ४ίϯϙʔωϯτͷಡΈࠐΈ var { AppRegistry, StyleSheet, Text, View, } = React;

     React Native͕࢖༻͢Δ
 σϑΥϧτͳίϯϙʔωϯτ
  4. viewͷߏங  var altProject = React.createClass({ render: function() { return

    ( <View style={styles.container}> <Text style={styles.welcome}> Welcome to React Native! </Text> <Text style={styles.instructions}> To get started, edit index.ios.js </Text> <Text style={styles.instructions}> Press Cmd+R to reload,{'\n'} Cmd+D or shake for dev menu </Text> </View> ); } });
  5. styleͷߏங var styles = StyleSheet.create({ container: { flex: 1, justifyContent:

    'center', alignItems: 'center', backgroundColor: '#F5FCFF', }, welcome: { fontSize: 20, textAlign: 'center', margin: 10, }, instructions: { textAlign: 'center', color: '#333333', marginBottom: 5, }, });  iOS ͷ UI ίϯϙʔωϯτ͸ 
 CSS ͷελΠϧઃఆʹରԠ͠ͳ͍ͨΊɺ
 react nativeͷಠࣗίϯϙʔωϯτͰ࣮૷͠·͢
  6. σʔλͷऔಘ fetchData: function() { fetch(REQUEST_URL) .then((response) => response.json()) .then((responseData) =>

    { this.setState({ dataSource: this.state.dataSource.cloneWithRows(responseData), loaded: true, }); }) .done(); }, 
  7. React Native • React Native ͸ JavaScriptCoreΛ࢖༻͢Δ • ผεϨουͰJavaScriptCoreΛ࢖͍
 React

    NativeͰॻ͍ͨίʔυΛಡΈࠐ·ͤΔ • Titaniumͱಉ༷ʹωΠςΟϒ΁ͷඇಉظϒ Ϧοδ͕ଘࡏ͢Δ(͜͜ͰUIKitͱ઀ଓ͢Δ) 
  8. React Native • React.js ͱಉ͡ཁྖͰॻ͘͜ͱ͕Ͱ͖Δ • ES6Ͱॻ͘͜ͱ͕Մೳ • Polyfill͕͋ΔͷͰnpmϞδϡʔϧ͸࢖͑Δ •

    UIKitΛ஌ͬͯͳ͍ͱͭΒ͍ײ͋͡Δ • TitaniumΛ΍ΔΑΓ΋࣮֬ʹֶशίετ͕௿͍