|
4 | 4 | */ |
5 | 5 |
|
6 | 6 | import React, { Component } from 'react'; |
7 | | -import { |
8 | | - Platform, |
9 | | - StyleSheet, |
10 | | - Text, |
11 | | - View |
12 | | -} from 'react-native'; |
| 7 | +import {Platform, Picker, ScrollView, StyleSheet, Text, View} from "react-native"; |
13 | 8 |
|
14 | | -import Markdown from './react-native-markdown-renderer'; |
| 9 | +import Markdown, { |
| 10 | + AstRenderer, |
| 11 | + getUniqueID, |
| 12 | + PluginContainer, |
| 13 | + renderRules, |
| 14 | + styles, |
| 15 | +} from './react-native-markdown-renderer'; |
| 16 | +// |
| 17 | +import markdownItCheckbox from 'markdown-it-checkbox'; |
| 18 | +import copyAll from './src/copyAll'; |
| 19 | +import customMarkdownStyle from './src/customMarkdownStyle'; |
| 20 | +import copyAllCheckboxPlugin from './src/copyAllCheckboxPlugin'; |
| 21 | +import pluginRules from './src/pluginRules'; |
15 | 22 |
|
16 | 23 | const instructions = Platform.select({ |
17 | | - ios: 'Press Cmd+R to reload,\n' + |
18 | | - 'Cmd+D or shake for dev menu', |
19 | | - android: 'Double tap R on your keyboard to reload,\n' + |
20 | | - 'Shake or press menu button for dev menu', |
| 24 | + ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu', |
| 25 | + android: 'Double tap R on your keyboard to reload,\n' + 'Shake or press menu button for dev menu', |
21 | 26 | }); |
22 | 27 |
|
23 | 28 | export default class App extends Component { |
| 29 | + state = { |
| 30 | + view: 5, |
| 31 | + }; |
| 32 | + |
| 33 | + list = [ |
| 34 | + { description: 'default' }, |
| 35 | + { description: 'custom renderer' }, |
| 36 | + { description: 'custom style sheet' }, |
| 37 | + { description: 'custom rules' }, |
| 38 | + { description: 'custom rules & styles' }, |
| 39 | + { description: 'plugins (checkbox)' }, |
| 40 | + ]; |
| 41 | + |
| 42 | + getView(value) { |
| 43 | + switch (value) { |
| 44 | + case 0: { |
| 45 | + return <Markdown children={copyAll} />; |
| 46 | + } |
| 47 | + case 1: { |
| 48 | + return <Markdown renderer={renderer.render} children={copyAll} />; |
| 49 | + } |
| 50 | + case 2: { |
| 51 | + return <Markdown style={customMarkdownStyle} children={copyAll} />; |
| 52 | + } |
| 53 | + case 3: { |
| 54 | + return <Markdown rules={rules} children={copyAll} />; |
| 55 | + } |
| 56 | + case 4: { |
| 57 | + return <Markdown rules={rules} style={customMarkdownStyle} children={copyAll} />; |
| 58 | + } |
| 59 | + case 5: { |
| 60 | + return ( |
| 61 | + <Markdown |
| 62 | + rules={pluginRules} |
| 63 | + plugins={[new PluginContainer(markdownItCheckbox, { divWrap: true })]} |
| 64 | + style={customMarkdownStyle} |
| 65 | + children={copyAllCheckboxPlugin} |
| 66 | + /> |
| 67 | + ); |
| 68 | + } |
| 69 | + |
| 70 | + default: { |
| 71 | + return <Markdown># Text</Markdown>; |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + |
24 | 76 | render() { |
25 | 77 | return ( |
26 | | - <View style={styles.container}> |
27 | | - <Text style={styles.welcome}> |
28 | | - Welcome to React Native! |
29 | | - </Text> |
30 | | - <Text style={styles.instructions}> |
31 | | - To get started, edit App.js |
32 | | - </Text> |
33 | | - <Text style={styles.instructions}> |
34 | | - {instructions} |
35 | | - </Text> |
| 78 | + <View style={styleSheet.container}> |
| 79 | + <Picker |
| 80 | + selectedValue={this.state.view} |
| 81 | + onValueChange={(itemValue, itemIndex) => this.setState({ view: itemIndex })} |
| 82 | + > |
| 83 | + {this.list.map((val, index) => <Picker.Item key={val.description} label={val.description} value={index} />)} |
| 84 | + </Picker> |
| 85 | + |
| 86 | + <ScrollView>{this.getView(this.state.view)}</ScrollView> |
36 | 87 | </View> |
37 | 88 | ); |
38 | 89 | } |
39 | 90 | } |
40 | 91 |
|
41 | | -const styles = StyleSheet.create({ |
| 92 | +const styleSheet = StyleSheet.create({ |
42 | 93 | container: { |
43 | 94 | flex: 1, |
44 | | - justifyContent: 'center', |
45 | | - alignItems: 'center', |
46 | | - backgroundColor: '#F5FCFF', |
47 | | - }, |
48 | | - welcome: { |
49 | | - fontSize: 20, |
50 | | - textAlign: 'center', |
51 | | - margin: 10, |
52 | | - }, |
53 | | - instructions: { |
54 | | - textAlign: 'center', |
55 | | - color: '#333333', |
56 | | - marginBottom: 5, |
| 95 | + marginTop: 20, |
57 | 96 | }, |
58 | 97 | }); |
0 commit comments