2017-07-07 193 views
0

在我的渲染函數中,我提出了一個請求,所以加載時會顯示'loading'。接收到數據後,我調用'setState'使DOM重新渲染。我想展示模態,但模態不存在。我怎麼了?React-Native Modal在Dom渲染時不顯示

render: function() { 

    if (!this.props.data) { 
      return (<View style={{flex:1}}> 
        <Text>loading</Text> 
       </View>); 
    } 
    return (
     <View style={{flex:1, width:screenWidth}}> 
     <Modal 
       visible={true} 
       transparent={true} 
       onRequestClose={()=>{ 
       }} 
       onShow={()=>{ 
       }}> 
       <View 
        style={{flex:1,justifyContent:'center',alignItems:'center',backgroundColor:'rgba(0, 0, 0, 0.3)'}}> 
        <View style={{height:200,width:275,backgroundColor:'white'}}> 
         <Button title='confirm' onPress={()=>{}}/> 
         <Button title='cancel' onPress={()=>{}}/> 
        </View> 
       </View> 
      </Modal> 
     </View> 
    ); 
} 

回答

0

你可以像單迴路檢查條件:

render(){ 
    return(
     {(!this.props.data) 
     ? (<View style={{flex:1}}> 
       <Text>loading</Text> 
      </View>) 
     : (<View style={{flex:1, width:screenWidth}}> 
      <Modal/> { /*your modal code */} 
     </View>) 
     } 
    ); 
} 

首先檢查你的模式沒有條件的打開與否,如果是,則是風格還是重新撕心裂肺的問題。

+0

@Eric你有沒有修好? –

+0

我收到了一個錯誤,'意外的令牌'。也許'?:'不能在返回函數中使用? – Eric

+0

你可以請顯示該代碼嗎? –