Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add injectJavascript method #307

Merged
merged 7 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ export default FontFamilyStylesheet;
```javascript
import FontFamilyStylesheet from 'stylesheet.js';

<RichEditor
editorStyle={{ initialCSSText: `${FontFamilyStylesheet}`, contentCSSText: `font-family: 'Your Font Family';` }}
/>
const fontFamily = 'Your_Font_Family';
const initialCSSText = { initialCSSText: `${FontFamilyStylesheet}`, contentCSSText: `font-family: ${fontFamily}` }
<RichEditor editorStyle={initialCSSText}/>
```
5. Reload the app. You should now be seeing your Rich Editor content in your custom font face!

Expand Down Expand Up @@ -293,6 +293,8 @@ import React from "react";
import { Text, Platform, KeyboardAvoidingView, SafeAreaView, ScrollView } from "react-native";
import {actions, RichEditor, RichToolbar} from "react-native-pell-rich-editor";


const handleHead = ({tintColor}) => <Text style={{color: tintColor}}>H1</Text>
const TempScreen = () => {
const richText = React.useRef();
return (
Expand All @@ -312,7 +314,7 @@ const TempScreen = () => {
<RichToolbar
editor={richText}
actions={[ actions.setBold, actions.setItalic, actions.setUnderline, actions.heading1 ]}
iconMap={{ [actions.heading1]: ({tintColor}) => (<Text style={[{color: tintColor}]}>H1</Text>), }}
iconMap={{ [actions.heading1]: handleHead }}
/>
</SafeAreaView>
);
Expand Down
2 changes: 1 addition & 1 deletion examples/src/example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @author wxik
* @since 2019-06-24 14:52
*/
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {
Appearance,
Button,
Expand Down
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ export class RichEditor extends React.Component<RichEditorProps> {

insertHTML: (html: string) => void;

injectJavascript: (type: string) => void;

preCode: (type: string) => void;

/**
Expand Down
4 changes: 4 additions & 0 deletions src/RichEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ export default class RichTextEditor extends Component {
}
}

injectJavascript(script) {
return this.webviewBridge.injectJavaScript(script);
}

preCode(type) {
this.sendAction(actions.code, 'result', type);
}
Expand Down