跳到内容
CrossFly 是 100% 开源在 GitHub 关注我们
CrossFlyCrossFly
开始使用
示例

三十八个可以 就地运行的界面

四个完整应用和三十四个配方,全部在浏览器中运行,用的就是发布到 Android、iOS、桌面端(Windows、macOS 和 Linux)和网页的同一份 Java 代码。旁边就是源码,复制走即可继续。

4
示例应用
34
配方
4
个平台,一份代码

正在此处运行

由 TeaVM 编译为 JavaScript —— 是同一份代码,不是录像。

WindowGridLayoutSkinSqliteDbTeaVM
正在此处运行CrossFly 0.1.32
正在启动应用…

由 TeaVM 编译为 JavaScript —— 是同一份代码,不是录像。

主题
配方93 行
Layouts

Any Component becomes a container with setLayout. The same three labels, three ways.

布局
配方65 行
Theme tokens

Flip the switch. The token line follows the theme; the hardcoded one does not, and turns unreadable — no rebuild involved.

主题
配方76 行
Switching skins

Shape, radius, padding and typeface all come from the skin. Nothing below knows which one is in force.

主题
配方71 行
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().

导航浮层
配方113 行
Listing: cards or table

A card answers "what is this one?"; a row answers "how do these compare?". Which one the reader needs changes during the day, so Listing lets them switch.

列表
配方81 行
Choosing from a list

ListViewWindow does single and multi selection, with the title, the confirm and the tap-to-choose already wired.

列表输入
配方123 行
Picking a date range

DatePicker answers "which day". This answers "between which two", which has its own rules — and its own ways of being wrong.

输入
配方65 行
Reordering a list

The first row has no up arrow and the last has no down arrow — hidden, not removed, so the column does not jitter as rows move.

列表
配方77 行
Making a screen testable

Tag anything a test must reach. Text breaks on rewording, class breaks on a second instance, index breaks on insertion — a tag breaks only when someone removes it.

测试
配方84 行
A form that fights back

setMode does most of the work: it picks the keyboard, the mask and the validation together. A regex on the way out only tells the user they already got it wrong.

表单输入
配方97 行
Telling the user something

Interrupt in proportion to what you need back. A confirmation on something reversible teaches people to dismiss confirmations — including the one that mattered.

反馈
配方65 行
Bottom nav that becomes a rail

One flag — tabsAtBottom — and the strip is a bottom bar on a phone and a rail on a tablet. Resize the window to see it happen.

导航布局
配方131 行
Waiting

Known length gets a bar. Unknown gets a spinner. A finished measurement — a share, a score — gets a ring, and that one is not waiting at all.

反馈
配方80 行
Cards that reflow

Tell CardGrid the width a card wants, not how many columns to use. Resize the window — the reflow is the framework's, not yours.

布局
配方97 行
A header that collapses

header() scrolls away, pinned() never does. Put the identity in the first and the control the reader needs at row 200 in the second.

布局列表
配方102 行
Charts

autoThemeColors themes the axes, grid and background — but NOT the series. A series left at colour 0 falls back to a library grey, and becomes the one thing on screen ignoring your brand.

图表
配方110 行
A list too big to build

createView is rare, bindView is constant. Anything slow in bindView — a query, a request, an allocation — is felt directly as stutter while scrolling.

列表性能
配方154 行
Storing something

Add a few notes and reopen the recipe — they are still there. The same code runs on desktop, Android, iOS and the web.

数据
配方188 行
Capturing a signature

White pad, not the theme surface: the image is captured to be printed. Under dark mode a themed pad captures white ink on navy, which is unusable downstream.

输入绘制
配方84 行
Pickers

show(answer -> …) on all of them, and answer is null when the user backed out. The ones needing hardware live in R21, and the system file picker in R31 — those can be refused.

输入
配方244 行
Camera, barcode and GPS

Ask whether the device HAS it before offering it. PlatformUtils.isSupported answers per capability, at runtime — never a check on which platform this is.

设备
配方162 行
Animation

Styles.animationDuration is the house value — match it, so the app moves at one speed. Anything the user waits through twice was too long the first time.

动画
配方119 行
Painting your own

A component is a rectangle that can draw. width/height are yours, getAutoHeight says how much room you want, and onPaint puts something in it.

绘制
配方90 行
Floating action button

It floats over the content, so leave room at the bottom of the list — bottomInset is what stops it covering the last row nobody can then scroll past.

导航
配方124 行
A map with pins

OSM needs no API key, so a map works the moment you write it. Opens in a window of its own — a native view inside a scrolling page floats over everything around it.

设备
配方97 行
Images

Decode once, keep the Image, reuse it. Loading inside onPaint or inside a list's bind step is what makes scrolling stutter where the pictures are.

图片
配方110 行
Keyboard and focus

Tab follows the order you ADDED the fields, not where they ended up on screen. Build in reading order and the tab order is correct without being designed.

输入
配方161 行
Writing your own component

Search dev/crossfly/ui first — most of what you are about to write is already there. When it genuinely is not, this is the shape.

自定义组件
配方129 行
Brand and dark mode

One seed generates the whole palette, for both themes. Nothing below names a colour, which is why the switch needs no rebuild.

主题
配方160 行
Empty, loading and broken

Three of these are usually left to render as blank space. Blank space reads as a bug, never as an answer.

反馈列表
配方249 行
Files, sharing and printing

Ask the capability, not the platform. Phones, Windows 10+ and the Mac have the picker and the share sheet; Linux has no share sheet; a browser has the picker always and the sheet only sometimes. Printing takes a PDF, and every platform's own dialog does the rest.

设备
配方284 行
Video playback

A native surface over the canvas, like the map. Ask the capability first: all five platforms have it now, and one that does not says so instead of showing black.

设备media
配方120 行
Embedded web page

A native browser over the canvas, at this component's rect. On the web it is an <iframe>, and script only reaches a page from your own origin.

设备media
配方402 行
Reading an odometer (OCR)

Show a strip, read the strip. The viewfinder is only as tall as the digits, and the recognizer gets that band and nothing else — so the speedometer and the trip meter around it never compete with the number.

设备
应用2025 行
Depot — offline-first CRUD

One shell, three listings over a local database, a detail and a long form. A thing you navigate away from is a Window; a thing you switch between is not.

数据列表表单
应用495 行
Pulse — a dashboard

One screen, read rather than operated: a headline number, a KPI grid and charts, all re-fed by the single control that changes the period.

图表
应用445 行
Fieldwork — capturing from the device

Every capture has three states, not two: empty, captured, and unavailable on this device — and the third is the one a phone-only developer never sees.

设备
应用1017 行
Order entry — a wizard

A linear flow that validates per step, lets the reader walk back freely, and ends on a review built from the same data the steps collected.

表单导航
给 AI 助手

本页的机器可读版本,让模型直接读取示例集,而不是猜测 API。

全部示例(JSON)llms.txt

从其中一个开始

挑一个最接近你要做的形态,复制过去,再改属于你的那部分。

阅读文档