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

Native開発者から見たReactNative

 Native開発者から見たReactNative

at Gunosy React Meetup

y_matsuwitter

March 31, 2015
Tweet

More Decks by y_matsuwitter

Other Decks in Programming

Transcript

  1. ֤छϞδϡʔϧͷϩʔυ 'use strict'; var React = require('react-native'); var { AppRegistry,

    // ΞϓϦͷىಈϙΠϯτ StyleSheet, // ֤ཁૉͷελΠϧ Text, // ςΩετϥϕϧ View, // View ListView, // Ϧετ Image, // ը૾View NavigatorIOS, // iOSͷUINavigationController TouchableWithoutFeedback, //λονΠϕϯτͷऔಘ WebView // WebView } = React; var QIITA_URL = "https://qiita.com/api/v2/tags/reactjs/items";
  2. φϏήʔγϣϯͷఆٛ • ΞϓϦ͕࠷ॳʹىಈ͢ΔViewControllerͱͯ͠ࠓճ͸Naviga0on Λ࢖ͬͨ // ϕʔεͷUINavigationControllerʹ֘౰͢Δ΋ͷ var ReactQiitaNavigator = React.createClass({

    render: function() { return ( <NavigatorIOS style={styles.navigator} initialRoute={{ component: ReactQiitaList, title: 'ReactQiita', }}/> ); } })
  3. Listදࣔ:&ॳظԽ // هࣄҰཡϦετ var ReactQiitaList = React.createClass({ getInitialState: function() {

    return { items: new ListView.DataSource({ rowHasChanged: (row1, row2) => row1 !== row2, }), loaded: false, }; }, componentDidMount: function() { this.fetchData(); //σʔλͷऔಘʢޙड़ʣ },
  4. ListView:)શମඳը render: function() { if (!this.state.loaded) { // ಡΈࠐΈϏϡʔͷඳըʢࠓճ͸આ໌লུʣ return

    this.renderLoadingView(); } return ( <ListView dataSource={this.state.items} renderRow={this.renderItem} //֤ߦͷඳըϝιουΛࢦఆ style={styles.listView}/> ); },
  5. ListView:)ߦͷඳը ஫:"TouchableWithoutFeedback͸̎ͭҎ্ͷࢠΛ௚Լʹ࣋ͯͳ͍ renderLoadingView: function() { /*লུ*/ }, renderItem: function(item, sectionID,

    rowID) { return ( <TouchableWithoutFeedback onPress={() => this.onPressed(item)}> // Πϕϯτݕ஌ <View style={styles.container}> <Image source={{uri: item.user.profile_image_url}} style={styles.thumbnail}/> <View style={styles.rightContainer}> <Text style={styles.title}>{item.title}</Text> <Text style={styles.name}>{item.user.id}</Text> </View> </View> </TouchableWithoutFeedback> ); },
  6. ελΠϧͷهड़ // ֤छσβΠϯཁૉɺҰ෦ൈਮ var styles = StyleSheet.create({ navigator: { flex:

    1 }, container: { flex: 1, flexDirection: 'row', justifyContent: 'center', alignItems: 'center', backgroundColor: '#FFFFFF', }, }