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

Commit 3b805fc

Browse files
committed
upgrade react native webview
1 parent d01b61f commit 3b805fc

File tree

6 files changed

+27684
-11
lines changed

6 files changed

+27684
-11
lines changed

ReactNativeDraftjsExample/App.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
* @flow
77
*/
88

9-
import React, { useState } from "react";
9+
import React, { useState, useEffect } from "react";
1010
import {
1111
SafeAreaView,
1212
StyleSheet,
1313
TouchableOpacity,
1414
View,
15-
Text
15+
Text,
16+
Platform
1617
} from "react-native";
1718
import KeyboardSpacer from "react-native-keyboard-spacer";
1819
import RNDraftView from "react-native-draftjs";
@@ -72,6 +73,10 @@ const App = () => {
7273
const _draftRef = React.createRef();
7374
const [activeStyles, setActiveStyles] = useState([]);
7475
const [blockType, setActiveBlockType] = useState("unstyled");
76+
const [editorState, setEditorState] = useState("");
77+
78+
const defaultValue =
79+
"<h1>A Full fledged Text Editor</h1><p>This editor is built with Draft.js. Hence should be suitable for most projects. However, Draft.js Isn’t fully compatible with mobile yet. So you might face some issues.</p><p><br></p><p>This is a simple implementation</p><ul> <li>It contains <strong>Text formatting </strong>and <em>Some blocks formatting</em></li> <li>Each for it’s own purpose</li></ul><p>You can also do</p><ol> <li>Custom style map</li> <li>Own css styles</li> <li>Custom block styling</li></ol><p>You are welcome to try it!</p>";
7580

7681
const editorLoaded = () => {
7782
_draftRef.current && _draftRef.current.focus();
@@ -85,12 +90,22 @@ const App = () => {
8590
_draftRef.current && _draftRef.current.setBlockType(blockType);
8691
};
8792

93+
useEffect(() => {
94+
/**
95+
* Get the current editor state in HTML.
96+
* Usually keep it in the submit or next action to get output after user has typed.
97+
*/
98+
setEditorState(_draftRef.current ? _draftRef.current.getEditorState() : "");
99+
});
100+
console.log(editorState);
101+
88102
return (
89103
<SafeAreaView style={styles.containerStyle}>
90104
<RNDraftView
105+
defaultValue={defaultValue}
91106
onEditorReady={editorLoaded}
92107
style={{ flex: 1 }}
93-
placeholder={"Some placeholder Text..."}
108+
placeholder={"Add text here..."}
94109
ref={_draftRef}
95110
onStyleChanged={setActiveStyles}
96111
onBlockTypeChanged={setActiveBlockType}
@@ -101,7 +116,7 @@ const App = () => {
101116
toggleStyle={toggleStyle}
102117
toggleBlockType={toggleBlockType}
103118
/>
104-
<KeyboardSpacer />
119+
{Platform.OS === "ios" ? <KeyboardSpacer /> : null}
105120
</SafeAreaView>
106121
);
107122
};

ReactNativeDraftjsExample/android/app/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,7 @@ task copyDownloadableDepsToLibs(type: Copy) {
208208
}
209209

210210
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
211+
project.afterEvaluate {
212+
apply from: '../../node_modules/react-native-draftjs/copyHtml.gradle';
213+
copyEditorHtmlToAppAssets(file('../../node_modules/react-native-draftjs'))
214+
}

0 commit comments

Comments
 (0)