IOS反应导航:屏幕未使用TabNavigator重新渲染

时间:2017-04-09 20:19:33

标签: ios react-native react-navigation tabnavigator

有屏幕Home和New。 Home显示存储在db中的数据列表。对db的新写入。主屏幕应重新显示用户导航到新数据但不显示新数据。这是预期的行为,是否有一个简单的解决方案?

主屏幕:

class Home extends React.Component {
static navigationOptions = {
    title: 'Home',
};

constructor(props) {
    super(props);

    realm = new Realm({schema: [Case]});
    this.state = {
        cases: realm.objects('Case'),
    }
};

render() {
    const listItems = this.state.cases.map((data, index) =>
        <View style={Styles.listItem}>
            <Text key={index}>
                {data.name}
            </Text>
        </View>
    );
    return (
        <View>
            <ScrollView>
                { listItems }
            </ScrollView>
        </View>
    );
}

路由配置:

const MainScreenNavigator = TabNavigator({
Home: { screen: Home },
New: { screen: NewCase },
});

const SimpleApp = StackNavigator({
    Home: { screen: MainScreenNavigator },
});

AppRegistry.registerComponent('SimpleApp', () => SimpleApp);

0 个答案:

没有答案