Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 在react native中从后台模式返回时更新数据_React Native - Fatal编程技术网

React native 在react native中从后台模式返回时更新数据

React native 在react native中从后台模式返回时更新数据,react-native,React Native,嗨,我在react native中使用地理位置坐标来显示我周围的用户。我已经实现了一个下拉刷新功能,可以在我改变位置后刷新用户列表。当我从后台模式返回时,如何刷新数据 displayPosition = () => { this.watchId = Geolocation.getCurrentPosition( (position) => { let obj = { latitude: position.co

嗨,我在react native中使用地理位置坐标来显示我周围的用户。我已经实现了一个下拉刷新功能,可以在我改变位置后刷新用户列表。当我从后台模式返回时,如何刷新数据

  displayPosition = () => {
      this.watchId = Geolocation.getCurrentPosition(
        (position) => {
          let obj = {
            latitude: position.coords.latitude,
            longitude: position.coords.longitude,
            error: null
          }
          this.setState(obj);
        },
        (error) => this.setState({ error: error.message }),
        { enableHighAccuracy: true, timeout: 200000, maximumAge: 1000},
      );
      if(this.state.latitude!=null){
        this.getData();
      }else{
        setTimeout(this.displayPosition.bind(this),200)
      }
      //console.log(this.state.latitude);
      //console.log(this.state.longitude);
  }

  handleRefresh = () => {
    this.setState (
      {
        refreshing: true,
      },
      () => {
        this.setState({refreshing: false});
        this.displayPosition();
        //this.getData();
      }
    );
  };


  componentDidMount() {
    this.displayPosition();
    //this.getData();
    this.props.navigation.setParams({ refresh: this._handleRefresh });
  }

  componentWillUnmount() {
    Geolocation.clearWatch(this.watchId);
  }
谢谢

您可以在react native中为相同的应用程序添加侦听器

对于同一个列表,共有4个列表器

willFocus-屏幕将聚焦 didFocus-屏幕聚焦如果有转换,则转换完成 willBlur-屏幕将不聚焦 didBlur-屏幕未聚焦如果有过渡,则过渡完成 请尝试下面的代码

componentWillMount(){
    const didFocusSubscription = this.props.navigation.addListener(
      'didFocus',
      payload => {
        console.warn('didFocus ', payload);
        # just write your code/call a method here which you want to execute when the app comes from background
        this.handleRefresh()
      }
    );
}
完成后别忘了取下它

componentWillUnmount(){
    didFocusSubscription.remove();
}
你能读的更多。谢谢:

您可以在react native中为相同内容添加侦听器

对于同一个列表,共有4个列表器

willFocus-屏幕将聚焦 didFocus-屏幕聚焦如果有转换,则转换完成 willBlur-屏幕将不聚焦 didBlur-屏幕未聚焦如果有过渡,则过渡完成 请尝试下面的代码

componentWillMount(){
    const didFocusSubscription = this.props.navigation.addListener(
      'didFocus',
      payload => {
        console.warn('didFocus ', payload);
        # just write your code/call a method here which you want to execute when the app comes from background
        this.handleRefresh()
      }
    );
}
完成后别忘了取下它

componentWillUnmount(){
    didFocusSubscription.remove();
}
你能读的更多。谢谢: