1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-18 23:07:45 +02:00
Files
Assets
CliClient
CliClientDemo
ElectronClient
ReactNativeClient
android
ios
lib
components
screens
shared
Dropdown.js
ItemList.js
ModalDialog.js
SaveIcon.png
action-button.js
app-nav.js
base-screen.js
checkbox.js
global-style.js
note-body-viewer.js
note-item.js
note-list.js
screen-header.js
select-date-time-dialog.js
side-menu-content.js
side-menu.js
images
models
services
vendor
ArrayUtils.js
BaseApplication.js
BaseModel.js
BaseSyncTarget.js
Cache.js
DropboxApi.js
EventDispatcher.js
JoplinError.js
MdToHtml.js
MdToHtml_Katex.js
ModelCache.js
ObjectUtils.js
SyncTargetDropbox.js
SyncTargetFilesystem.js
SyncTargetMemory.js
SyncTargetNextcloud.js
SyncTargetOneDrive.js
SyncTargetOneDriveDev.js
SyncTargetRegistry.js
SyncTargetWebDAV.js
WebDavApi.js
database-driver-node.js
database-driver-react-native.js
database.js
dialogs.js
file-api-driver-dropbox.js
file-api-driver-local.js
file-api-driver-memory.js
file-api-driver-onedrive.js
file-api-driver-webdav.js
file-api.js
folders-screen-utils.js
fs-driver-base.js
fs-driver-dummy.js
fs-driver-node.js
fs-driver-rn.js
geolocation-node.js
geolocation-react.js
import-enex-md-gen.js
import-enex.js
joplin-database.js
layout-utils.js
locale.js
logger.js
markdown-utils.js
mime-utils.js
net-utils.js
onedrive-api.js
package.json
parameters.js
parseUri.js
path-utils.js
poor-man-intervals.js
promise-utils.js
react-logger.js
reducer.js
registry.js
shim-init-node.js
shim-init-react.js
shim.js
string-utils.js
synchronizer.js
time-utils.js
urlUtils.js
uuid.js
locales
.babelrc
.buckconfig
.flowconfig
.gitattributes
.gitignore
.watchmanconfig
app.json
build_android.bat
build_android_prod.bat
clean_build.bat
debug_log.bat
debug_log.sh
index.android.js
index.ios.js
index.js
main.js
package-lock.json
package.json
root.js
start_emulator.bat
start_server.bat
start_server.sh
Tools
docs
readme
.gitignore
.travis.yml
BUILD.md
CONTRIBUTING.md
LICENSE
README.md
_config.yml
appveyor.yml
joplin.sublime-project
linkToLocal.sh
joplin/ReactNativeClient/lib/components/action-button.js

141 lines
3.8 KiB
JavaScript
Raw Normal View History

const React = require('react'); const Component = React.Component;
const { StyleSheet, Text } = require('react-native');
const Icon = require('react-native-vector-icons/Ionicons').default;
const ReactNativeActionButton = require('react-native-action-button').default;
const { connect } = require('react-redux');
const { globalStyle } = require('lib/components/global-style.js');
const { _ } = require('lib/locale.js');
2017-05-16 21:05:53 +00:00
const styles = StyleSheet.create({
actionButtonIcon: {
fontSize: 20,
height: 22,
color: 'white',
2017-05-16 21:05:53 +00:00
},
2017-07-30 23:04:26 +02:00
itemText: {
// fontSize: 14, // Cannot currently set fontsize since the bow surrounding the label has a fixed size
}
2017-05-16 21:05:53 +00:00
});
class ActionButtonComponent extends React.Component {
2017-07-14 00:35:37 +01:00
constructor() {
super();
this.state = {
2017-07-15 19:21:39 +01:00
buttonIndex: 0,
2017-07-14 00:35:37 +01:00
};
}
UNSAFE_componentWillReceiveProps(newProps) {
if ('buttonIndex' in newProps) {
2017-07-15 19:21:39 +01:00
this.setState({ buttonIndex: newProps.buttonIndex });
2017-07-15 00:12:32 +01:00
}
}
2017-05-24 20:51:50 +00:00
newTodo_press() {
this.props.dispatch({
type: 'NAV_GO',
routeName: 'Note',
2017-05-24 20:51:50 +00:00
noteId: null,
folderId: this.props.parentFolderId,
itemType: 'todo',
2017-05-24 20:51:50 +00:00
});
}
2017-05-16 21:05:53 +00:00
newNote_press() {
this.props.dispatch({
type: 'NAV_GO',
routeName: 'Note',
2017-05-16 21:05:53 +00:00
noteId: null,
folderId: this.props.parentFolderId,
itemType: 'note',
2017-05-16 21:05:53 +00:00
});
}
newFolder_press() {
this.props.dispatch({
type: 'NAV_GO',
routeName: 'Folder',
2017-05-16 21:05:53 +00:00
folderId: null,
});
}
render() {
2017-07-14 00:35:37 +01:00
let buttons = this.props.buttons ? this.props.buttons : [];
2017-05-24 20:51:50 +00:00
2017-07-14 00:35:37 +01:00
if (this.props.addFolderNoteButtons) {
if (this.props.folders.length) {
buttons.push({
title: _('New to-do'),
onPress: () => { this.newTodo_press() },
color: '#9b59b6',
icon: 'md-checkbox-outline',
2017-07-14 00:35:37 +01:00
});
buttons.push({
title: _('New note'),
onPress: () => { this.newNote_press() },
color: '#9b59b6',
icon: 'md-document',
2017-07-14 00:35:37 +01:00
});
}
buttons.push({
title: _('New notebook'),
onPress: () => { this.newFolder_press() },
color: '#3498db',
icon: 'md-folder',
2017-07-14 00:35:37 +01:00
});
}
2017-05-24 20:51:50 +00:00
2017-07-14 00:35:37 +01:00
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;
2017-07-14 00:35:37 +01:00
buttonComps.push(
<ReactNativeActionButton.Item key={key} buttonColor={button.color} title={buttonTitle} onPress={button.onPress}>
<Icon name={button.icon} style={styles.actionButtonIcon} />
2017-05-16 21:05:53 +00:00
</ReactNativeActionButton.Item>
2017-07-08 23:57:09 +01:00
);
}
2017-05-24 20:51:50 +00:00
2017-07-14 00:35:37 +01:00
if (!buttonComps.length && !this.props.mainButton) {
return <ReactNativeActionButton style={{ display: 'none' }}/>
2017-07-14 00:35:37 +01:00
}
let mainButton = this.props.mainButton ? this.props.mainButton : {};
let mainIcon = mainButton.icon ? <Icon name={mainButton.icon} style={styles.actionButtonIcon} /> : <Icon name="md-add" style={styles.actionButtonIcon} />
2017-07-14 00:35:37 +01:00
2017-07-15 19:21:39 +01:00
if (this.props.multiStates) {
if (!this.props.buttons || !this.props.buttons.length) throw new Error('Multi-state button requires at least one state');
if (this.state.buttonIndex < 0 || this.state.buttonIndex >= this.props.buttons.length) throw new Error('Button index out of bounds: ' + this.state.buttonIndex + '/' + this.props.buttons.length);
2017-07-15 19:21:39 +01:00
let button = this.props.buttons[this.state.buttonIndex];
let mainIcon = <Icon name={button.icon} style={styles.actionButtonIcon} />
2017-07-14 00:35:37 +01:00
return (
<ReactNativeActionButton
icon={mainIcon}
buttonColor="rgba(231,76,60,1)"
onPress={() => { button.onPress() }}
2017-07-14 00:35:37 +01:00
/>
);
} else {
return (
<ReactNativeActionButton textStyle={styles.itemText} icon={mainIcon} buttonColor="rgba(231,76,60,1)" onPress={ function() { } }>
{ buttonComps }
2017-07-14 00:35:37 +01:00
</ReactNativeActionButton>
);
}
2017-05-16 21:05:53 +00:00
}
}
const ActionButton = connect(
(state) => {
return {
folders: state.folders,
locale: state.settings.locale,
};
}
)(ActionButtonComponent)
2017-05-16 21:05:53 +00:00
module.exports = { ActionButton };