首页 > 解决方案 > 如何刷新全屏并重新加载react-native中的所有组件

问题描述

我正在使用 react-native,react-navigation。我想使用滚动视图刷新我的应用程序的整个屏幕并重新渲染所有组件,有人可以就此提出建议吗?

标签: react-native

解决方案


嘿,您可以首先使用NavigationEventsreact-navigation 导入NavigationEvents

这是我的代码。

   import { NavigationEvents } from 'react-navigation';
    import * as React from 'react';
    import { Text, View, StyleSheet } from 'react-native';
    import Constants from 'expo-constants';
    export default class App extends React.Component {
      render() {
        return (
          <View style={styles.container}>
  <NavigationEvents
            onDidFocus={() => alert('Welcome')}
          />
            <Text style={styles.paragraph}>
              Hello word
            </Text>
            <Card>
              <AssetExample />
            </Card>
          </View>
        );
      }
    }

    const styles = StyleSheet.create({
      container: {
        flex: 1,
        justifyContent: 'center',
        paddingTop: Constants.statusBarHeight,
        backgroundColor: '#ecf0f1',
        padding: 8,
      },
      paragraph: {
        margin: 24,
        fontSize: 18,
        fontWeight: 'bold',
        textAlign: 'center',
      },
    });

我使用<NavigationEvents onDidFocus={() => alert('Welcome')}/>它,它被称为 wvwer time 您打开页面。

希望对您有所帮助,请随时提出疑问。


推荐阅读