2017-02-08 2 views
1

ネイティブベースのバージョン2.0.2、反応ネイティブバージョン0.40.0を使用しています。ネイティブベースのローディング要素

ネイティブベースの&を使用してGithubリポジトリ検索を作成するためのチュートリアルに従っていますが、それを自分の機能と統合して別のものを作りますが、すべてのコンポーネントが正しく読み込まれません。 The Header &ドキュメントのフッターの例がうまくいきましたが、検索バーの丸みを帯びたプロパティやアイコンクラスのようなものを追加すると、反映されません。

ボタンコンポーネントを追加すると、次のエラーが発生します。問題の

image

コードは

var constants = require("../constants") 

var React = require('react'); 
var ReactNative = require('react-native'); 
var t = require('tcomb-form-native'); 

var authenticate = require("../services/authenticate") 

import { Container, Header, Title, Content, Footer, FooterTab, Button, Left, Right, Body,Picker,InputGroup,Icon,Input,Item } from 'native-base'; 

var { 
    AppRegistry, 
    AsyncStorage, 
    StyleSheet, 
    Text, 
    View, 
    TouchableHighlight, 
    Alert, 
    ListView, 
    Image, 
} = ReactNative; 

var Form = t.form.Form; 
var getFeatured = require("../services/get_featured"); 
var getCategory = require("../services/get_categories"); 
var search = require("../services/search"); 

var Query; 


const options = { 
    fields: { 
     category: { 
      order: 'asc', 
      nullOption: {value: '', text: 'Anything'} 
     } 
    } 
} 

class SplashPage extends React.Component{ 

    constructor() { 
    super(); 
    this.set_initial_state() 
    //this.set_categories(); 
    //this.get_featured(); 
    } 

    set_initial_state(){ 
     this.state ={ 
      hasResult: false, 
      hasCategory:false, 
      noResult: false, 
      isLoading: true, 
      isLoadingCat:true, 
      searchResult:false, 
      categories : [], 
      searchText:"", 
      searchCat:"", 
      filterCat:"", 
      articles:[], 
     } 
    } 

    set_categories() { 
    var par = this; 
    getCategory().then(function(catData){ 
     par.setState({ 
     isLoadingCat:false, 
     hasCategory:true, 
     categories:catData, 
     }); 

     console.error("till here"); 

    }); 

    } 

    get_categories(){ 
    const cats = this.state.categories; 
    const CatItems = cats.map((cat,i)=>{ 
     return (
     <Picker.item key={i} label={cat} value={cat} /> 
    ); 
    }); 
    return CatItems; 

    } 

    openRecipe(data){ 
    this.props.navigator.push({ 
     id: 'RecipePage', 
     name: 'Recipe',  
     recipe_id:data.id, 
    }); 
    } 

    get_featured(){ 
    var par = this; 
    getFeatured().then(function(articles){ 
     par.setState(
      { 
       articles:articles, 
       hasResult: true, 
       isLoading:false, 
       searchResult:false, 
      } 
     ) 
    }).catch(function(error) { 
     console.error(error); 
    }); 

    } 

    perform_search(){ 
    var value = this.state.searchText; 
    var par = this; 
    if(value){ 
     par.setState(
      { 
       hasResult: false, 
       isLoading:true, 
      } 
     ) 

     var category = value.category; 
     var ingredient = value.ingredient.toString().split(',').join(' '); 
     search(ingredient,category).then((articles) => { 
     par.setState(
      { 
       articles:articles, 
       hasResult: true, 
       isLoading:false, 
       searchResult:true 
      } 
     ) 
     }).catch(function(error) { 
     console.error(error); 
     }); 

     } 
    } 

    render() { 

    return (

     <Header searchBar rounded>        
    <InputGroup>       
     <Icon name="ios-search" />       
     <Input placeholder="Search" value={this.state.searchText} onChangeText={(text) => this.setState({searchText:text})} onSubmitEditing={()=>this.search()}/> 
     <Picker 
         iosHeader="Select one" 
         mode="dropdown" 
         selectedValue={this.state.searchCat} 
         onValueChange={(cat) => this.setState({searchCat:cat})}> 

         <Item label="Cats" value="key0" /> 
         <Item label="Cats2" value="key02" /> 

     </Picker> 
    </InputGroup>      
    <Button transparent onPress={()=>this.search()}>Go</Button>     
</Header> 


    ); 
    } 
} 

module.exports = SplashPage; 

私は依存関係をチェックし、すべてのものがインストールされています。

答えて

2

私は私がonPressであなたのButtonで考える間違った何かがありますあなたが

<Container> 
    <Content> 
     // your code 
     <Button> 
     <Text>Click Me! </Text> 
     </Button> 
    </Content> 
</Container> 
0

でコードをラップするべきだと思います。 あなたのコードはonPress={()=>this.search()} ですが、私はsearch()方法が表示されていない、あなたの問題はあなたが<Button>タグを追加した後、あなたはこの1つ変更することができてきた場合、私はちょうどperform_search()方法

を見つける:この1に

<Button transparent onPress={()=>this.search()}>Go</Button> 

を:

<Button transparent onPress={()=>this.perform_search()}><Text>Go</Text></Button> 

も、この1:onSubmitEditing={()=>this.search()}

これと

onSubmitEditing={()=>this.perform_search()}

native-baseTextをインポートすることを忘れないでください、希望はあなたの問題を解決することができます:)

関連する問題