1
1
import { createElement } from 'react' ;
2
- import { View , Text , Button , TextInput , StyleSheet , Image } from 'react-native' ;
2
+ import { View , Text , TouchableOpacity , TextInput , StyleSheet , Image } from 'react-native' ;
3
3
4
4
let styleData = 1 ,
5
5
classData = 2 ,
@@ -24,36 +24,50 @@ let initialStyles = StyleSheet.create({
24
24
25
25
export function createViewNode ( nodeData ) {
26
26
return function ( children ) {
27
- let props = fromNodeData ( nodeData )
27
+ let props = toProps ( nodeData )
28
28
29
29
return createElement ( View , props , ...children ) ;
30
30
} ;
31
31
}
32
32
33
+ let noop = ( ) => { } ;
34
+
33
35
export function createButtonNode ( nodeData ) {
34
36
return function ( children ) {
35
- let props = fromNodeData ( nodeData )
36
- props . title = children [ 0 ] ;
37
+ let props = toProps ( nodeData ) ,
38
+ title = children [ 0 ]
39
+ onPress = noop ,
40
+ disabled = false ;
41
+
42
+ if ( props . disabled ) {
43
+ disabled = true ;
44
+ delete props . disabled ;
45
+ }
37
46
38
- return createElement ( Button , props ) ;
47
+ if ( props . onPress ) {
48
+ onPress = props . onPress ;
49
+ delete props . onPress ;
50
+ }
51
+
52
+ return createElement ( TouchableOpacity , { onPress, disabled } , createElement ( View , props , createElement ( Text , props , title . toUpperCase ( ) ) ) ) ;
39
53
}
40
54
}
41
55
42
56
export function createHrNode ( nodeData ) {
43
- let props = fromNodeData ( nodeData ) ;
57
+ let props = toProps ( nodeData ) ;
44
58
45
59
if ( props . style === undefined )
46
60
props . style = [ initialStyles . hr ] ;
47
61
else {
48
62
props . style = [ initialStyles . hr , props . style ] ;
49
63
}
50
64
51
- return createViewNode ( nodeData ) ( undefined ) ;
65
+ return createElement ( View , props , undefined ) ;
52
66
}
53
67
54
68
export function createTableNode ( nodeData ) {
55
69
return function ( children ) {
56
- let props = fromNodeData ( nodeData ) ;
70
+ let props = toProps ( nodeData ) ;
57
71
58
72
if ( props . style === undefined )
59
73
props . style = [ initialStyles . table ] ;
@@ -67,7 +81,7 @@ export function createTableNode(nodeData) {
67
81
68
82
export function createTrNode ( nodeData ) {
69
83
return function ( children ) {
70
- let props = fromNodeData ( nodeData ) ;
84
+ let props = toProps ( nodeData ) ;
71
85
72
86
if ( props . style === undefined )
73
87
props . style = [ initialStyles . tr ] ;
@@ -81,56 +95,47 @@ export function createTrNode(nodeData) {
81
95
82
96
export function createLabelNode ( nodeData ) {
83
97
return function ( children ) {
84
- let props = fromNodeData ( nodeData ) ,
98
+ let props = toProps ( nodeData ) ,
85
99
propedChildren = [ ] ;
86
100
87
101
for ( let c of children ) {
88
- let txt = text ( c ) ;
89
- txt . props = props ;
90
-
91
- propedChildren . push ( txt ) ;
102
+ propedChildren . push ( createElement ( Text , props , c ) ) ;
92
103
}
93
104
94
105
return createViewNode ( undefined ) ( propedChildren ) ;
95
106
}
96
107
}
97
108
98
109
export function createBrNode ( nodeData ) {
99
- let txt = text ( '\n' ) ;
100
- txt . props = fromNodeData ( nodeData ) ;
101
-
102
- return txt ;
110
+ return createElement ( Text , toProps ( nodeData ) , '\n' ) ;
103
111
}
104
112
105
113
export function createInputNode ( nodeData ) {
106
- let props = fromNodeData ( nodeData ) ;
114
+ let props = toProps ( nodeData ) ;
107
115
108
116
if ( props . type === 'button' || props . type === 'submit' ) {
109
- return createElement ( Button , { title : props . value || "" , ... props } )
117
+ return createButtonNode ( nodeData ) ( [ props . value || "" ] ) ;
110
118
}
111
119
112
120
return createElement ( TextInput , props ) ;
113
121
}
114
122
115
123
export function createANode ( nodeData ) {
116
124
return function ( children ) {
117
- let props = fromNodeData ( nodeData ) ,
125
+ let props = toProps ( nodeData ) ,
118
126
propedChildren = [ ] ;
119
127
120
128
for ( let c of children ) {
121
- let txt = text ( c ) ;
122
- txt . props = props ;
123
-
124
- propedChildren . push ( txt ) ;
129
+ propedChildren . push ( createElement ( Text , props , c ) ) ;
125
130
}
126
131
127
- return createViewNode ( undefined ) ( propedChildren ) ;
132
+ return createElement ( View , undefined , ... propedChildren ) ;
128
133
}
129
134
}
130
135
131
136
export function createBNode ( nodeData ) {
132
137
return function ( children ) {
133
- let props = fromNodeData ( nodeData ) ;
138
+ let props = toProps ( nodeData ) ;
134
139
135
140
if ( props . style === undefined )
136
141
props . style = [ initialStyles . b ] ;
@@ -141,18 +146,15 @@ export function createBNode(nodeData) {
141
146
let propedChildren = [ ] ;
142
147
143
148
for ( let c of children ) {
144
- let txt = text ( c ) ;
145
- txt . props = props ;
146
-
147
- propedChildren . push ( txt ) ;
149
+ propedChildren . push ( createElement ( Text , props , c ) ) ;
148
150
}
149
151
150
- return createViewNode ( undefined ) ( propedChildren ) ;
152
+ return createElement ( View , undefined , ... propedChildren ) ;
151
153
}
152
154
}
153
155
154
156
export function createImageNode ( nodeData ) {
155
- let props = fromNodeData ( nodeData ) ;
157
+ let props = toProps ( nodeData ) ;
156
158
157
159
return createElement ( Image , props ) ;
158
160
}
@@ -161,7 +163,7 @@ export function text(value) {
161
163
return createElement ( Text , undefined , value ) ;
162
164
}
163
165
164
- function fromNodeData ( allData ) {
166
+ function toProps ( allData ) {
165
167
let nodeData = { } ;
166
168
167
169
if ( allData !== undefined )
0 commit comments