本页面由葡萄牙语机器翻译,可能存在错误。葡萄牙语版本为准。
从 React Native 迁移
在 RN 中你用 JSX 描述 UI,状态变化时会发生重新渲染。在 CrossFly 中 UI 是 装配一次的 Java 代码,你变更它。请先阅读 理念。
转换表
| React Native | CrossFly |
|---|---|
| 函数组件 + JSX | 在 onShow() 中装配的 Window/Component 子类(无标记语言) |
useState / 重新渲染 |
字段 + repaint() |
props |
构造函数参数(无路由表) |
<View> / <Text> / <Image> |
Component / Label / ImageView |
<FlatList> |
VirtualListView |
flexbox(flex: 1) |
add(LAY_FILL, c) + VerticalLayout/HorizontalLayout |
StyleSheet |
ComponentStyle / Skin(ingap/outgap = 内边距/外边距) |
react-navigation |
Window 栈(show() / hide()) |
useEffect / Promise / async |
Thread + Component.onUI(...) |
AsyncStorage |
无对应项 → SQLite 或 Device.homeFolder 中的文件 |
之前/之后——列表
// React Native
function Lista({ itens }) {
return <FlatList data={itens}
renderItem={({ item }) => <Text>{item.nome}</Text>} />;
}
// CrossFly — props 变成构造函数参数;UI 用 Java 编写
public class Lista extends Window {
private final List<Item> itens;
public Lista(List<Item> itens) { this.itens = itens; } // "props"
@Override public void onShow() throws Exception {
super.onShow();
setLayout(new VerticalLayout());
add(LAY_FILL, new VirtualListView(Relative.ofFont(3f), new DataAdapter() {
public int getCount() { return itens.size(); }
public Component createView() { return new Label(""); }
public void bindView(Component v, int i) { ((Label) v).setText(itens.get(i).nome); }
}));
}
}
变化最大的地方
- 没有 JS 桥接 且没有热重载——这是编译后的 Java(在桌面端循环很快;参见 平台)。
- **
props→ 构造函数:**通过new Tela(dados)传递数据并调用.show()。 - **
StyleSheet→ComponentStyle:**内边距/外边距是ingap/outgap,不是 flex 属性。
另请参阅
这个页面有帮助吗?感谢你的反馈!