react-native - 使用 react-navigation 导航会导致组件不显示数据,需要重新渲染
问题描述
当我使用 react-navigation 导航时,显示的屏幕(SearchPage - 无状态功能组件)有一个CategoriesMultiselect
(类组件)缺少类别数据(视觉上)。数据肯定仍然存在,因为当我滚动页面时,数据会显示出来,因为它被重新渲染了。
searchPage
当导航到(或重新呈现类别多选)时,我将如何导致重新呈现?
导航的代码:
import FBLoginButton from './button/view'
import React, { Component } from 'react'
import { View } from 'react-native'
import { Container, Text, Button } from 'native-base'
import VepoHeader from '../../formControls/header/view'
import { styles } from '../../style'
import { withNavigation } from 'react-navigation'
class LoginView extends Component {
constructor(props) {
super(props)
this.buttonPress = this.buttonPress.bind(this)
}
buttonPress() {
console.log('called')
this.props.navigation.navigate('Search')
}
render() {
return (
<Container style={{ backgroundColor: '#27a562' }}>
<Container
style={{
flex: 1,
height: '100%',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center'
}}>
<FBLoginButton />
<Text style={{ color: '#FFF',
marginTop: 20,
marginBottom: 20 }}>OR</Text>
<Button
block
style={{
...styles.labelHeight,
borderRadius: 4,
borderWidth: 0.5,
borderColor: '#FFF',
width: 250,
marginLeft: 'auto',
marginRight: 'auto',
backgroundColor: 'transparent',
}}
onPress={this.buttonPress}>
<Text style={{fontSize: 13.5}}>Continue without Login</Text>
</Button>
</Container>
</Container>
)
}
}
export default withNavigation(LoginView)
导航到无状态功能 searchPage 组件后,我需要在 CategoriesMultiselect 上调用 forceupdate()。
我怎么做?
解决方案
推荐阅读
- java - 如何将 ArrayList 添加到另一个 ArrayList?
- python - 二元分类器的 SVM 训练总是给出 0 类
- r - 具有多个条件的子集
- typescript - 将方法动态添加到打字稿中的类
- keras - 为什么在这个例子中使用 binary_crossentropy?
- c# - 在 c# win 表单中的 webview 中替代 Document.GetElementFromPoint(e.ClientMousePosition)
- ios - 我确实从相机或图库中选择图像以及如何保存该图像以显示在其他视图中?
- r - 仅包含某些汉字的行的过滤条件
- algorithm - 如何证明递归算法的正确性
- python - 如何从字符串构建字典