Skip to content

Commit

Permalink
cleanup and bumping version
Browse files Browse the repository at this point in the history
  • Loading branch information
abanobmikaeel committed Oct 3, 2023
1 parent b1cf926 commit a9587a5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
7 changes: 3 additions & 4 deletions example/src/Ckeditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function Ckeditor({ route }: any) {
};

const onChange = (e: any) => {
console.log('onChange', e);
// console.log('onChange', e);
};

const onError = (e: any) => {
Expand All @@ -40,7 +40,7 @@ export default function Ckeditor({ route }: any) {
};

const onLoadEnd = (e: any) => {
console.log('onLoadEnd', e);
// console.log('onLoadEnd', e);
};

const renderError = () => {
Expand All @@ -50,7 +50,6 @@ export default function Ckeditor({ route }: any) {
const renderLoading = () => {
return <ActivityIndicator></ActivityIndicator>;
};
console.log('here? ckeditor');

return (
<View style={styles.container}>
Expand All @@ -70,7 +69,7 @@ export default function Ckeditor({ route }: any) {
height={height}
androidHardwareAccelerationDisabled={false}
fontFamily={fontFamily}
colors={{}}
colors={{ backgroundColors: 'white' }}
toolbarBorderSize={toolbarBorderSize}
editorFocusBorderSize={editorFocusBorderSize}
// placeHolderText={placeHolderText}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-ckeditor-custom",
"version": "0.3.2",
"version": "0.3.3",
"description": "A react native library to handle custom ckeditors",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
37 changes: 21 additions & 16 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useEffect, useRef } from 'react';
import { SafeAreaView } from 'react-native';
// import SafeAreaView from 'react-native-safe-area-view';
import { Dimensions } from 'react-native';
import { WebView, type WebViewMessageEvent } from 'react-native-webview';

Expand Down Expand Up @@ -58,12 +57,14 @@ export const CKEditor5 = ({
const onMessage = (event: WebViewMessageEvent) => {
const data = event.nativeEvent.data;
if (data.indexOf('RNCKEditor5') === 0) {
console.log(data);
const [_, cmd, value] = data.split(':');
console.log(cmd);
switch (cmd) {
case 'onFocus':
if (value === 'true' && onFocus) onFocus();
if (value === 'false' && onBlur) onBlur();
// webView.injectJavaScript(
// webview?.current?.injectJavaScript(
// `document.querySelector( '.ck-editor__editable' ).blur()`
// );
}
Expand All @@ -72,10 +73,12 @@ export const CKEditor5 = ({
};

useEffect(() => {
const webviewRef = webview.current;
return () => {
if (webview) {
webview.current?.injectJavaScript(
`(function() {document.removeEventListener('message', handleMessage);})();`
if (webviewRef) {
webviewRef.injectJavaScript(
`element.removeEventListener("cleanupLater", cleanupLater, true);
true;`
);
}
};
Expand All @@ -96,27 +99,25 @@ export const CKEditor5 = ({
alert(e)
}
});
editor.editing.view.document.on(
'change:isFocused',
editor.editing.view.document.on('change:isFocused',
(evt, name, value) => {
console.log('editable isFocused =', value);
window.ReactNativeWebView.postMessage(JSON.stringify(msg));
window.ReactNativeWebView.postMessage(
'RNCKEditor5:onFocus:' + value, "*"
);
}
);
document.addEventListener("message", function(data) {
editor.setData(data.data);
})
// Set initial data after editor is ready
editor.setData(\`${initialData}\`);
})
.catch(error => {
console.error(error);
});
};
const cleanupLater = (data) => {
console.log(data.data);
editor.setData(data.data);
}
document.addEventListener("message", cleanupLater)
var style = document.createElement("style");
style.type = "text/css";
Expand Down Expand Up @@ -158,11 +159,15 @@ export const CKEditor5 = ({
`
: ''
}
\`
document.head.appendChild(style);
\`${injectedJavascript}\`
\`${injectedJavascript}\`;
window.onerror = function(message, sourcefile, lineno, colno, error) {
alert("Message: " + message + " - Source: " + sourcefile + " Line: " + lineno + ":" + colno);
return true;
};
true;
`;

return (
Expand Down

0 comments on commit a9587a5

Please sign in to comment.