Skip to content

Commit 103b505

Browse files
committed
Component render recognizes when Native is a child type and will look for different cases in the switch related to imported Native components
1 parent 7a3f740 commit 103b505

File tree

2 files changed

+20
-35
lines changed

2 files changed

+20
-35
lines changed

src/helperFunctions/importNativeGeneartor.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/utils/componentRender.util.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
PropInt
77
} from '../interfaces/Interfaces';
88
import cloneDeep from '../helperFunctions/cloneDeep';
9+
import { nativeComponentTypes } from '../reducers/initialState';
10+
import importNativeNameGenerator from '../helperFunctions/importNativeGenerator';
911

1012
const componentRender = (
1113
component: ComponentInt,
@@ -77,7 +79,7 @@ const componentRender = (
7779
.props.map((prop: PropInt) => `${prop.key}={${prop.value}}`)
7880
.join(' ');
7981
}
80-
if (child.childType === 'HTML') {
82+
if (child.childType === 'HTML' || child.childType === 'NATIVE') {
8183
const keys: string[] = Object.keys(child.HTMLInfo);
8284
return keys
8385
.map(key => {
@@ -118,6 +120,11 @@ const componentRender = (
118120
return 'p';
119121
// REACT NATIVE COMPONENTS
120122
// TO DO: UPDATE REDUCER LOGIC TO HAVE THESE COMPONENTS IN A SEPARATE FUNCTION
123+
default:
124+
return 'div';
125+
}
126+
} else if (child.childType === 'NATIVE') {
127+
switch (child.componentName) {
121128
case 'RNView':
122129
return 'View';
123130
case 'RNSafeAreaView':
@@ -145,6 +152,7 @@ const componentRender = (
145152
return child.componentName;
146153
}
147154
}
155+
148156
// logic below consists of conditional that will render depending
149157
// on the toggling of "state" and/or "class"
150158
// class components can optioally have a state which will
@@ -157,10 +165,14 @@ const componentRender = (
157165
158166
${childrenArray
159167
.filter(child => child.childType !== 'HTML')
160-
.map(
161-
child =>
162-
`import ${child.componentName} from './${child.componentName}.tsx'`
163-
)
168+
.map(child => {
169+
if (child.childType === 'NATIVE') {
170+
return `import {${importNativeNameGenerator(
171+
child
172+
)}} from 'react-native'`;
173+
} else
174+
`import ${child.componentName} from './${child.componentName}.tsx'`;
175+
})
164176
.reduce((acc: Array<string>, child) => {
165177
if (!acc.includes(child)) {
166178
acc.push(child);
@@ -169,6 +181,8 @@ const componentRender = (
169181
return acc;
170182
}, [])
171183
.join('\n')}
184+
185+
172186
173187
interface Props {
174188
${props.map(prop => `${prop.key}: ${typeSwitcher(prop.type)}\n`)}
@@ -212,9 +226,7 @@ const componentRender = (
212226
return `
213227
<${componentNameGenerator(child)} ${propDrillTextGenerator(
214228
child
215-
)}>${
216-
/*child.HTMLInfo.value*/ `GGGGGGG`
217-
}</${componentNameGenerator(child)}>`;
229+
)}>${child.HTMLInfo.value}</${componentNameGenerator(child)}>`;
218230
}
219231
// code to be rendered for all self closing component/elements
220232
else

0 commit comments

Comments
 (0)