Skip to content
CrossFly is 100% open sourceFollow us on GitHub
CrossFlyCrossFly
Get started
All examples
RecipesNavigationOverlays71 lines · 1 files

Bottom sheet with a fixed footer

BottomSheet already gives you the header, the grabber, the close button and a footer that floats over the scroll. You only fill body().

What this shows

A bottom sheet with a header and a footer that stay put while the middle scrolls.

Run it on your machine

Every example is a plain Window, so the launcher only needs its name.

gradlew lwjgl3:run --args="classname dev.cf.recipe.R04Sheet"
Editing it

Java is compiled ahead of time, so the browser cannot rebuild an edit on its own — the code you see here was turned into JavaScript by TeaVM before it was published. Copy the file into a project and it runs unchanged on all four platforms; the command above is the whole setup.

Running hereCrossFly 0.1.32
Starting the app…

Compiled to WebAssembly-era JavaScript by TeaVM — the same code, not a video of it. · All examples

What it uses

Framework types this example touches. The linked ones have a reference page.

BottomSheetButtonComponentDebugGridLayoutStylesWidgets

The source

Complete and unabridged. This is the file, not an excerpt of it.

Raw
dev/cf/recipe/R04Sheet.java
package dev.cf.recipe;

import dev.cf.Tones;

import dev.crossfly.ui.*;
import dev.crossfly.ui.color.*;
import dev.crossfly.ui.graphics.*;
import dev.crossfly.ui.layout.*;
import dev.crossfly.ui.style.*;

import static dev.crossfly.ui.Widgets.*;

/**
 * A bottom sheet with a header and a footer that stay put while the middle scrolls.
 */
public class R04Sheet extends Recipe
{
   public String title()
   {
      return "Bottom sheet with a fixed footer";
   }

   public String note()
   {
      return "BottomSheet already gives you the header, the grabber, the close button and a footer"
         + " that floats over the scroll. You only fill body().";
   }

   public void build(Component body) throws Exception
   {
      Button abrir = Tones.action("Open the sheet");
      abrir.testTag("recipe.open");
      abrir.onAction(c -> abrirSheet());
      body.add(LAY_AUTO, abrir);
   }

   private void abrirSheet()
   {
      try
      {
         // The kicker is the small upper-case label above the title.
         final BottomSheet sheet = new BottomSheet("FILTER", "Choose a segment");
         sheet.maxHeightRatio(.7f);

         for (int i = 1; i <= 20; i++)
         {
            // A tonal pill per segment: twenty identical grey lines is a list nobody can aim at.
            Component linha = new Component();
            linha.setLayout(new GridLayout(Position.START, Position.CENTER));
            linha.add(LAY_AUTO, LAY_AUTO, Tones.tile(0xE574, Tones.cycle(i)),
               outgap(label("Segment " + i, 1f, false, Styles.textColor, Position.START),
                  .6f, 0, 0, 0));
            sheet.body()
               .add(LAY_AUTO, outgap(linha, 0, .3f, 0, .3f));
         }

         // The footer does NOT go into the body: it floats over the scroll and stays reachable with
         // the list at its end — which is why it has an API of its own.
         Button aplicar = Tones.action("Apply");
         aplicar.onAction(c -> sheet.hide());
         sheet.footer(aplicar);

         sheet.show();
      }
      catch (Exception e)
      {
         dev.crossfly.util.Debug.handle(e);
      }
   }
}
For an AI assistant

Machine-readable versions of this page, so a model can read the shelf instead of guessing at the API.

This example, as JSONThis example, as Markdown
PreviousSwitching skinsNextListing: cards or table