Skip to content

Login screen in SwiftUI, Flutter, React Native and HTML/CSS

A complete login screen in all four targets, with every layout number explained.

Open in editor

A login screen is the smallest screen that still has every awkward part of a real one: a heading, two text fields (one of them secure), a text link, and a button that has to do something. We drew this one once on the canvas at 390 by 844 (an iPhone 14) and exported it to all four targets. The code below is the generator's output, unedited.

What we drew

Every number below is a choice, and every one of them appears literally in the code.

ElementPositionSizeNotes
Title, "Welcome back"x 24, y 120342 x 3628px, bold
Subtitlex 24, y 164342 x 2215px, grey
Email fieldx 24, y 232342 x 481px border, radius 12, email keyboard
Password fieldx 24, y 296342 x 48same, secure entry
"Forgot password?"x 24, y 360160 x 2014px, medium
Sign in buttonx 24, y 412342 x 52radius 14, label centred, calls handleSignIn

The side margin is 24 and the content width is 342, so the right margin is also 24 (24 + 342 + 24 = 390). Fields are 48 tall and the button is 52, which keeps both comfortably above the 44-point minimum touch target Apple recommends. The gap between the two fields is 16 (280 to 296).

React Native

Placement is a literal left and top on each style. The button and its label sit inside one Pressable, so tapping the label presses the button.

import React from 'react';
import { View, Text, Pressable, TextInput, StyleSheet } from 'react-native';

export default function Login() {
  const handleSignIn = () => {};

  return (
    <View style={styles.screen}>
      <Text style={styles.title}>{"Welcome back"}</Text>
      <Text style={styles.subtitle}>{"Sign in to pick up where you left off."}</Text>
      <TextInput style={styles.email} placeholder={"Email"} placeholderTextColor="#9ca3af" keyboardType="email-address" />
      <TextInput style={styles.password} placeholder={"Password"} placeholderTextColor="#9ca3af" secureTextEntry />
      <Text style={styles.forgot}>{"Forgot password?"}</Text>
      <Pressable onPress={handleSignIn} style={({ pressed }) => [styles.group, pressed && styles.pressed]}>
        <View style={styles.signIn} />
        <View style={styles.signInLabel}><Text style={styles.signInLabelText}>{"Sign in"}</Text></View>
      </Pressable>
    </View>
  );
}

const styles = StyleSheet.create({
  screen: {
    flex: 1,
    backgroundColor: '#ffffff',
  },
  title: {
    position: 'absolute',
    left: 24,
    top: 120,
    width: 342,
    height: 36,
    color: '#17171A',
    fontFamily: 'Inter',
    fontSize: 28,
    lineHeight: 36,
    textAlign: 'left',
    fontWeight: '700',
  },
  subtitle: {
    position: 'absolute',
    left: 24,
    top: 164,
    width: 342,
    height: 22,
    color: '#5B5B63',
    fontFamily: 'Inter',
    fontSize: 15,
    lineHeight: 21,
    textAlign: 'left',
  },
  email: {
    position: 'absolute',
    left: 24,
    top: 232,
    width: 342,
    height: 48,
    backgroundColor: '#ffffff',
    color: '#17171A',
    fontFamily: 'Inter',
    fontSize: 16,
    paddingHorizontal: 12,
    textAlign: 'left',
    borderRadius: 12,
    borderWidth: 1,
    borderColor: '#E4E1D8',
  },
  password: {
    position: 'absolute',
    left: 24,
    top: 296,
    width: 342,
    height: 48,
    backgroundColor: '#ffffff',
    color: '#17171A',
    fontFamily: 'Inter',
    fontSize: 16,
    paddingHorizontal: 12,
    textAlign: 'left',
    borderRadius: 12,
    borderWidth: 1,
    borderColor: '#E4E1D8',
  },
  forgot: {
    position: 'absolute',
    left: 24,
    top: 360,
    width: 160,
    height: 20,
    color: '#2A50D8',
    fontFamily: 'Inter',
    fontSize: 14,
    lineHeight: 18,
    textAlign: 'left',
    fontWeight: '500',
  },
  group: {
    position: 'absolute',
    left: 24,
    top: 412,
    width: 342,
    height: 52,
  },
  signIn: {
    position: 'absolute',
    left: 0,
    top: 0,
    width: 342,
    height: 52,
    borderRadius: 14,
    backgroundColor: '#2A50D8',
  },
  signInLabel: {
    position: 'absolute',
    left: 0,
    top: 0,
    width: 342,
    height: 52,
    justifyContent: 'center',
  },
  signInLabelText: {
    color: '#ffffff',
    fontFamily: 'Inter',
    fontSize: 16,
    lineHeight: 21,
    textAlign: 'center',
    fontWeight: '600',
  },
  pressed: {
    opacity: 0.6,
  },
});

What this does not do

This is a layout, and the generated code is honest about that:

  • No logic. handleSignIn is an empty function. Calling your auth API, validating the email and showing errors are yours to add. The fields are uncontrolled in React Native and Flutter, and bound to throwaway state in SwiftUI.
  • Fixed size. The screen is 390 by 844 and does not reflow. On a smaller or larger phone you would draw another screen at that size.
  • No keyboard avoidance. Nothing moves when the keyboard opens. If your layout needs that, wrap the screen in your platform's keyboard-avoiding view.
  • Fonts by name. The code asks for Inter by family name and does not embed the font file, so add it to your project (the HTML export links it from Google Fonts).

Make your own

Open the editor, change any number, and the four files above change with it. What you can build lists every control and property the canvas supports, limits included.