码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2019-12-26 14:55:58      阅读:447      评论:0      收藏:0      [点我收藏+]

标签:import   param   def   justify   number   button   首页   styles   ext   



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())

标签:import   param   def   justify   number   button   首页   styles   ext   

原文地址:https://www.cnblogs.com/james-L/p/12101907.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!