Twenty new components

Every app has a few screens that look like every other app. A checkout with a card field and a country picker. A rating at the end of an order. A sign-up that runs over four steps. A row of faces showing who else is in the chat. None of it is hard, and all of it takes an afternoon you’d rather spend on the part of the app that’s actually yours.

This week twenty of those components landed in core. They run on iOS, Android, desktop and the web, take their look from your theme, and each comes with a code sample you can paste. Here are the ones I’d reach for first.

Rating stars, a dial, card, phone and country fields, a date range and slide to pay on iOS

SlideToConfirm: no more accidental purchases

A button is too easy to hit by mistake when the action costs money or deletes something. A slider needs intent: the user drags the knob to the end, and letting go early slides it back.

SlideToConfirm pay = new SlideToConfirm("Slide to pay");
pay.addActionListener(e -> Log.p("Paid"));

Once confirmed it stays at the end and ignores further drags until you call reset(), so a nervous double swipe never pays twice.

CreditCardField and CountryPicker: the checkout form

CreditCardField groups digits the way the card prints them, four by four or 4-6-5 for American Express, detects the brand from the first digits and checks the number with the Luhn checksum as the user types.

CreditCardField card = new CreditCardField();
Button pay = new Button("Pay");
card.addDataChangedListener((type, index) -> pay.setEnabled(card.isValidNumber()));

It only formats and validates. It never stores or sends the number, so hand getNumber() to your payment provider, ideally one that tokenizes it.

CountryPicker is a searchable list of countries with flags, names and dialing codes. Typing filters on any of them, and bindPhoneField keeps a phone field’s prefix in step with the country:

CountryPicker country = new CountryPicker();
country.setSelectedCountryCode("FR");
country.addActionListener(e -> Log.p(country.getSelectedCountryCode() + " " + country.getDialingCode()));

For every other formatted field there’s InputMask. A 9 stands for a digit, an a for a letter, and everything else is inserted for the user:

TextField phone = new TextField();
phone.setInputMask(new InputMask("(999) 999-9999"));
String digits = phone.getInputMask().unmask(phone.getText());

StepFlow: sign-ups and wizards

Multi-step flows are where apps lose people, so they should at least be clear. StepFlow shows numbered markers, a body per step, and Back and Continue buttons. A validator decides whether the user may move on, and a step can be marked as needing attention.

TextField address = new TextField("", "Address");
StepFlow flow = new StepFlow()
        .addStep("Shipping", "Where it goes", address)
        .addStep("Payment", null, new Label("Card on file"))
        .addStep("Review", null, new Label("Everything looks right"));
flow.setStepValidator((f, step) -> step != 0 || address.getText().length() > 0);
flow.addFinishListener(e -> Log.p("Order placed"));

It lays out horizontally, as a checkout does, or vertically with the body under each step, as a setup screen does.

StepFlow horizontally for a checkout and vertically with a step that needs attention

SwipeDeck: cards you swipe away

Dating apps made it famous, but a swipe deck works just as well for flash cards, triaging a queue or picking recipes. The top card follows the finger and tilts with the drag. Released past a third of the width, it flies off that side.

SwipeDeck deck = new SwipeDeck();
deck.addCard(new Label("First"));
deck.addCard(new Label("Second"));
deck.addCard(new Label("Third"));
deck.setSwipeListener((card, direction) ->
        Log.p(direction == SwipeDeck.RIGHT ? "Liked" : "Passed"));

Turn on swiping up with setUpEnabled(true), and drive it from buttons with swipeLeft() and swipeRight() for users who don’t swipe.

RatingBar and CircularSlider: picking a value

RatingBar shows any fraction, so an average of 4.3 paints 4.3 stars, and rounds what the user picks to whole or half stars:

RatingBar rating = new RatingBar(5);
rating.setValue(3.5f);
rating.addActionListener(e -> Log.p("Rated " + rating.getValue()));

CircularSlider is the dial of a thermostat or a volume knob. A tap or drag anywhere on it moves the thumb to the nearest point of the arc, and the arc itself is yours to set:

CircularSlider dial = new CircularSlider(0, 100);
dial.setValue(40);
dial.addActionListener(e -> Log.p("Value " + dial.getValue()));

Avatars, banners and pages

An avatar group with a presence dot, breadcrumbs, a paginator, a banner and a split button

Avatar shows a photo cropped to a circle, or initials on a colour derived from the name, so a person keeps the same colour everywhere. AvatarGroup overlaps a few and shows “+3” for the rest:

AvatarGroup group = new AvatarGroup(4);
for (String name : new String[] {"Ada Lovelace", "Grace Hopper", "Alan Turing"}) {
    group.addAvatar(new Avatar(name, null));
}

Banner is a message inside the page, with actions and a close button, for things the user should see but shouldn’t have to dismiss a dialog for:

Banner offline = new Banner("You are offline. Changes are saved on this device.");
offline.addAction("Retry", e -> Log.p("Retry"));
offline.setDismissible(true);

Paginator handles long result lists, with the first and last pages always visible and the gaps shown as an ellipsis. Breadcrumbs shows where the user is in a deep hierarchy. SplitButton puts a main action next to an arrow that opens the alternatives, the way “Save” and “Save as” belong together.

Small touches that make an app feel finished

Some components exist only to make an app feel alive, and they’re the ones users notice:

  • AnimatedNumber counts up or down to each new value, fast at first and slowing at the end. A balance that rolls to its new total feels better than one that jumps.
  • TypewriterLabel types its text out a character at a time, and a tap shows the rest.
  • IconMorph turns one material icon into another, menu into back arrow, play into pause.
  • Confetti.burst(form) celebrates a finished order or a completed lesson, then cleans up after itself in about three seconds.
AnimatedNumber total = new AnimatedNumber();
total.setPrefix("$");
total.setDecimals(2);
total.setValue(1249.5);

IconMorph play = new IconMorph(FontImage.MATERIAL_PLAY_ARROW, FontImage.MATERIAL_PAUSE);
Button finish = new Button("Finish");
finish.addActionListener(e -> Confetti.burst(finish.getComponentForm()));

Images: crop and zoom

ImageViewer gained a crop mode, with a rectangle the user moves and resizes over the picture, the step every profile photo upload needs. PinchZoom and ZoomContainer bring the same pinch and pan to any component, not just images.

Try them

All twenty are in core and documented in the developer guide. Generate a project in the Initializr, or point your agent at our llms.txt and ask for a checkout screen with a card field, a country picker and slide to pay. That’s the end of this week’s series. Start back at a server for a dollar a month if you missed it.