如何在React-Native中修复我的refreshcontrol和scrollview

时间:2019-04-18 11:55:08

标签: javascript reactjs react-native scrollview jsx

我想在页面上创建“拉动刷新” ,我可以启用或显示该刷新,但是在下拉列表后,总是出现错误(不确定),我真的很想重新渲染,但是同样的问题,实际上我使用的是本机反应,希望你们能帮助我

这是我的代码

class Dashboard extends Component {
  constructor(props) {
    super(props)
    this.state = {
      isLoading: true,
      error: null,
      refreshing: false
    }

    Navigation.mergeOptions(this.props.componentId, {
      topBar: {
        title: {
          component: {
            name: NAVBAR_HEADER
          }
        }
      }
    })
    this.mounted = false
    this.state = {
      user: null
    }
  }

  async componentDidMount() {
    this.mounted = true

    let user = await Storage.get('users')
    this.setState({
      user: user
    })
  }

  componentWillUnmount() {
    this.mounted = false
  }

  _onRefresh = () => {
    this.setState({ refreshing: true })
    this.componentDidMount().then(() => {
      this.setState({ refreshing: false })
    })
  }
   render() {
    return (
      <ScrollView
        style={styles.container}
        refreshControl={
          <RefreshControl
            refreshing={this.state.refreshing}
            onRefresh={this._onRefresh}
          />
        }
      >
        {this.state.user && (
          <Query
            query={PARTNER_DETAILS}
            variables={{ partner_id: this.state.user.partner_id }}
            fetchPolicy="cache-and-network"
          >
            {({ loading, error, data, refetch }) => {
              return (
                <ProfileBanner
                  onPress={this.goToProfile}
                  loading={loading}
                  {...data.resPartnerById}
                />
              )
            }}
          </Query>
        )}
        <BlogImage />
        {this.mounted && <Revenue />}
      </ScrollView>
    )
  }
}

const styles = {
  container: {
    flex: 1,
    backgroundColor: '#f5f5f5'
  }
}

export default Dashboard

我也想进行刷新和渲染刷新,但始终未定义,我猜这是onRefresh中的错误

0 个答案:

没有答案