1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-11 18:24:43 +02:00

Mobile: Optimising screen rendering to make text input faster

This commit is contained in:
Laurent Cozic 2019-07-12 18:32:08 +01:00
parent 091cbc5355
commit 981c97cca5
2 changed files with 50 additions and 24 deletions

View File

@ -26,7 +26,7 @@ const DialogBox = require('react-native-dialogbox').default;
// default height. // default height.
const PADDING_V = 10; const PADDING_V = 10;
class ScreenHeaderComponent extends Component { class ScreenHeaderComponent extends React.PureComponent {
constructor() { constructor() {
super(); super();
@ -311,9 +311,10 @@ class ScreenHeaderComponent extends Component {
} }
const titlePickerItems = (mustSelect) => { const titlePickerItems = (mustSelect) => {
const folders = this.props.folders.filter(f => f.id !== Folder.conflictFolderId());
let output = []; let output = [];
if (mustSelect) output.push({ label: _('Move to notebook...'), value: null }); if (mustSelect) output.push({ label: _('Move to notebook...'), value: null });
const folderTree = Folder.buildTree(this.props.folders); const folderTree = Folder.buildTree(folders);
output = addFolderChildren(folderTree, output, 0); output = addFolderChildren(folderTree, output, 0);
return output; return output;
} }

View File

@ -4,10 +4,12 @@ const { connect } = require('react-redux');
const { uuid } = require('lib/uuid.js'); const { uuid } = require('lib/uuid.js');
const RNFS = require('react-native-fs'); const RNFS = require('react-native-fs');
const Note = require('lib/models/Note.js'); const Note = require('lib/models/Note.js');
const ObjectUtils = require('lib/ObjectUtils.js');
const BaseItem = require('lib/models/BaseItem.js'); const BaseItem = require('lib/models/BaseItem.js');
const Setting = require('lib/models/Setting.js'); const Setting = require('lib/models/Setting.js');
const Resource = require('lib/models/Resource.js'); const Resource = require('lib/models/Resource.js');
const Folder = require('lib/models/Folder.js'); const Folder = require('lib/models/Folder.js');
const md5 = require('md5');
const { BackButtonService } = require('lib/services/back-button.js'); const { BackButtonService } = require('lib/services/back-button.js');
const NavService = require('lib/services/NavService.js'); const NavService = require('lib/services/NavService.js');
const BaseModel = require('lib/BaseModel.js'); const BaseModel = require('lib/BaseModel.js');
@ -186,6 +188,8 @@ class NoteScreenComponent extends BaseScreenComponent {
this.properties_onPress = this.properties_onPress.bind(this); this.properties_onPress = this.properties_onPress.bind(this);
this.onMarkForDownload = this.onMarkForDownload.bind(this); this.onMarkForDownload = this.onMarkForDownload.bind(this);
this.sideMenuOptions = this.sideMenuOptions.bind(this); this.sideMenuOptions = this.sideMenuOptions.bind(this);
this.folderPickerOptions_valueChanged = this.folderPickerOptions_valueChanged.bind(this);
this.saveNoteButton_press = this.saveNoteButton_press.bind(this);
} }
styles() { styles() {
@ -596,6 +600,11 @@ class NoteScreenComponent extends BaseScreenComponent {
const isTodo = note && !!note.is_todo; const isTodo = note && !!note.is_todo;
const isSaved = note && note.id; const isSaved = note && note.id;
const cacheKey = md5([isTodo, isSaved].join('_'));
if (!this.menuOptionsCache_) this.menuOptionsCache_ = {};
if (this.menuOptionsCache_[cacheKey]) return this.menuOptionsCache_[cacheKey];
let output = []; let output = [];
// The file attachement modules only work in Android >= 5 (Version 21) // The file attachement modules only work in Android >= 5 (Version 21)
@ -627,6 +636,9 @@ class NoteScreenComponent extends BaseScreenComponent {
output.push({ title: _('Properties'), onPress: () => { this.properties_onPress(); } }); output.push({ title: _('Properties'), onPress: () => { this.properties_onPress(); } });
output.push({ title: _('Delete'), onPress: () => { this.deleteNote_onPress(); } }); output.push({ title: _('Delete'), onPress: () => { this.deleteNote_onPress(); } });
this.menuOptionsCache_ = {};
this.menuOptionsCache_[cacheKey] = output;
return output; return output;
} }
@ -651,6 +663,39 @@ class NoteScreenComponent extends BaseScreenComponent {
if (fieldToFocus === 'body') this.refs.noteBodyTextField.focus(); if (fieldToFocus === 'body') this.refs.noteBodyTextField.focus();
} }
async folderPickerOptions_valueChanged(itemValue, itemIndex) {
const note = this.state.note;
if (!note.id) {
await this.saveNoteButton_press(itemValue);
} else {
await Note.moveToFolder(note.id, itemValue);
}
note.parent_id = itemValue;
const folder = await Folder.load(note.parent_id);
this.setState({
lastSavedNote: Object.assign({}, note),
note: note,
folder: folder,
});
}
folderPickerOptions() {
const options = {
enabled: true,
selectedFolderId: this.state.folder ? this.state.folder.id : null,
onValueChange: this.folderPickerOptions_valueChanged,
};
if (this.folderPickerOptions_ && options.selectedFolderId === this.folderPickerOptions_.selectedFolderId) return this.folderPickerOptions_;
this.folderPickerOptions_ = options;
return this.folderPickerOptions_;
}
render() { render() {
if (this.state.isLoading) { if (this.state.isLoading) {
return ( return (
@ -803,31 +848,11 @@ class NoteScreenComponent extends BaseScreenComponent {
return ( return (
<View style={this.rootStyle(this.props.theme).root}> <View style={this.rootStyle(this.props.theme).root}>
<ScreenHeader <ScreenHeader
folderPickerOptions={{ folderPickerOptions={this.folderPickerOptions()}
enabled: true,
selectedFolderId: folder ? folder.id : null,
onValueChange: async (itemValue, itemIndex) => {
if (!note.id) {
await this.saveNoteButton_press(itemValue);
} else {
await Note.moveToFolder(note.id, itemValue);
}
note.parent_id = itemValue;
const folder = await Folder.load(note.parent_id);
this.setState({
lastSavedNote: Object.assign({}, note),
note: note,
folder: folder,
});
},
}}
menuOptions={this.menuOptions()} menuOptions={this.menuOptions()}
showSaveButton={showSaveButton} showSaveButton={showSaveButton}
saveButtonDisabled={saveButtonDisabled} saveButtonDisabled={saveButtonDisabled}
onSaveButtonPress={() => this.saveNoteButton_press()} onSaveButtonPress={this.saveNoteButton_press}
showSideMenuButton={false} showSideMenuButton={false}
showSearchButton={false} showSearchButton={false}
/> />