【问题标题】:closed-Reload page in React-NativeReact-Native 中的关闭重新加载页面
【发布时间】:2018-12-02 14:02:39
【问题描述】:

我正在开发一个 react-native 应用程序,我想在其中自动重新加载页面,谁能告诉我如何在 react-native 代码中做到这一点, 我有三个组件,其中一个组件必须下拉我只想重新加载我页面的当前屏幕this is the image,当有人更改语言时,我想重新加载页面

【问题讨论】:

  • 您的问题不清楚。请给我更多关于你的问题的信息。您想刷新屏幕中的数据吗?刷新来自 api 的数据?刷新你的模拟器?..

标签: react-native react-native-android react-native-ios


【解决方案1】:

你可以使用forceupdatehttps://reactjs.org/docs/react-component.html#forceupdate

forceupdate 将重新渲染组件。

【讨论】:

  • 感谢您的解决方案,但 forceUpdate 不起作用,因为它会更新当前组件,但我们在单个页面中有三个不同的组件
【解决方案2】:

https://facebook.github.io/react-native/docs/refreshcontrol.html

这是 react native 刷新组件的指南,通常我们创建函数 _onRefresh(),你可以在特定的时间间隔调用它。

希望这个答案对你有所帮助。

【讨论】:

    【解决方案3】:

    componentDidMount() 上使用 setTimeout 重新加载页面。

    示例:

    setTimeout(() => {
        this.setState({time: true})
    }, 1000)
    

    【讨论】:

      【解决方案4】:

      我假设您说的是在模拟器中自动刷新更改的组件。

      您可能希望在 iOS 或 Android 模拟器中启用热重载

      You can pull up the developer screen in the iOS simulator showing Hot Reloading by pressing CMD + D.

      【讨论】:

      • 感谢您的解决方案,但此解决方案不起作用,因为它会重新加载整个应用程序我只想重新加载当前页面
      • @jasminraval 你可能混淆了实时重载热重载Here's an explanation. 基本上,热重载应该能完成你想要的。
      【解决方案5】:

      简单准确清晰!

      componentWillMount(){
          this._subscribe = this.props.navigation.addListener('didFocus', () => {
           this.LoadData();
           //Put your Data loading function here instead of my this.LoadData()
          });}
      

      【讨论】:

        猜你喜欢
        • 2018-05-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多