Browse Source

Gentrify toolbar

Yedidya Kennard 8 years ago
parent
commit
ccfea80c59
1 changed files with 40 additions and 8 deletions
  1. 40
    8
      src/RichTextToolbar.js

+ 40
- 8
src/RichTextToolbar.js View File

@@ -29,11 +29,27 @@ export default class RichTextToolbar extends Component {
29 29
     getEditor: PropTypes.func.isRequired
30 30
   };
31 31
 
32
+  constructor(props) {
33
+    super(props);
34
+    this.state = {
35
+      editor: undefined
36
+    };
37
+  }
38
+
39
+  componentDidMount() {
40
+    const editor = this.props.getEditor();
41
+    if (!editor) {
42
+      throw new Error('Toolbar has no editor!');
43
+    } else {
44
+      this.setState({editor});
45
+    }
46
+  }
47
+
32 48
   _getButton(action, selected) {
33 49
     return (
34 50
       <TouchableOpacity
35 51
           key={action}
36
-          style={{flex: 1, backgroundColor: 'blue', justifyContent: 'center'}}
52
+          style={{flex: 1, backgroundColor: '#D3D3D3', justifyContent: 'center'}}
37 53
           onPress={() => this._onPress(action)}
38 54
       >
39 55
         <Text style={{textAlign: 'center'}}>
@@ -54,16 +70,32 @@ export default class RichTextToolbar extends Component {
54 70
   _onPress(action) {
55 71
     switch(action) {
56 72
       case actions.setBold:
57
-        this.props.getEditor().setBold();
58
-        break;
59 73
       case actions.setItalic:
60
-        this.props.getEditor().setItalic();
61
-        break;
62 74
       case actions.insertBulletsList:
63
-        this.props.getEditor().insertBulletsList();
64
-        break;
65 75
       case actions.insertOrderedList:
66
-        this.props.getEditor().insertOrderedList();
76
+      case actions.setUnderline:
77
+      case actions.heading1:
78
+      case actions.heading2:
79
+      case actions.heading3:
80
+      case actions.heading4:
81
+      case actions.heading5:
82
+      case actions.heading6:
83
+      case actions.setParagraph:
84
+      case actions.removeFormat:
85
+      case actions.alignLeft:
86
+      case actions.alignCenter:
87
+      case actions.alignRight:
88
+      case actions.alignFull:
89
+      case actions.setSubscript:
90
+      case actions.setSuperscript:
91
+      case actions.setStrikethrough:
92
+      case actions.setHR:
93
+      case actions.setIndent:
94
+      case actions.setOutdent:
95
+        this.state.editor._sendAction(action);
96
+        break;
97
+      case actions.insertLink:
98
+      case actions.insertImage:
67 99
         break;
68 100
     }
69 101
   }