diff --git a/ReactNativeClient/lib/components/action-button.js b/ReactNativeClient/lib/components/action-button.js
index 5d297c47d..e1b788f01 100644
--- a/ReactNativeClient/lib/components/action-button.js
+++ b/ReactNativeClient/lib/components/action-button.js
@@ -19,13 +19,13 @@ class ActionButtonComponent extends React.Component {
constructor() {
super();
this.state = {
- toggled: false,
+ buttonIndex: 0,
};
}
componentWillReceiveProps(newProps) {
- if ('toggled' in newProps) {
- this.setState({ toggled: newProps.toggled });
+ if ('buttonIndex' in newProps) {
+ this.setState({ buttonIndex: newProps.buttonIndex });
}
}
@@ -104,18 +104,16 @@ class ActionButtonComponent extends React.Component {
let mainButton = this.props.mainButton ? this.props.mainButton : {};
let mainIcon = mainButton.icon ? : +;
- 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];
+ 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');
+ let button = this.props.buttons[this.state.buttonIndex];
let mainIcon =
return (
{
- let doToggle = button.onPress(this.state.toggled);
- if (doToggle !== false) this.setState({ toggled: !this.state.toggled });
- }}
+ onPress={() => { button.onPress() }}
/>
);
} else {
diff --git a/ReactNativeClient/lib/components/screens/note.js b/ReactNativeClient/lib/components/screens/note.js
index 66ab8bc0e..362492198 100644
--- a/ReactNativeClient/lib/components/screens/note.js
+++ b/ReactNativeClient/lib/components/screens/note.js
@@ -46,7 +46,10 @@ class NoteScreenComponent extends BaseScreenComponent {
}
if (this.state.mode == 'edit') {
- this.setState({ mode: 'view' });
+ this.setState({
+ note: Object.assign({}, this.state.lastSavedNote),
+ mode: 'view',
+ });
return true;
}
@@ -298,9 +301,9 @@ class NoteScreenComponent extends BaseScreenComponent {
if (this.state.mode == 'edit' && !this.isModified()) return ;
- let toggled = this.state.mode == 'edit';
+ let buttonIndex = this.state.mode == 'view' ? 0 : 1;
- return
+ return
}
const actionButtonComp = renderActionButton();