React Native返回刷新页面(this.props.navigation.goBack())

Posted james-l

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了React Native返回刷新页面(this.props.navigation.goBack())相关的知识,希望对你有一定的参考价值。



import React, { Component } from ‘react‘;
import {
    AppRegistry,
    StyleSheet,
    Text,
    View,
    Button
} from ‘react-native‘;

export default class HomeScreen extends Component {
    constructor(props){
        super(props);
    }
    static navigationOptions = {
        title: ‘首页‘,
      };
    _refresh=()=>{alert(‘返回刷新哈!‘)
    }
    render() {
        return (
            <View style={styles.container}>
                <Text style={styles.welcome}>
                    Welcome to React Native!
                </Text>
                <Button
                    onPress={()=>{
                        this.props.navigation.navigate(‘NewsScreen‘,{
                            refresh:()=>{
                             this._refresh();
                            },
                        })
                    }}
                    title="新闻"
                />
            </View>
        );
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: ‘center‘,
        alignItems: ‘center‘,
        backgroundColor: ‘#F5FCFF‘,
    },
    welcome: {
        fontSize: 20,
        textAlign: ‘center‘,
        margin: 10,
    },
});
import React, { Component } from ‘react‘;
import {
  Platform,
  StyleSheet,
  Text,
  View,
  Button
} from ‘react-native‘;

export default class NewsScreen extends Component {
  constructor(props) {
    super(props);
  }
  static navigationOptions = {
    title: ‘新闻‘,
  };
  render() {
    return (
      <Button
      title="点我试试"
      onPress={
        () => { 
          this.props.navigation.goBack() 
          this.props.navigation.state.params.refresh();
        }
      }
    />
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: ‘center‘,
    alignItems: ‘center‘,
    backgroundColor: ‘#F5FCFF‘,
  },
});

以上是关于React Native返回刷新页面(this.props.navigation.goBack())的主要内容,如果未能解决你的问题,请参考以下文章

React Native返回刷新页面(this.props.navigation.goBack())

react native 路由跳转后页面不刷新问题

react-native如何在facebook登录和注销后刷新页面

react native 刷新机制----通知

有效登录后React Native iOS“Safari无法打开页面,因为地址无效”

React Native:你可以强制刷新应用程序或重新渲染页面 onPress of a button?