|
1 | 1 | import * as React from "react"; |
2 | | -import { StyleSheet } from "react-native"; |
| 2 | +import { ScrollView, StyleSheet, Text } from "react-native"; |
3 | 3 | import CodeHighlighter from "react-native-code-highlighter"; |
| 4 | +import { SafeAreaView } from "react-native-safe-area-context"; |
4 | 5 | import { atomOneDarkReasonable as hljsStyle } from "react-syntax-highlighter/dist/esm/styles/hljs"; |
5 | 6 |
|
6 | 7 | const CODE_STR = ` |
7 | | -import * as React from "react"; |
8 | | -import { StyleSheet } from "react-native"; |
9 | | -import { SafeAreaView } from "react-native-safe-area-context"; |
10 | | -import CodeHighlighter from "react-native-code-highlighter"; |
11 | | -import { darcula as hljsStyle } from "react-syntax-highlighter/dist/esm/styles/hljs"; |
12 | | -import React, { |
13 | | - useMemo, |
14 | | - type FunctionComponent, |
15 | | - type ReactNode, |
16 | | - type CSSProperties, |
17 | | -} from "react"; |
18 | | -import { |
19 | | - Text, |
20 | | - View, |
21 | | - ScrollView, |
22 | | - type ViewStyle, |
23 | | - type TextStyle, |
24 | | -} from "react-native"; |
25 | | -import SyntaxHighlighter, { |
26 | | - type SyntaxHighlighterProps, |
27 | | -} from "react-syntax-highlighter"; |
28 | | -// import { trimNewlines } from "trim-newlines"; |
29 | | -import { |
30 | | - getRNStylesFromHljsStyle, |
31 | | - type HighlighterStyleSheet, |
32 | | -} from "./../utils/styles"; |
| 8 | +import React from 'react'; |
| 9 | +import {SectionList, StyleSheet, Text, View} from 'react-native'; |
| 10 | +
|
| 11 | +const styles = StyleSheet.create({ |
| 12 | + container: { |
| 13 | + flex: 1, |
| 14 | + paddingTop: 22, |
| 15 | + }, |
| 16 | + sectionHeader: { |
| 17 | + paddingTop: 2, |
| 18 | + paddingLeft: 10, |
| 19 | + paddingRight: 10, |
| 20 | + paddingBottom: 2, |
| 21 | + fontSize: 14, |
| 22 | + fontWeight: 'bold', |
| 23 | + backgroundColor: 'rgba(247,247,247,1.0)', |
| 24 | + }, |
| 25 | + item: { |
| 26 | + padding: 10, |
| 27 | + fontSize: 18, |
| 28 | + height: 44, |
| 29 | + }, |
| 30 | +}); |
| 31 | +
|
| 32 | +const SectionListBasics = () => { |
| 33 | + return ( |
| 34 | + <View style={styles.container}> |
| 35 | + <SectionList |
| 36 | + sections={[ |
| 37 | + {title: 'D', data: ['Devin', 'Dan', 'Dominic']}, |
| 38 | + { |
| 39 | + title: 'J', |
| 40 | + data: [ |
| 41 | + 'Jackson', |
| 42 | + 'James', |
| 43 | + 'Jillian', |
| 44 | + 'Jimmy', |
| 45 | + 'Joel', |
| 46 | + 'John', |
| 47 | + 'Julie', |
| 48 | + ], |
| 49 | + }, |
| 50 | + ]} |
| 51 | + renderItem={({item}) => <Text style={styles.item}>{item}</Text>} |
| 52 | + renderSectionHeader={({section}) => ( |
| 53 | + <Text style={styles.sectionHeader}>{section.title}</Text> |
| 54 | + )} |
| 55 | + keyExtractor={item => \`basicListEntry-$\{item\}\`} |
| 56 | + /> |
| 57 | + </View> |
| 58 | + ); |
| 59 | +}; |
| 60 | +
|
| 61 | +export default SectionListBasics; |
33 | 62 | `; |
34 | 63 |
|
35 | 64 | export default function App() { |
36 | 65 | return ( |
37 | | - <CodeHighlighter |
38 | | - containerStyle={styles.codeContainer} |
39 | | - textStyle={styles.text} |
40 | | - hljsStyle={hljsStyle} |
41 | | - language="typescript" |
42 | | - > |
43 | | - {CODE_STR} |
44 | | - </CodeHighlighter> |
| 66 | + <SafeAreaView> |
| 67 | + <Text>Example from https://reactnative.dev/docs/using-a-listview</Text> |
| 68 | + <ScrollView> |
| 69 | + <CodeHighlighter |
| 70 | + containerStyle={styles.codeContainer} |
| 71 | + textStyle={styles.text} |
| 72 | + hljsStyle={hljsStyle} |
| 73 | + language="typescript" |
| 74 | + > |
| 75 | + {CODE_STR} |
| 76 | + </CodeHighlighter> |
| 77 | + </ScrollView> |
| 78 | + </SafeAreaView> |
45 | 79 | ); |
46 | 80 | } |
47 | 81 |
|
48 | 82 | const styles = StyleSheet.create({ |
49 | 83 | codeContainer: { |
50 | | - padding: 16, |
| 84 | + paddingHorizontal: 16, |
51 | 85 | minWidth: "100%", |
52 | 86 | }, |
53 | 87 | text: { |
|
0 commit comments