Skip to content

refactor(kmp): move platform-neutral sources to commonMain - #1847

Closed
bmc08gt wants to merge 3 commits into
feat/desktop-spike-a2from
refactor/desktop-spike-lift-common
Closed

bmc08gt wants to merge 3 commits into
feat/desktop-spike-a2from
refactor/desktop-spike-lift-common

Conversation

@bmc08gt

@bmc08gt bmc08gt commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #1844. Moves source files out of androidMain wherever they compile for every target as-is, in the modules this stack already converted to KMP. It converts no new modules.

Pass 1, mechanical (2fa0c04): 90 files across 8 modules. Each file was moved, compiled for jvm, and moved back on failure, so no code changed. Six build files gain Compose (and libsodium in app:core) on commonMain.

module moved still in androidMain
ui:components 37 44
app:core 27 37
app:core-ui 9 22
shared:tokens 7 11
ui:core 5 2
ui:navigation 3 12
shared:common-ui 1 13
shared:theme 1 0

What stays references R, Hilt, java.*, Android APIs (Context, Uri, Bitmap, Navigation3), or a neighbour in the same package that does. Pass 2, R to Compose resources (1d77df4): 13 more files (core-ui 6, ui:components 4, common-ui 2, app:core 1). They read the generated Res through org.jetbrains.compose.resources on both platforms, so Android now loads these strings and icons from Compose resources instead of R. ComposeResourcesOnAndroidTest renders one string and one vector under Robolectric to show they resolve on Android at runtime.

The other R files stay because they also need an androidMain-only neighbour, take @DrawableRes Int/@StringRes Int parameters that would change caller signatures, or use a plural whose items are @string/ references (UnreadSeparator), which Compose resources don't resolve.

Pass 3, the Int-id lookups (597c412): stringRes/painterForResId and the per-module id objects (CoreStrings, CoreDrawables, TxStrings, FlagStrings) are gone; call sites read Res.string.x/Res.drawable.x. The transaction mappers build text outside composition, so ResourceHelper.getString(StringResource, args) maps the key back to R on Android, and ResourceHelperStringResourceTest checks that path returns the real string. shared:userflags gains Compose resources and Field.label/hint become StringResource. ComposeResourceIds stays on jvm for the name-keyed currency-flag lookup.

If one PR is easier to review, this can fold into #1844.

…onMain

Moves 90 files whose code compiles for jvm unchanged: ui:components 37,
app:core 27, core-ui 9, shared:tokens 7, ui:core 5, ui:navigation 3,
common-ui 1, theme 1. Six modules get the Compose (and, for app:core,
libsodium) artifacts on commonMain so the moved files resolve.

Each file was moved, compiled for jvm, and moved back if it failed, so no
code changed. What stays in androidMain references R, Hilt, java.*,
Android APIs, or a neighbour that does.
@bmc08gt bmc08gt self-assigned this Oct 24, 2026
@github-actions github-actions Bot added type: refactor Code restructuring, no behavior change area: ui Compose UI, theme, components, resources area: tokens Token accounts, balances, token info and removed type: refactor Code restructuring, no behavior change labels Oct 24, 2026
…files

13 files that were held in androidMain only by `R` move to commonMain
(core-ui 6, ui:components 4, common-ui 2, app:core 1). They read strings
and drawables through the generated `Res` with
org.jetbrains.compose.resources, on Android as well as desktop, so no
Int-id seam is added.

ui:components and common-ui gain the Compose resources plugin with the
same res-sync block app:core uses. ui:components gets the multiplatform
material icons on commonMain and core-ui gets shared:theme there.

UnreadSeparator stays in androidMain: its plural items point at other
strings with @string/, which Compose resources does not resolve.

ComposeResourcesOnAndroidTest renders a converted string and vector under
Robolectric, since a missing Compose resource throws at runtime rather
than failing the build.
@github-actions github-actions Bot added the type: refactor Code restructuring, no behavior change label Oct 24, 2026
Common code read strings and icons through stringRes/painterForResId and
per-module id objects (CoreStrings, CoreDrawables, TxStrings, FlagStrings),
each an expect object with R on Android and Compose ids on jvm. Call sites
now use Res.string.x / Res.drawable.x directly and the id objects are gone.

- ResourceHelper gains getString(StringResource, args). The transaction
  mappers build text outside composition, so Android maps the resource key
  back to R and jvm calls getString. ResourceHelperStringResourceTest checks
  the Android path finds the real string.
- shared:userflags gets Compose resources; Field.label/hint are
  StringResource, and the Android-only editor reads them with
  stringResource.
- Currency flags are still looked up by name at runtime on jvm, so
  ComposeResourceIds stays for the name-keyed ResourceHelper.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: tokens Token accounts, balances, token info area: ui Compose UI, theme, components, resources type: refactor Code restructuring, no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant