# Viniendo de SwiftUI

> Mapeo View/@State→Component y un formulario reescrito, con la diferencia de destino.

Source: https://crossfly.dev/es/docs/migrate/from-swiftui — CrossFly documentation. Full docs as one file: https://crossfly.dev/llms-full.txt

# Viniendo de SwiftUI

En SwiftUI el `body` se computa y la vista **se invalida** cuando `@State` cambia. En CrossFly tú **montas
una vez** y **mutas**. Lee primero [la filosofía](/docs/migrate/overview).

## Tabla de traducción
| SwiftUI | CrossFly |
|---|---|
| `View` / `body` computado | UI montada **una vez** en `onShow()` |
| `@State` / `@Binding` / `@ObservedObject` | campos + `repaint()` (sin invalidación automática) |
| `VStack` / `HStack` / `ZStack` | `VerticalLayout` / `HorizontalLayout` / `RelativeLayout` |
| `Spacer()` | `Gap` / fracciones (el `Spacer` del framework fue **eliminado**) |
| `.padding()` | `ingap` en el estilo |
| `List` | `VirtualListView` |
| `Text` | `Label` |
| `Button` | `Button` |
| `NavigationStack` / `.sheet` | pila de `Window` / `ActionSheet` |
| `.alert` | `Alert` |
| `async` / `await` / `Task` | `Thread` + `Component.onUI(...)` |
| `Color` | `int 0xAARRGGBB` |

## Diferencia de destino
SwiftUI corre **solo en Apple**. CrossFly es **una base Java** que corre en iOS **y** Android, Escritorio y
Web — el mismo código de pantalla en todos (ver [plataformas](/docs/platforms)).

## Cómo era / cómo queda — formulario
```swift
// SwiftUI
struct LoginView: View {
   @State private var email = ""
   var body: some View {
      VStack {
         TextField("E-mail", text: $email)
         Button("Entrar") { entrar(email) }
      }
   }
}
```
```java
// CrossFly
public class LoginScreen extends Window {
   @Override public void onShow() throws Exception {
      super.onShow();
      setLayout(new VerticalLayout());
      TextField email = new TextField().caption("E-mail");
      add(LAY_AUTO, email);
      Button entrar = new Button("Entrar");
      entrar.onAction(c -> entrar(email.getText()));   // lee el valor al enviar (sin $binding)
      add(LAY_AUTO, entrar);
   }
}
```
> Sin `$binding`: tú **lees `getText()`** cuando lo necesitas (ej.: en el `onAction`), no hay vínculo automático
> campo↔variable (ver [Campos de texto](/docs/ui/forms-and-input/text-fields)).

## Véase también
- [Formularios y entrada](/docs/ui/forms-and-input) · [Navegación](/docs/ui/navigation)
