首页 > 其他分享 >RN navigation goback刷新上一个页面

RN navigation goback刷新上一个页面

时间:2023-03-09 19:55:41浏览次数:43  
标签:center goback Component refresh react props RN navigation


/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

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=()=>{
        console.log('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',
  },
});

标签:center,goback,Component,refresh,react,props,RN,navigation
From: https://www.cnblogs.com/ianlab/p/17201201.html

相关文章