You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-26 22:41:17 +02:00
Improved edit/save note
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import React, { Component } from 'react';
|
||||
import { StyleSheet } from 'react-native';
|
||||
import { StyleSheet, Text } from 'react-native';
|
||||
import Icon from 'react-native-vector-icons/Ionicons';
|
||||
import ReactNativeActionButton from 'react-native-action-button';
|
||||
import { connect } from 'react-redux'
|
||||
import { Log } from 'lib/log.js'
|
||||
import { _ } from 'lib/locale.js'
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
actionButtonIcon: {
|
||||
@@ -15,6 +16,13 @@ const styles = StyleSheet.create({
|
||||
|
||||
class ActionButtonComponent extends React.Component {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.state = {
|
||||
toggled: false,
|
||||
};
|
||||
}
|
||||
|
||||
newTodo_press() {
|
||||
this.props.dispatch({
|
||||
type: 'Navigation/NAVIGATE',
|
||||
@@ -44,33 +52,73 @@ class ActionButtonComponent extends React.Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
let buttons = [];
|
||||
let buttons = this.props.buttons ? this.props.buttons : [];
|
||||
|
||||
if (this.props.folders.length) {
|
||||
buttons.push(
|
||||
<ReactNativeActionButton.Item key="ab_todo" buttonColor='#9b59b6' title="New todo" onPress={() => { this.newTodo_press() }}>
|
||||
<Icon name="md-checkbox-outline" style={styles.actionButtonIcon} />
|
||||
</ReactNativeActionButton.Item>
|
||||
);
|
||||
if (this.props.addFolderNoteButtons) {
|
||||
if (this.props.folders.length) {
|
||||
buttons.push({
|
||||
title: _('New todo'),
|
||||
onPress: () => { this.newTodo_press() },
|
||||
color: '#9b59b6',
|
||||
icon: 'md-checkbox-outline',
|
||||
});
|
||||
|
||||
buttons.push(
|
||||
<ReactNativeActionButton.Item key="ab_note" buttonColor='#9b59b6' title="New note" onPress={() => { this.newNote_press() }}>
|
||||
<Icon name="md-document" style={styles.actionButtonIcon} />
|
||||
buttons.push({
|
||||
title: _('New note'),
|
||||
onPress: () => { this.newNote_press() },
|
||||
color: '#9b59b6',
|
||||
icon: 'md-document',
|
||||
});
|
||||
}
|
||||
|
||||
buttons.push({
|
||||
title: _('New folder'),
|
||||
onPress: () => { this.newFolder_press() },
|
||||
color: '#3498db',
|
||||
icon: 'md-folder',
|
||||
});
|
||||
}
|
||||
|
||||
let buttonComps = [];
|
||||
for (let i = 0; i < buttons.length; i++) {
|
||||
let button = buttons[i];
|
||||
let buttonTitle = button.title ? button.title : '';
|
||||
let key = buttonTitle.replace(/\s/g, '_') + '_' + button.icon;
|
||||
buttonComps.push(
|
||||
<ReactNativeActionButton.Item key={key} buttonColor={button.color} title={buttonTitle} onPress={button.onPress}>
|
||||
<Icon name={button.icon} style={styles.actionButtonIcon} />
|
||||
</ReactNativeActionButton.Item>
|
||||
);
|
||||
}
|
||||
|
||||
buttons.push(
|
||||
<ReactNativeActionButton.Item key="ab_folder" buttonColor='#3498db' title="New folder" onPress={() => { this.newFolder_press() }}>
|
||||
<Icon name="md-folder" style={styles.actionButtonIcon} />
|
||||
</ReactNativeActionButton.Item>
|
||||
);
|
||||
if (!buttonComps.length && !this.props.mainButton) {
|
||||
return <ReactNativeActionButton style={{ display: 'none' }}/>
|
||||
}
|
||||
|
||||
return (
|
||||
<ReactNativeActionButton buttonColor="rgba(231,76,60,1)">
|
||||
{ buttons }
|
||||
</ReactNativeActionButton>
|
||||
);
|
||||
let mainButton = this.props.mainButton ? this.props.mainButton : {};
|
||||
let mainIcon = mainButton.icon ? <Icon name={mainButton.icon} style={styles.actionButtonIcon} /> : <Text style={{fontSize: 20, color:"#ffffff"}}>+</Text>;
|
||||
|
||||
if (this.props.isToggle) {
|
||||
if (!this.props.buttons || this.props.buttons.length != 2) throw new Error('Toggle state requires two buttons');
|
||||
let button = this.props.buttons[this.state.toggled ? 1 : 0];
|
||||
let mainIcon = <Icon name={button.icon} style={styles.actionButtonIcon} />
|
||||
return (
|
||||
<ReactNativeActionButton
|
||||
icon={mainIcon}
|
||||
buttonColor="rgba(231,76,60,1)"
|
||||
onPress={() => {
|
||||
let doToggle = button.onPress(this.state.toggled);
|
||||
if (doToggle !== false) this.setState({ toggled: !this.state.toggled });
|
||||
}}
|
||||
/>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<ReactNativeActionButton icon={mainIcon} buttonColor="rgba(231,76,60,1)" onPress={ function() { } }>
|
||||
{ buttonComps }
|
||||
</ReactNativeActionButton>
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user