是否可以在React Native中动态创建和添加视图组件?例如,首先我只有空屏幕,所有视图的信息都来自JSON中的服务器,然后需要在屏幕上生成它们.例如 - 应用程序从服务器获取json.这个json描述了必须构建的屏幕:
{
"type": "linearlayout",
"subviews": [{
"type": "text",
"fields": {
"text": "This is text field"
},
"styles": {
"color": "",
"textSize": 14
}
}, {
"type": "button",
"fields": {
"text": "JUST BUTTON"
},
"transition": {
"name": "http://www.link.com"
}
}, {
"type": "text",
"fields": {
"text": "This is another text field"
},
"styles": {
"color": "",
"textSize": 18
}
}]
}
Run Code Online (Sandbox Code Playgroud)
所以,通过JSON,我需要在React Native中动态构建视图.但我看不到任何在JSX中编写JS代码的能力 - 只有静态视图和动态更改道具
请帮忙!我正在尝试使用jackson kotlin模块从JSON生成对象.这是json来源:
{
"name": "row",
"type": "layout",
"subviews": [{
"type": "horizontal",
"subviews": [{
"type": "image",
"icon": "ic_no_photo",
"styles": {
"view": {
"gravity": "center"
}
}
}, {
"type": "vertical",
"subviews": [{
"type": "text",
"fields": {
"text": "Some text 1"
}
}, {
"type": "text",
"fields": {
"text": "Some text 2"
}
}]
}, {
"type": "vertical",
"subviews": [{
"type": "text",
"fields": {
"text": "Some text 3"
}
}, {
"type": "text",
"fields": {
"text": "Some text 4"
}
}]
}, …Run Code Online (Sandbox Code Playgroud)