-
Notifications
You must be signed in to change notification settings - Fork 18
/
CustomExample.js
196 lines (184 loc) · 5.34 KB
/
CustomExample.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import React from 'react';
import RenderHTML from 'react-native-render-html';
import { useHtmlTableProps, tableModel } from '@native-html/table-plugin';
import ClickTable from './ClickTable';
import WebView from 'react-native-webview';
const table1 = `
This custom component will adapt it's layout depending on table stats.
If the table has less than 4 columns and 8 rows, or less than 400 printable characters, it will be shown inline.
Otherwise, a button will be displayed to open a modal.
<h2>Small table</h2>
<table>
<tr>
<th>Entry Header 1</th>
<th>Entry Header 2</th>
<th>Entry Header 3</th>
</tr>
<tr>
<td>Entry First Line 1</td>
<td>Entry First Line 2</td>
<td>Entry First Line 3</td>
</tr>
<tr>
<td>Entry Second Line 1</td>
<td>Entry Second Line 2</td>
<td>Entry Second Line 3</td>
</tr>
<tr>
<td>Entry Third Line 1</td>
<td>Entry Third Line 2</td>
<td>Entry Third Line 3</td>
</tr>
</table>
<h2>Big table</h2>
<table>
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste website</td>
<td>Maria Anders</td>
<td><a class="a" href="https://en.wikipedia.org/wiki/germany">Germany</a></td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td><a href="https://en.wikipedia.org/wiki/mexico">Mexico</a></td>
</tr>
<tr>
<td>Ernst Handel</td>
<td>Roland Mendel</td>
<td><a href="https://en.wikipedia.org/wiki/austria">Austria</a></td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helen Bennett</td>
<td><a href="https://en.wikipedia.org/wiki/united_kingdom">UK</td>
</tr>
<tr>
<td>Laughing Bacchus Winecellars</td>
<td>Yoshi Tannamuri</td>
<td><a href="https://en.wikipedia.org/wiki/canada">Canada</a></td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td><a href="https://en.wikipedia.org/wiki/italy">Italy</a></td>
</tr>
<tr>
<td>Alfreds Futterkiste website</td>
<td>Maria Anders</td>
<td><a href="https://en.wikipedia.org/wiki/germany">Germany</a></td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td><a href="https://en.wikipedia.org/wiki/mexico">Mexico</a></td>
</tr>
<tr>
<td>Ernst Handel</td>
<td>Roland Mendel</td>
<td><a href="https://en.wikipedia.org/wiki/austria">Austria</a></td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helen Bennett</td>
<td><a href="https://en.wikipedia.org/wiki/united_kingdom">UK</td>
</tr>
<tr>
<td>Laughing Bacchus Winecellars</td>
<td>Yoshi Tannamuri</td>
<td><a href="https://en.wikipedia.org/wiki/canada">Canada</a></td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td><a href="https://en.wikipedia.org/wiki/italy">Italy</a></td>
</tr>
<tr>
<td>Alfreds Futterkiste website</td>
<td>Maria Anders</td>
<td><a href="https://en.wikipedia.org/wiki/germany">Germany</a></td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td><a href="https://en.wikipedia.org/wiki/mexico">Mexico</a></td>
</tr>
<tr>
<td>Ernst Handel</td>
<td>Roland Mendel</td>
<td><a href="https://en.wikipedia.org/wiki/austria">Austria</a></td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helen Bennett</td>
<td><a href="https://en.wikipedia.org/wiki/united_kingdom">UK</td>
</tr>
<tr>
<td>Laughing Bacchus Winecellars</td>
<td>Yoshi Tannamuri</td>
<td><a href="https://en.wikipedia.org/wiki/canada">Canada</a></td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td><a href="https://en.wikipedia.org/wiki/italy">Italy</a></td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helen Bennett</td>
<td><a href="https://en.wikipedia.org/wiki/united_kingdom">UK</td>
</tr>
<tr>
<td>Laughing Bacchus Winecellars</td>
<td>Yoshi Tannamuri</td>
<td><a href="https://en.wikipedia.org/wiki/canada">Canada</a></td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td><a href="https://en.wikipedia.org/wiki/italy">Italy</a></td>
</tr>
</table>
<h2>Text</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
`;
function TableRenderer(props) {
const tableProps = useHtmlTableProps(props);
return React.createElement(ClickTable, tableProps);
}
TableRenderer.model = tableModel;
const htmlConfig = {
renderers: {
table: TableRenderer
},
tagsStyles: {
table: {}
},
WebView,
defaultWebViewProps: {}
};
export default function CustomExample({
instance,
onLinkPress,
availableWidth
}) {
return (
<RenderHTML
key={`custom-${instance}`}
provideEmbeddedHeaders={(uri, tagName) => null}
source={{ html: table1 }}
contentWidth={availableWidth}
renderersProps={{
a: { onPress: onLinkPress },
...htmlConfig.renderersProps
}}
debug={false}
/>
);
}