javascript - 使用卡片 View react native 从服务器获取数据

标签 javascript android ios reactjs react-native

我想使用 card view react native 从服务器获取数据,但是当我打开 Activity 时它仍在加载,我的代码哪里出错了?

renderItem = ({ item }) => {
return (
  <Card>
    <CardItem cardBody>
      <Image source={{ uri: 'http://bprwasa.com/assets/frontend/images/gallery/kpo.jpg' }} style={{ height: 200, width: null, flex: 1 }} />
    </CardItem>
    <CardItem>
      <Body>
        <Text>
          {item.nama_wil}
        </Text>
      </Body>
    </CardItem>
  </Card>
)}

还有这个

render() {
return (
  this.state.isLoading
    ?
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      <ActivityIndicator size='large' color='#330066' animating />
    </View>
    :
    <Container>
      <Content>
      {this.state.dataSource}
      {this.renderItem}
      </Content>
    </Container>

)}}

最佳答案

在您的情况下,问题是您没有将 ActivityIndi​​catoranimating 属性设置为 false

但是同样重要的是要注意在 react-native 版本 0.58.3 之前仍然存在一个错误,检查 this

解决方案

使用这个可重用组件,它有解决方法 { opacity: this.state.showActivityIndi​​cator ? 1 : 0 确保将其属性 showActivityIndi​​cator 设置为 truefalse

import React, { Component } from "react";
import { ActivityIndicator, StyleSheet } from "react-native";

export default class ActivityProgress extends Component {
  constructor(props) {
    super(props);
    this.state = {
      showActivityIndicator: props.showActivityIndicator
    };
  }

  componentDidUpdate(prevProps) {
    if (this.props.showActivityIndicator != prevProps.showActivityIndicator) {
      this.setState({
        showActivityIndicator: this.props.showActivityIndicator
      });
    }
  }

  render() {
    return (
      <ActivityIndicator
        size={isAndroid() ? 100 : "large"}
        color="red"
        animating={true}
        style={[
          { opacity: this.state.showActivityIndicator ? 1 : 0 },
          styles.spinnerLoading
        ]}
      />
    );
  }
}

const styles = StyleSheet.create({
  spinnerLoading: {
    position: "absolute",
    left: 0,
    right: 0,
    top: 0,
    bottom: 0,
    alignItems: "center",
    justifyContent: "center"
  }
});

希望这对您有所帮助!

关于javascript - 使用卡片 View react native 从服务器获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54842074/

相关文章:

Javascript 关注 div 内的 span

android - AutoCompleteTextView 结果出现然后消失

android - 如何在 Android 中创建 Draggabble 系统警报?

ios - Swift:UIAlertController 从列表中选择子集

ios - 快速修改自身的字符串扩展

Iphone CLLocationCoordinate2D

javascript - 如何在 Angular2 应用程序中使用 ngrx-effects 从商店返回分页数据或从 api 服务返回新数据?

javascript - 我的 sidenav 颜色没有随着按钮(点击)而改变

javascript - 使用原生js创建pdf文件?

android - DDMS View 文件资源管理器中的数据目录