Cache note list

pull/41/head
Laurent Cozic 2017-07-31 22:03:12 +02:00
parent f7da1118db
commit 8ce02e6e4c
3 changed files with 27 additions and 5 deletions

View File

@ -1,5 +1,6 @@
import React, { Component } from 'react';
import { connect } from 'react-redux'
import { NotesScreen } from 'lib/components/screens/notes.js';
import { View } from 'react-native';
import { _ } from 'lib/locale.js';
@ -9,11 +10,19 @@ class AppNavComponent extends Component {
if (!this.props.route) throw new Error('Route must not be null');
let route = this.props.route;
let Screen = this.props.screens[route.routeName].screen;
let Screen = null;
let notesScreenVisible = false;
if (route.routeName == 'Notes') {
notesScreenVisible = true;
} else {
Screen = this.props.screens[route.routeName].screen;
}
return (
<View style={{ flex: 1 }}>
<Screen navigation={{ state: route }} />
<NotesScreen visible={notesScreenVisible} navigation={{ state: route }} />
{ !notesScreenVisible && <Screen navigation={{ state: route }} /> }
</View>
);
}

View File

@ -2,12 +2,14 @@ import React, { Component } from 'react';
import { StyleSheet } from 'react-native';
import { globalStyle } from 'lib/components/global-style.js';
const styles_ = StyleSheet.create({
const styleObject_ = {
screen: {
flex: 1,
backgroundColor: globalStyle.backgroundColor,
},
});
};
const styles_ = StyleSheet.create(styleObject_);
class BaseScreenComponent extends React.Component {
@ -15,6 +17,10 @@ class BaseScreenComponent extends React.Component {
return styles_;
}
styleObject() {
return styleObject_;
}
}
export { BaseScreenComponent };

View File

@ -43,6 +43,7 @@ class NotesScreenComponent extends BaseScreenComponent {
};
const parent = this.parentItem(props);
if (!parent) return;
const source = JSON.stringify({
options: options,
@ -110,6 +111,7 @@ class NotesScreenComponent extends BaseScreenComponent {
} else if (props.notesParentType == 'Tag') {
output = Tag.byId(props.tags, props.selectedTagId);
} else {
return null;
throw new Error('Invalid parent type: ' + props.notesParentType);
}
return output;
@ -129,9 +131,14 @@ class NotesScreenComponent extends BaseScreenComponent {
let title = parent ? parent.title : null;
const addFolderNoteButtons = this.props.selectedFolderId && this.props.selectedFolderId != Folder.conflictFolderId();
let rootStyle = Object.assign({}, this.styleObject().screen);
if (!this.props.visible) {
rootStyle.flex = 0.001; // This is a bit of a hack but it seems to work fine - it makes the component invisible but without unmounting it
}
const { navigate } = this.props.navigation;
return (
<View style={this.styles().screen}>
<View style={rootStyle}>
<ScreenHeader title={title} menuOptions={this.menuOptions()} />
<NoteList style={{flex: 1}}/>
<ActionButton addFolderNoteButtons={addFolderNoteButtons} parentFolderId={this.props.selectedFolderId}></ActionButton>