Skip to content

Updated readme with code that worked with latest react, expo and typescript #189

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
116 changes: 116 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,123 @@ const App: () => React$Node = () => {

export default App;
```
You can find this example [here](https://snack.expo.dev/@hassieb/react-native-markdown-display-ordered-list)

This next example worked with `"react-native-markdown-display": "^7.0.0-alpha.2",` on React`18.1.0`, React Native `0.70.5` via the Expo command `npx create-expo-app --template` with typescript selected.

```jsx
import React from "react";
import { StyleSheet, SafeAreaView, ScrollView, StatusBar } from "react-native";
import { useTheme } from "@react-navigation/native";

import Markdown from "react-native-markdown-display";

const copy = `# h1 Heading 8-)

**This is some bold text!**

This is normal text
`;

const MarkdownWrapper: React.FC<any> = ({ children }) => {
const { colors } = useTheme();
// @ts-ignore
return <Markdown style={styles({ colors })}>{children}</Markdown>;
};

const App: () => React.ReactElement = () => {
return (
<>
<StatusBar barStyle="dark-content" />
<SafeAreaView>
<ScrollView
contentInsetAdjustmentBehavior="automatic"
style={{ height: "100%" }}
>
<MarkdownWrapper>{copy}</MarkdownWrapper>
</ScrollView>
</SafeAreaView>
</>
);
};

export const styles = (props: any) =>
StyleSheet.create({
text: {
color: props.colors.text,
},
});

export default App;
```

With text input

```jsx
import React from "react";
import {
StyleSheet,
SafeAreaView,
ScrollView,
StatusBar,
TextInput,
} from "react-native";
import { useTheme } from "@react-navigation/native";

import Markdown from "react-native-markdown-display";

const copy = `# h1 Heading 8-)

**This is some bold text!**

This is normal text
`;

const MarkdownWrapper: React.FC<any> = ({ children }) => {
const { colors } = useTheme();
// @ts-ignore
return <Markdown style={styles({ colors })}>{children}</Markdown>;
};

const App: () => React.ReactElement = () => {
const [text, onChangeText] = React.useState(copy);
const { colors } = useTheme();
return (
<>
<StatusBar barStyle="dark-content" />
<SafeAreaView>
<ScrollView
contentInsetAdjustmentBehavior="automatic"
style={{ height: "100%" }}
>
<TextInput
multiline
style={{ ...styles({colors}).input, color: colors.text }}
onChangeText={onChangeText}
value={text}
/>
<MarkdownWrapper>{text}</MarkdownWrapper>
</ScrollView>
</SafeAreaView>
</>
);
};

export const styles = (props: any) =>
StyleSheet.create({
text: {
color: props.colors.text,
},
input: {
height: 80,
margin: 12,
borderWidth: 1,
padding: 10,
},
});

export default App;
```

### Props and Functions

Expand Down