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

Let onMessage handlers coexist #250

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Changes from 1 commit
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
15 changes: 14 additions & 1 deletion src/RichText/RichText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import { CoreEditorActionType } from '../bridges/core';

interface RichTextProps extends WebViewProps {
editor: EditorBridge;

/** Makes it so that the onMessage method provided by Tentap does not fire if you have your own custom onMessage method.
* Introduced for backwards compatibility with previous versions of Tentap that had this behaviour by default.
* */
exclusivelyUseCustomOnMessage?: boolean;
}

const styles = StyleSheet.create({
Expand All @@ -36,7 +41,12 @@ const DEV_SERVER_URL = 'http://localhost:3000';
// TODO: make it a prop
const TOOLBAR_HEIGHT = 44;

export const RichText = ({ editor, ...props }: RichTextProps) => {
export const RichText = ({
editor,
onMessage,
exclusivelyUseCustomOnMessage = true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the use-case for this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the prop? Keeping compatibility and maintaining current behaviour so I don't accidentally break peoples' setups. And in general the use-case for the pr is being able to use the onMessage prop of the webview without messing up tentap's own behaviour

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any case it's a very important feature for me, so I know there's a usecase haha

...props
}: RichTextProps) => {
const [editorHeight, setEditorHeight] = useState(0);
const [key, setKey] = useState('webview');
const [loaded, setLoaded] = useState(isFabric());
Expand All @@ -49,6 +59,9 @@ export const RichText = ({ editor, ...props }: RichTextProps) => {
};

const onWebviewMessage = (event: WebViewMessageEvent) => {
onMessage && onMessage(event);
if (exclusivelyUseCustomOnMessage && onMessage) return;

const { data } = event.nativeEvent;
// on expo-web we sometimes get react-dev messages that come in as objects - so we ignore these
if (typeof data !== 'string') return;
Expand Down