這裏是我的代碼。我現在用爲APIComponentwillMount功能,然後使用isLoading變量,並相應地顯示特定視圖。 但其不工作 ...它似乎是我做錯了,請了一眼,幫我出我的新反應 - 本地陣營母語:列表視圖前顯示加載屏幕如何填充
const UserPage = React.createClass({
getInitialState() {
return {
dataSource: dataSource.cloneWithRows(dataList),
isLoading:true
}
},
componentWillMount() {
SharedPreferences.getItem("sender_id", (value) => {
let user_id = value;
let url = "BaseURL/fetchSendTokens?user_id="+user_id;
fetch(url, {
method: "GET",
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
},
})
.then((response) => response.json())
.then((responseData) => {
if (responseData.responsecode === 1) {
dataList = responseData.data;
this.setState = ({
dataSource: this.state.dataSource.cloneWithRows(dataList),
isLoading:false,
})
}
else {
ToastAndroid.show('Please try again...', ToastAndroid.SHORT);
}
})
.catch(e => {
ToastAndroid.show('Please try again...', ToastAndroid.SHORT);
})
.done();
});
},
renderRow(rowData, sectionID,){
let currentView = (rowData.visitor_profileImageUrl)?
<Image
source={{uri:rowData.visitor_profileImageUrl}}
style={{height:40,width:40,margin:15,borderRadius:100}}
resizeMode="contain"/> :
<Image
source={userprofilepic}
style={{height:40,width:40,margin:15,borderRadius:100}}
resizeMode="contain"/>;
return <View key={ sectionID }>
<View style={{ flex: 1,height:70,flexDirection: 'row'}}>
<View>
{currentView}
</View>
<Text style={{fontSize : 18,marginTop:15,marginLeft:20,color:"black"}} >{ rowData.visitor_name }</Text>
</View>
</View>
},
render() {
let loadingGif = "URL-loading.gif";
let currentView = (this.state.isLoading)?<View style={styles.background}>
<View style={styles.markWrap}>
<Image source={{uri:loadingGif}} style={styles.verifyLogo} resizeMode="contain"/>
</View>
</View>:
<ListView dataSource={this.state.dataSource} renderRow={this.renderRow} enableEmptySections={true}/>;
return(
<View>
{currentView}
</View>
);
},
});
不要改變渲染狀態! – Lucero
那它怎麼不起作用? – Lucero
多數民衆贊成在說什麼,我問..... –