Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/_build-ios-port.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
id: src_hash
run: |
set -euo pipefail
SRC_HASH=$(find CodenameOne/src Ports/iOSPort vm/JavaAPI vm/ByteCodeTranslator Themes \
SRC_HASH=$(find CodenameOne/src Ports/iOSPort vm/JavaAPI vm/ByteCodeTranslator Themes native-themes \
-type f \( -name '*.java' -o -name '*.m' -o -name '*.h' -o -name '*.xml' -o -name '*.properties' -o -name '*.css' \) 2>/dev/null \
| sort | xargs shasum -a 256 | shasum -a 256 | awk '{print $1}')
POM_HASH=$(find . -name 'pom.xml' -not -path './scripts/*' 2>/dev/null \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ios-packaging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
id: src_hash
run: |
set -euo pipefail
SRC_HASH=$(find CodenameOne/src Ports/iOSPort vm/JavaAPI vm/ByteCodeTranslator Themes \
SRC_HASH=$(find CodenameOne/src Ports/iOSPort vm/JavaAPI vm/ByteCodeTranslator Themes native-themes \
-type f \( -name '*.java' -o -name '*.m' -o -name '*.h' -o -name '*.xml' -o -name '*.properties' -o -name '*.css' \) 2>/dev/null \
| sort | xargs shasum -a 256 | shasum -a 256 | awk '{print $1}')
POM_HASH=$(find . -name 'pom.xml' -not -path './scripts/*' 2>/dev/null \
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/scripts-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ name: Test Android build scripts
- '!CodenameOne/src/**/*.md'
- 'Ports/Android/**'
- '!Ports/Android/**/*.md'
- 'native-themes/android-material/**'
- '!native-themes/android-material/**/*.md'
- 'maven/**'
- '!maven/core-unittests/**'
- 'tests/**'
Expand Down Expand Up @@ -49,6 +51,8 @@ name: Test Android build scripts
- '!CodenameOne/src/**/*.md'
- 'Ports/Android/**'
- '!Ports/Android/**/*.md'
- 'native-themes/android-material/**'
- '!native-themes/android-material/**/*.md'
- 'maven/**'
- '!maven/core-unittests/**'
- 'tests/**'
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/scripts-ios-native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ on:
- '!CodenameOne/src/**/*.md'
- 'Ports/iOSPort/**'
- '!Ports/iOSPort/**/*.md'
- 'native-themes/ios-modern/**'
- '!native-themes/ios-modern/**/*.md'
- 'vm/**'
- '!vm/**/*.md'
- 'tests/**'
Expand Down Expand Up @@ -47,6 +49,8 @@ on:
- '!CodenameOne/src/**/*.md'
- 'Ports/iOSPort/**'
- '!Ports/iOSPort/**/*.md'
- 'native-themes/ios-modern/**'
- '!native-themes/ios-modern/**/*.md'
- 'vm/**'
- '!vm/**/*.md'
- 'tests/**'
Expand Down Expand Up @@ -108,7 +112,7 @@ jobs:
id: src_hash
run: |
set -euo pipefail
SRC_HASH=$(find CodenameOne/src Ports/iOSPort vm/JavaAPI vm/ByteCodeTranslator Themes \
SRC_HASH=$(find CodenameOne/src Ports/iOSPort vm/JavaAPI vm/ByteCodeTranslator Themes native-themes \
-type f \( -name '*.java' -o -name '*.m' -o -name '*.h' -o -name '*.xml' -o -name '*.properties' -o -name '*.css' \) 2>/dev/null \
| sort | xargs shasum -a 256 | shasum -a 256 | awk '{print $1}')
POM_HASH=$(find . -name 'pom.xml' -not -path './scripts/*' 2>/dev/null \
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/scripts-ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ on:
- '!CodenameOne/src/**/*.md'
- 'Ports/iOSPort/**'
- '!Ports/iOSPort/**/*.md'
- 'native-themes/ios-modern/**'
- '!native-themes/ios-modern/**/*.md'
- 'vm/**'
- '!vm/**/*.md'
- 'tests/**'
Expand Down Expand Up @@ -51,6 +53,8 @@ on:
- '!CodenameOne/src/**/*.md'
- 'Ports/iOSPort/**'
- '!Ports/iOSPort/**/*.md'
- 'native-themes/ios-modern/**'
- '!native-themes/ios-modern/**/*.md'
- 'vm/**'
- '!vm/**/*.md'
- 'tests/**'
Expand Down Expand Up @@ -118,7 +122,7 @@ jobs:
id: src_hash
run: |
set -euo pipefail
SRC_HASH=$(find CodenameOne/src Ports/iOSPort vm/JavaAPI vm/ByteCodeTranslator Themes \
SRC_HASH=$(find CodenameOne/src Ports/iOSPort vm/JavaAPI vm/ByteCodeTranslator Themes native-themes \
-type f \( -name '*.java' -o -name '*.m' -o -name '*.h' -o -name '*.xml' -o -name '*.properties' -o -name '*.css' \) 2>/dev/null \
| sort | xargs shasum -a 256 | shasum -a 256 | awk '{print $1}')
POM_HASH=$(find . -name 'pom.xml' -not -path './scripts/*' 2>/dev/null \
Expand Down
141 changes: 139 additions & 2 deletions docs/developer-guide/Native-Themes.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,11 @@ inherits from it.
|===

To rebrand the app, override the colour at the role level rather
than touching every UIID. For example, to flip the primary
container palette to teal:
than touching every UIID. The example below layers a teal palette
on top from your app's own `theme.css`; if you'd rather edit the
shipped theme directly and ship a fully recoloured `.res`, see
`Recolouring the accent palette via CSS variables` further down -
that path lets a single variable edit drive every accent UIID.

[source,css]
----
Expand Down Expand Up @@ -240,6 +243,134 @@ accent-driven UIIDs the same way as Android above. The colour names
match Apple's `UIColor.systemBlue` etc. so you can mirror the SF
Symbols semantics if you want.

=== Recolouring the accent palette via CSS variables

Both shipped themes expose their accent palette as CSS variables
inside the `#Constants` block at the top of the theme file, so a
single edit recolours every accent-bearing component without
re-declaring rules per UIID. This is the simplest way to ship a
rebranded native theme with your app.

.iOS modern (`native-themes/ios-modern/theme.css`)
[cols="2,1,1", options="header"]
|===
|Variable |Light |Dark

|`--accent-color`
|`#007aff`
|`#0a84ff`

|`--accent-pressed-color`
|`#0064d1`
|`#64b1ff`

|`--accent-disabled-color`
|`#b3d4ff`
|`#004a99`

|`--accent-on-color`
|`#ffffff`
|(same)
|===

Drives `Button`, `RaisedButton`, `CheckBox.selected`,
`RadioButton.selected`, `OnOffSwitch`, `BackCommand`,
`TitleCommand`, `FloatingActionButton`.

.Android Material 3 (`native-themes/android-material/theme.css`)
[cols="2,1,1,2", options="header"]
|===
|Variable |Light |Dark |Material 3 token

|`--accent-color`
|`#6750a4`
|`#d0bcff`
|`primary`

|`--accent-on-color`
|`#ffffff`
|`#381e72`
|`on-primary`

|`--accent-container-color`
|`#eaddff`
|`#4f378b`
|`primary-container`

|`--accent-on-container-color`
|`#21005d`
|`#eaddff`
|`on-primary-container`

|`--accent-pressed-color`
|`#d0bcff`
|`#4f378b`
|`state-pressed`
|===

Drives `Button`, `RaisedButton`, `FlatButton`, `CheckBox.selected`,
`RadioButton.selected`, `Switch.selected`, `OnOffSwitch`,
`BackCommand`, `TitleCommand`, `Tab.selected`, `SelectedTab`,
`SideCommand.pressed`, `MultiButton.pressed`,
`FloatingActionButton`.

==== Forking a theme to rebrand

Copy the native theme into your project, edit the variable values,
and rebuild:

[source,bash]
----
cp -R native-themes/ios-modern native-themes/ios-myapp
$EDITOR native-themes/ios-myapp/theme.css
./scripts/build-native-themes.sh
----

For example, to flip the iOS accent from system blue to brand
magenta in both light and dark mode, change just the variable
declarations at the top of the file:

[source,css]
----
#Constants {
--accent-color: #d81b60;
--accent-color-dark: #ff80ab;
--accent-pressed-color: #b71c5c;
--accent-pressed-color-dark: #f06292;
--accent-disabled-color: #ffd6e2;
--accent-disabled-color-dark: #4a0026;
--accent-on-color: #ffffff;
/* ... existing constants below ... */
}
----

Every UIID listed above picks up the new colour. No per-UIID rule
edits needed.

==== When variable substitution applies

The CSS compiler resolves `var()` references at *theme-compile
time* - the next run of `scripts/build-native-themes.sh` bakes
the values into the `.res` file. This is what you want when
shipping a customised theme with your app: edit the source, build
once, ship the `.res`.

It is *not* a runtime mechanism. Two cases where the variable
indirection does **not** propagate:

* **Layered app `theme.css` redefining a variable.** Your app's
`theme.css` is compiled into a separate `.res` and merged at
startup; redeclaring `--accent-color` there has no effect on
the already-baked native theme styles. Override the specific
UIIDs instead (see `Customising in your own theme` below), or
fork the native theme.
* **Switching the accent palette while the app is running.**
Live theming, in-app accent toggles, A/B tests - use the
`UIManager.addThemeProps` path documented in the next section.

In practice neither is a problem: most apps fork once at build
time and ship a single recoloured native theme.

=== Runtime palette override

Push a Hashtable of theme props through `UIManager.addThemeProps`
Expand Down Expand Up @@ -382,6 +513,12 @@ RaisedButton.disabled { background-color: #ffd6e2; color: #ffffff; }
The user's CSS is layered on top of the native theme at app launch,
so refresh / restart picks the override up.

For a wholesale accent rebrand, forking the shipped theme.css and
editing its CSS variables (see `Recolouring the accent palette via
CSS variables` above) is usually less code than redeclaring every
accent-bearing UIID here. Layering remains the right choice when
you want to keep the framework's accent and only tweak a few UIIDs.

=== Inheriting from a native UIID

`cn1-derive` lets a custom UIID start from one of the native
Expand Down
Loading
Loading