|
@@ -1,5 +1,26 @@
|
1
|
1
|
import React, {Component, PropTypes} from 'react';
|
2
|
|
-import {View, TouchableOpacity} from 'react-native';
|
|
2
|
+import {View, TouchableOpacity, Text} from 'react-native';
|
|
3
|
+import {actions} from './const';
|
|
4
|
+
|
|
5
|
+const defaultActions = [
|
|
6
|
+ actions.insertImage,
|
|
7
|
+ actions.setBold,
|
|
8
|
+ actions.setItalic,
|
|
9
|
+ actions.insertBulletsList,
|
|
10
|
+ actions.insertOrderedList,
|
|
11
|
+ actions.insertLink
|
|
12
|
+];
|
|
13
|
+
|
|
14
|
+function getDefaultIconText() {
|
|
15
|
+ const texts = {};
|
|
16
|
+ texts[actions.insertImage] = 'IMG';
|
|
17
|
+ texts[actions.setBold] = 'B';
|
|
18
|
+ texts[actions.setItalic] = 'I';
|
|
19
|
+ texts[actions.insertBulletsList] = '0';
|
|
20
|
+ texts[actions.insertOrderedList] = '1';
|
|
21
|
+ texts[actions.insertLink] = '<a>';
|
|
22
|
+ return texts;
|
|
23
|
+}
|
3
|
24
|
|
4
|
25
|
|
5
|
26
|
export default class RichTextToolbar extends Component {
|
|
@@ -8,15 +29,42 @@ export default class RichTextToolbar extends Component {
|
8
|
29
|
getEditor: PropTypes.func.isRequired
|
9
|
30
|
};
|
10
|
31
|
|
11
|
|
- render() {
|
|
32
|
+ _getButton(action, selected) {
|
12
|
33
|
return (
|
13
|
34
|
<TouchableOpacity
|
14
|
|
- style={{
|
15
|
|
- height: 50,
|
16
|
|
- backgroundColor: 'red'
|
17
|
|
- }}
|
18
|
|
- onPress={() => this.props.getEditor().setBold()}
|
19
|
|
- />
|
|
35
|
+ key={action}
|
|
36
|
+ style={{flex: 1, backgroundColor: 'blue', justifyContent: 'center'}}
|
|
37
|
+ onPress={() => this._onPress(action)}
|
|
38
|
+ >
|
|
39
|
+ <Text style={{textAlign: 'center'}}>
|
|
40
|
+ {getDefaultIconText()[action]}
|
|
41
|
+ </Text>
|
|
42
|
+ </TouchableOpacity>
|
|
43
|
+ );
|
|
44
|
+ }
|
|
45
|
+
|
|
46
|
+ render() {
|
|
47
|
+ return (
|
|
48
|
+ <View style={{flexDirection: 'row', height: 50}}>
|
|
49
|
+ {defaultActions.map((action) => this._getButton(action, false))}
|
|
50
|
+ </View>
|
20
|
51
|
);
|
21
|
52
|
}
|
|
53
|
+
|
|
54
|
+ _onPress(action) {
|
|
55
|
+ switch(action) {
|
|
56
|
+ case actions.setBold:
|
|
57
|
+ this.props.getEditor().setBold();
|
|
58
|
+ break;
|
|
59
|
+ case actions.setItalic:
|
|
60
|
+ this.props.getEditor().setItalic();
|
|
61
|
+ break;
|
|
62
|
+ case actions.insertBulletsList:
|
|
63
|
+ this.props.getEditor().insertBulletsList();
|
|
64
|
+ break;
|
|
65
|
+ case actions.insertOrderedList:
|
|
66
|
+ this.props.getEditor().insertOrderedList();
|
|
67
|
+ break;
|
|
68
|
+ }
|
|
69
|
+ }
|
22
|
70
|
}
|