1 | import * as visitor from './react-native/block.js'
|
2 | import getStyleForProperty from './react-native/get-style-for-property.js'
|
3 | import getStyles from './react-native/get-styles.js'
|
4 | import getValueForProperty from './react-native/get-value-for-property.js'
|
5 | import maybeUsesTextInput from './react-native/maybe-uses-text-input.js'
|
6 | import maybeUsesRouter from './react-native/maybe-uses-router.js'
|
7 | import maybeUsesStyleSheet from './react-native/maybe-uses-style-sheet.js'
|
8 | import restrictedNames from './react-native/restricted-names.js'
|
9 | import toComponent from './react/to-component.js'
|
10 | import walk from './walk.js'
|
11 |
|
12 | const imports = {
|
13 | DismissKeyboard: `import dismissKeyboard from 'dismissKeyboard'`,
|
14 | Link: "import { Link } from 'react-router-native'",
|
15 | Route: "import { Route } from 'react-router-native'",
|
16 | Router: "import { NativeRouter as Router } from 'react-router-native'",
|
17 | }
|
18 |
|
19 | export default ({ file, getImport, name, track = true, views }) => {
|
20 | const finalName = restrictedNames.includes(name) ? `${name}1` : name
|
21 | if (name !== finalName) {
|
22 | console.warn(
|
23 | `// "${name}" is a Views reserved name.
|
24 | We've renamed it to "${finalName}", so your view should work but this isn't ideal.
|
25 | To fix this, change its file name to something else.`
|
26 | )
|
27 | }
|
28 |
|
29 | const state = {
|
30 | captures: [],
|
31 | defaultProps: false,
|
32 | images: [],
|
33 | getStyleForProperty,
|
34 | getValueForProperty,
|
35 | isReactNative: true,
|
36 | name: finalName,
|
37 | remap: {},
|
38 | render: [],
|
39 | styles: {},
|
40 | svgs: [],
|
41 | testIdKey: 'testID',
|
42 | testIds: {},
|
43 | track,
|
44 | uses: [],
|
45 | use(block) {
|
46 | if (
|
47 | state.uses.includes(block) ||
|
48 | /props/.test(block) ||
|
49 | block === finalName
|
50 | )
|
51 | return
|
52 |
|
53 | state.uses.push(block)
|
54 | },
|
55 | withRouter: false,
|
56 | }
|
57 |
|
58 | const parsed = views[name]
|
59 | state.fonts = parsed.fonts
|
60 |
|
61 | walk(parsed.views[0], visitor, state)
|
62 |
|
63 | maybeUsesTextInput(state)
|
64 | maybeUsesRouter(state)
|
65 | maybeUsesStyleSheet(state)
|
66 |
|
67 | const finalGetImport = name => imports[name] || getImport(name)
|
68 |
|
69 | return {
|
70 | code: toComponent({
|
71 | getImport: finalGetImport,
|
72 | getStyles,
|
73 | name: finalName,
|
74 | state,
|
75 | }),
|
76 | fonts: parsed.fonts,
|
77 | props: parsed.props,
|
78 | svgs: state.svgs,
|
79 | }
|
80 | }
|