Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 22f123c

Browse files
committed
add support for custom style map
1 parent afd0f4a commit 22f123c

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

ReactNativeDraftjsExample/App.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,21 @@ const EditorToolBar = ({
6565
isActive={blockType === "ordered-list-item"}
6666
action={() => toggleBlockType("ordered-list-item")}
6767
/>
68+
<ControlButton
69+
text={"--"}
70+
isActive={activeStyles.includes("STRIKETHROUGH")}
71+
action={() => toggleStyle("STRIKETHROUGH")}
72+
/>
6873
</View>
6974
);
7075
};
7176

77+
const styleMap = {
78+
STRIKETHROUGH: {
79+
textDecoration: "line-through"
80+
}
81+
};
82+
7283
const App = () => {
7384
const _draftRef = React.createRef();
7485
const [activeStyles, setActiveStyles] = useState([]);
@@ -96,7 +107,7 @@ const App = () => {
96107
* Usually keep it in the submit or next action to get output after user has typed.
97108
*/
98109
setEditorState(_draftRef.current ? _draftRef.current.getEditorState() : "");
99-
});
110+
}, [_draftRef]);
100111
console.log(editorState);
101112

102113
return (
@@ -109,6 +120,7 @@ const App = () => {
109120
ref={_draftRef}
110121
onStyleChanged={setActiveStyles}
111122
onBlockTypeChanged={setActiveBlockType}
123+
styleMap={styleMap}
112124
/>
113125
<EditorToolBar
114126
activeStyles={activeStyles}

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class RNDraftView extends Component {
2727
executeScript = (functionName, parameter) => {
2828
this._webViewRef.current &&
2929
this._webViewRef.current.injectJavaScript(
30-
`window.${functionName}(${parameter ? `"${parameter}"` : ""});true;`
30+
`window.${functionName}(${parameter ? `'${parameter}'` : ""});true;`
3131
);
3232
};
3333

0 commit comments

Comments
 (0)