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

Expose worklet runtime #601

Merged
merged 3 commits into from
Jan 22, 2025
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
11 changes: 11 additions & 0 deletions src/MarkdownTextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ declare global {
let initialized = false;
let workletRuntime: WorkletRuntime | undefined;

function getWorkletRuntime(): WorkletRuntime {
if (workletRuntime === undefined) {
throw new Error(
"[react-native-live-markdown] Worklet runtime hasn't been created yet. Please avoid calling `getWorkletRuntime()` in top-level scope. Instead, call `getWorkletRuntime()` directly in `runOnRuntime` arguments list.",
);
}
return workletRuntime;
}

function initializeLiveMarkdownIfNeeded() {
if (initialized) {
return;
Expand Down Expand Up @@ -132,3 +141,5 @@ const styles = StyleSheet.create({
export type {PartialMarkdownStyle as MarkdownStyle, MarkdownTextInputProps};

export default MarkdownTextInput;

export {getWorkletRuntime};
6 changes: 6 additions & 0 deletions src/MarkdownTextInput.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -830,3 +830,9 @@ const styles = StyleSheet.create({
export default MarkdownTextInput;

export type {MarkdownTextInputProps, MarkdownTextInputElement, HTMLMarkdownElement};

function getWorkletRuntime() {
throw new Error('[react-native-live-markdown] `getWorkletRuntime` is not available on web. Please make sure to use it only on native Android or iOS.');
}

export {getWorkletRuntime};
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export {default as MarkdownTextInput} from './MarkdownTextInput';
export {default as MarkdownTextInput, getWorkletRuntime} from './MarkdownTextInput';
export type {MarkdownTextInputProps, MarkdownStyle} from './MarkdownTextInput';
export type {MarkdownType, MarkdownRange} from './commonTypes';
export {default as parseExpensiMark} from './parseExpensiMark';
Loading