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

Commit

Permalink
fix: stylesheet support
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniAkash committed Oct 8, 2020
1 parent 69a6c84 commit 7bda93a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
27 changes: 27 additions & 0 deletions example/src/App.tsx
Expand Up @@ -92,6 +92,32 @@ const styleMap = {
},
};

const editorStyleSheet = `
@import url(https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,600&display=swap);
body {
background-color: red;
}
h1 > div > span > span {
font-family: "Source Sans Pro", sans-serif;
font-weight: 600;
font-size: 18px;
line-height: 28px;
color: black;
}
li > div > span > span {
font-family: "Source Sans Pro", sans-serif;
font-size: 15px;
line-height: 32px;
color: black;
}
span {
font-family: "Source Sans Pro", sans-serif;
font-size: 15px;
line-height: 26px;
color: black;
}
`;

const App = () => {
const _draftRef = React.createRef<RNDraftView>();
const [activeStyles, setActiveStyles] = useState<string[]>([]);
Expand Down Expand Up @@ -148,6 +174,7 @@ const App = () => {
onStyleChanged={updateActiveStyle}
onBlockTypeChanged={setActiveBlockType}
styleMap={styleMap}
styleSheet={editorStyleSheet}
/>
<EditorToolBar
activeStyles={activeStyles}
Expand Down
6 changes: 5 additions & 1 deletion src/index.tsx
Expand Up @@ -103,7 +103,11 @@ class RNDraftView extends Component<
this.executeScript('setEditorPlaceholder', placeholder);
}
if (styleSheet) {
this.executeScript('setEditorStyleSheet', styleSheet);
// TODO: Replace single quotes with double quotes using regex
this.executeScript(
'setEditorStyleSheet',
styleSheet.replace(/(\r\n|\n|\r)/gm, '')
);
}
if (styleMap) {
try {
Expand Down

0 comments on commit 7bda93a

Please sign in to comment.