1
- import React , { createElement } from 'react' ;
1
+ import { createElement } from 'react' ;
2
2
import { View , Text , Button , TextInput , StyleSheet , Image } from 'react-native' ;
3
3
4
- let textNode = 1 ,
5
- elementNode = 2 ,
6
- svgNode = 3 ,
7
- lazyNode = 5 ,
8
- managedNode = 6 ;
9
4
let styleData = 1 ,
10
5
classData = 2 ,
11
6
propertyData = 3 ,
12
7
attributeData = 4 ,
13
8
keyData = 7 ;
14
9
10
+ let initialStyles = StyleSheet . create ( {
11
+ hr : {
12
+ borderBottomColor : 'black' ,
13
+ borderBottomWidth : StyleSheet . hairlineWidth ,
14
+ } ,
15
+ table : {
16
+ flexDirection : 'column'
17
+ } ,
18
+ tr : {
19
+ flexDirection : 'row' ,
20
+ justifyContent : 'space-between'
21
+ } ,
22
+ b : {
23
+ fontWeight : 'bold'
24
+ }
25
+ } ) ;
15
26
16
27
export function createViewNode ( nodeData ) {
17
28
return function ( children ) {
@@ -24,28 +35,52 @@ export function createViewNode(nodeData) {
24
35
export function createButtonNode ( nodeData ) {
25
36
return function ( children ) {
26
37
let props = fromNodeData ( nodeData )
38
+ props . title = children [ 0 ] ;
27
39
28
- return createElement ( Button , { title : children [ 0 ] , ... props } ) ;
40
+ return createElement ( Button , props ) ;
29
41
}
30
42
}
31
43
32
- let initialHrStyle = {
33
- borderBottomColor : 'black' ,
34
- borderBottomWidth : StyleSheet . hairlineWidth ,
35
- } ;
36
-
37
44
export function createHrNode ( nodeData ) {
38
45
let props = fromNodeData ( nodeData ) ;
39
46
40
47
if ( props . style === undefined )
41
- props . style = { ... initialHrStyle } ;
48
+ props . style = [ initialStyles . hr ] ;
42
49
else {
43
- props . style = { ... initialHrStyle , ... props . style } ;
50
+ props . style = [ initialStyles . hr , props . style ] ;
44
51
}
45
52
46
53
return createViewNode ( nodeData ) ( undefined ) ;
47
54
}
48
55
56
+ export function createTableNode ( nodeData ) {
57
+ return function ( children ) {
58
+ let props = fromNodeData ( nodeData ) ;
59
+
60
+ if ( props . style === undefined )
61
+ props . style = [ initialStyles . table ] ;
62
+ else {
63
+ props . style = [ initialStyles . table , props . style ] ;
64
+ }
65
+
66
+ return createElement ( View , props , ...children ) ;
67
+ }
68
+ }
69
+
70
+ export function createTrNode ( nodeData ) {
71
+ return function ( children ) {
72
+ let props = fromNodeData ( nodeData ) ;
73
+
74
+ if ( props . style === undefined )
75
+ props . style = [ initialStyles . tr ] ;
76
+ else {
77
+ props . style = [ initialStyles . tr , props . style ] ;
78
+ }
79
+
80
+ return createElement ( View , props , ...children ) ;
81
+ }
82
+ }
83
+
49
84
export function createLabelNode ( nodeData ) {
50
85
return function ( children ) {
51
86
let props = fromNodeData ( nodeData ) ,
@@ -95,18 +130,14 @@ export function createANode(nodeData) {
95
130
}
96
131
}
97
132
98
- let initialBStyle = {
99
- fontWeight : 'bold'
100
- } ;
101
-
102
133
export function createBNode ( nodeData ) {
103
134
return function ( children ) {
104
135
let props = fromNodeData ( nodeData ) ;
105
136
106
137
if ( props . style === undefined )
107
- props . style = { ... initialBStyle } ;
138
+ props . style = [ initialStyles . b ] ;
108
139
else {
109
- props . style = { ... initialBStyle , ... props . style } ;
140
+ props . style = [ initialStyles . b , props . style ] ;
110
141
}
111
142
112
143
let propedChildren = [ ] ;
@@ -133,11 +164,9 @@ export function text(value) {
133
164
}
134
165
135
166
function fromNodeData ( allData ) {
136
- let nodeData ;
137
-
138
- if ( allData !== undefined ) {
139
- nodeData = { } ;
167
+ let nodeData = { } ;
140
168
169
+ if ( allData !== undefined )
141
170
for ( let data of allData ) {
142
171
let dataOne = data [ 1 ] ;
143
172
//[0] also always contain the data type
@@ -162,7 +191,6 @@ function fromNodeData(allData) {
162
191
nodeData [ dataOne ] = data [ 2 ] ;
163
192
}
164
193
}
165
- }
166
194
167
195
return nodeData ;
168
196
}
0 commit comments