Skip to content

Commit a7ab5bd

Browse files
authored
feat(ios): add support for modern button configuration (tidev#14252)
* feat(ios): add support for modern button configuration * chore: clean up docs for removed API * feat: add docs * fix: fix minor docs issues * feat: support “font”, “textAlign” and “backgroundSelectedColor” * fix: handle backgroundSelectedColor properly * chore: document new properties * fix: properly handle backgroundSelectedColor
1 parent d42adf2 commit a7ab5bd

21 files changed

+543
-195
lines changed

apidoc/Titanium/UI/Button.yml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,6 @@ description: |
5656
5757
#### iOS Platform Notes
5858
59-
iOS buttons have two special properties, `style` and `systemButton`.
60-
61-
The `style` property specifies the type of button decoration, and can be set to one
62-
of the values described in <Titanium.UI.iOS.SystemButtonStyle>.
63-
64-
To use a custom button style, such as a background gradient, you may need to explicitly set
65-
the button's `style` property to `PLAIN`, to prevent the button style from overriding any background color or gradient.
66-
67-
Also note:
68-
6959
* When assigning a custom image to the `backgroundImage` property, the image must be
7060
partially or wholly transparent for the background color or background gradient to be visible.
7161
* Similarly, for an assigned background gradient to show through, the `backgroundColor` may need to be
@@ -114,7 +104,7 @@ description: |
114104
iOS supplies a built-in effect for pressed buttons. For most iOS buttons, the effect
115105
dims the entire button (except for the text) while the button is being pressed.
116106
117-
For toolbar buttons that use the [PLAIN](Titanium.UI.iOS.SystemButtonStyle.PLAIN) style
107+
For toolbar buttons that use the [PLAIN](Titanium.UI.BUTTON_STYLE_OPTION_NEUTRAL) style
118108
or use system icons such as [CAMERA](Titanium.UI.iOS.SystemButton.CAMERA), a glow effect is
119109
used. The glow effect shows as a white circular glow or highlight at the center of the button
120110
when the button is pressed.
@@ -231,6 +221,20 @@ properties:
231221
since: "3.2.0"
232222
platforms: [iphone, ipad, macos]
233223

224+
- name: configuration
225+
summary: Button configuration for modern button styling.
226+
description: |
227+
A <Titanium.UI.iOS.ButtonConfiguration> object that defines the appearance and behavior
228+
of the button. This provides a modern way to configure buttons with support for titles,
229+
subtitles, images, and various styling options.
230+
231+
When using a button configuration, it takes precedence over individual styling properties
232+
like `title`, `color`, and `backgroundColor`.
233+
type: Titanium.UI.iOS.ButtonConfiguration
234+
since: "13.0.0"
235+
platforms: [iphone, ipad, macos]
236+
osver: {ios: {min: "15.0"}}
237+
234238
- name: enabled
235239
summary: Set to `true` to enable the button, `false` to disable the button.
236240
type: Boolean
@@ -294,9 +298,6 @@ properties:
294298
summary: The border and fill style the button will use.
295299
description: |
296300
On Android, this is a creation-only property and cannot be changed dynamically.
297-
298-
For Titanium versions older than 10.0.0, this is an iOS only property and must be assigned
299-
a constant from <Titanium.UI.iOS.SystemButtonStyle> which is now deprecated.
300301
type: Number
301302
constants: Titanium.UI.BUTTON_STYLE_*
302303
platforms: [android, iphone, ipad, macos]

apidoc/Titanium/UI/DashboardView.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ examples:
161161
162162
var button = Ti.UI.createButton({
163163
title: 'Edit',
164-
style: Ti.UI.iOS.SystemButtonStyle.DONE,
164+
style: Ti.UI.BUTTON_STYLE_OPTION_POSITIVE,
165165
});
166166
167167
var toolbar = Ti.UI.iOS.createToolbar({
@@ -223,13 +223,13 @@ examples:
223223
224224
dashboard.addEventListener('edit', function(e) {
225225
button.title = 'Done';
226-
button.style = Ti.UI.iOS.SystemButtonStyle.DONE;
226+
button.style = Ti.UI.BUTTON_STYLE_OPTION_POSITIVE;
227227
isEditable = true;
228228
});
229229
230230
dashboard.addEventListener('commit', function(e) {
231231
button.title = 'Edit';
232-
button.style = Ti.UI.iOS.SystemButtonStyle.PLAIN;
232+
button.style = Ti.UI.BUTTON_STYLE_OPTION_NEUTRAL;
233233
isEditable = false;
234234
});
235235
@@ -290,13 +290,13 @@ examples:
290290
291291
function handleEdit(e) {
292292
$.button.title = 'Done';
293-
$.button.style = Ti.UI.iOS.SystemButtonStyle.DONE;
293+
$.button.style = Ti.UI.BUTTON_STYLE_OPTION_POSITIVE;
294294
isEditable = true;
295295
}
296296
297297
function handleCommit(e) {
298298
$.button.title = 'Edit';
299-
$.button.style = Ti.UI.iOS.SystemButtonStyle.PLAIN;
299+
$.button.style = Ti.UI.BUTTON_STYLE_OPTION_NEUTRAL;
300300
isEditable = false;
301301
}
302302

apidoc/Titanium/UI/TabbedBar.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,20 @@ properties:
6666
summary: Style of the tabbed bar.
6767
description: |
6868
Specify one of the constants:
69-
For iOS:
70-
[Titanium.UI.iOS.SystemButtonStyle](Titanium.UI.iOS.SystemButtonStyle),
71-
either `PLAIN`, `BORDERED`, or `BAR`.
72-
73-
The `BAR` style specifies a more compact style and allows the bar's background
74-
color or gradient to show through.
69+
For iOS, one use <Titanium.UI.BUTTON_STYLE_OPTION_POSITIVE> or <Titanium.UI.BUTTON_STYLE_OPTION_NEUTRAL>.
7570
7671
For Android use [Titanium.UI.TABS_STYLE_DEFAULT](Titanium.UI.TABS_STYLE_DEFAULT) or
7772
[Titanium.UI.TABS_STYLE_BOTTOM_NAVIGATION](Titanium.UI.TABS_STYLE_BOTTOM_NAVIGATION) and
7873
it is only supported in the creation dictionary of the proxy.
7974
type: Number
80-
default: Titanium.UI.iOS.SystemButtonStyle.PLAIN for iOS, Ti.UI.TABS_STYLE_DEFAULT for Android
75+
default: Titanium.UI.BUTTON_STYLE_OPTION_NEUTRAL for iOS, Ti.UI.TABS_STYLE_DEFAULT for Android
8176
examples:
8277
- title: Simple Tabbed Bar with 3 items
8378
example: |
8479
``` js
8580
var bb1 = Ti.UI.createTabbedBar({
8681
labels: ['One', 'Two', 'Three'],
8782
backgroundColor: '#336699',
88-
style: Ti.UI.iOS.SystemButtonStyle.BAR,
8983
width: 200,
9084
height: 25,
9185
top: 50

apidoc/Titanium/UI/TextArea.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ examples:
603603
604604
``` js
605605
var send = Ti.UI.createButton({
606-
style : Ti.UI.iOS.SystemButtonStyle.DONE,
606+
style : Ti.UI.BUTTON_STYLE_OPTION_POSITIVE,
607607
title : 'Send'
608608
});
609609

apidoc/Titanium/UI/TextField.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ examples:
665665
666666
var send = Ti.UI.createButton({
667667
title: 'Send',
668-
style: Ti.UI.iOS.SystemButtonStyle.DONE,
668+
style: Ti.UI.BUTTON_STYLE_OPTION_POSITIVE,
669669
});
670670
671671
var camera = Ti.UI.createButton({

apidoc/Titanium/UI/Toolbar.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ examples:
284284
285285
var send = Ti.UI.createButton({
286286
title: 'Send',
287-
style: Ti.UI.iOS.SystemButtonStyle.DONE,
287+
style: Ti.UI.BUTTON_STYLE_OPTION_POSITIVE,
288288
});
289289
290290
var camera = Ti.UI.createButton({

apidoc/Titanium/UI/Window.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,7 @@ properties:
14981498
<NavigationWindow>
14991499
<Window>
15001500
<WindowToolbar>
1501-
<Button id="send" title="Send" style="Ti.UI.iOS.SystemButtonStyle.DONE" />
1501+
<Button id="send" title="Send" style="Ti.UI.BUTTON_STYLE_OPTION_POSITIVE" />
15021502
<FlexSpace/>
15031503
<Button id="camera" systemButton="Ti.UI.iOS.SystemButton.CAMERA" />
15041504
<FlexSpace/>
Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
---
2+
name: Titanium.UI.iOS.ButtonConfiguration
3+
summary: |
4+
A configuration object for customizing the appearance and behavior of a button.
5+
description: |
6+
The ButtonConfiguration API provides a modern way to configure buttons on iOS with support for
7+
various styles, titles, subtitles, images, and padding. This API wraps the native `UIButtonConfiguration`
8+
introduced in iOS 15.0 and represents a modern alternative to the existing Button API while retaining
9+
backwards compatibility. In the future, this API may be merged into the root parameters of a button instead.
10+
11+
Use the <Titanium.UI.iOS.createButtonConfiguration> method to create a button configuration.
12+
13+
Button configurations support several predefined styles:
14+
- **plain**: A plain button style with minimal background
15+
- **tinted**: A tinted button style with a subtle background
16+
- **filled**: A filled button style with a solid background
17+
- **gray**: A gray button style
18+
- **borderless**: A borderless button style
19+
- **bordered**: A bordered button style with an outline
20+
- **borderedTinted**: A bordered button style with a tinted outline
21+
- **borderedProminent**: A bordered button style with a prominent appearance
22+
23+
Additional styles available on iOS 26.0+:
24+
- **glass**: A glass-like appearance
25+
- **prominentGlass**: A prominent glass-like appearance
26+
- **clearGlass**: A clear glass-like appearance
27+
- **prominentClearGlass**: A prominent clear glass-like appearance
28+
29+
extends: Titanium.Proxy
30+
platforms: [iphone, ipad, macos]
31+
since: {iphone: "13.0.0", ipad: "13.0.0", macos: "13.0.0"}
32+
osver: {ios: {min: "15.0"}}
33+
34+
properties:
35+
- name: style
36+
summary: The style of button configuration to create.
37+
description: |
38+
Sets the base configuration style for the button. This property should be set first
39+
as it determines the initial configuration that other properties will modify.
40+
41+
Valid string values are:
42+
- `"plain"`: A plain button style with minimal background
43+
- `"tinted"`: A tinted button style with a subtle background
44+
- `"filled"`: A filled button style with a solid background
45+
- `"gray"`: A gray button style
46+
- `"borderless"`: A borderless button style
47+
- `"bordered"`: A bordered button style with an outline
48+
- `"borderedTinted"`: A bordered button style with a tinted outline
49+
- `"borderedProminent"`: A bordered button style with a prominent appearance
50+
- `"glass"`: A glass-like appearance (iOS 26.0+)
51+
- `"prominentGlass"`: A prominent glass-like appearance (iOS 26.0+)
52+
- `"clearGlass"`: A clear glass-like appearance (iOS 26.0+)
53+
- `"prominentClearGlass"`: A prominent clear glass-like appearance (iOS 26.0+)
54+
type: String
55+
availability: creation
56+
57+
- name: title
58+
summary: The title text to display on the button.
59+
type: String
60+
61+
- name: subtitle
62+
summary: The subtitle text to display below the title.
63+
type: String
64+
65+
- name: backgroundColor
66+
summary: The background color of the button.
67+
description: |
68+
Sets the base background color for the button. This color may be modified
69+
by the system based on the button state and configuration style.
70+
type: [String, Titanium.UI.Color]
71+
72+
- name: color
73+
summary: The foreground color of the button's content.
74+
description: |
75+
Sets the base foreground color for the button's title and subtitle text.
76+
This color may be modified by the system based on the button state.
77+
type: [String, Titanium.UI.Color]
78+
79+
- name: image
80+
summary: The image to display on the button.
81+
description: |
82+
The image to display alongside the button's title. Use the imagePlacement
83+
property to control where the image appears relative to the title.
84+
type: [String, Titanium.Blob, Titanium.Filesystem.File]
85+
86+
- name: padding
87+
summary: The padding around the button's content.
88+
description: |
89+
An object with top, left, bottom, and right properties to specify
90+
the content insets for the button.
91+
type: Padding
92+
93+
- name: imagePlacement
94+
summary: The placement of the image relative to the title.
95+
description: |
96+
Controls where the button's image appears relative to its title text.
97+
98+
Valid string values are:
99+
- `"leading"`: Place the image before the title text
100+
- `"trailing"`: Place the image after the title text
101+
- `"top"`: Place the image above the title text
102+
- `"bottom"`: Place the image below the title text
103+
type: String
104+
default: "leading"
105+
106+
- name: imagePadding
107+
summary: The spacing between the image and title.
108+
description: |
109+
The amount of spacing in points between the button's image and its title text.
110+
type: Number
111+
default: 0
112+
113+
- name: titlePadding
114+
summary: The spacing between the title and subtitle.
115+
description: |
116+
The amount of spacing in points between the button's title and subtitle text.
117+
type: Number
118+
default: 0
119+
120+
- name: font
121+
summary: Font to use for the button title.
122+
description: |
123+
Sets the font applied to the configuration’s title via the underlying
124+
`UIButtonConfiguration.titleTextAttributesTransformer`.
125+
126+
When using `attributedString`, prefer setting font in the attributed content instead.
127+
type: Font
128+
129+
- name: textAlign
130+
summary: Text alignment of the configuration title.
131+
description: |
132+
Aligns the title within the button’s content area. Maps to
133+
`UIButtonConfigurationTitleAlignment`.
134+
type: [String, Number]
135+
constants: Titanium.UI.TEXT_ALIGNMENT_*
136+
137+
- name: attributedString
138+
summary: Specify an attributed string for the button title.
139+
description: |
140+
Sets the configuration’s `attributedTitle`. If set, avoid also setting
141+
`title`, `color`, and `font` to prevent conflicting styles.
142+
type: Titanium.UI.AttributedString
143+
144+
- name: backgroundSelectedColor
145+
summary: Background color to use while the button is highlighted (pressed).
146+
description: |
147+
When this configuration is assigned to a <Titanium.UI.Button> and both
148+
`backgroundColor` and `backgroundSelectedColor` are provided, the button will
149+
automatically swap the configuration’s background to `backgroundSelectedColor`
150+
when highlighted and restore the base color when not highlighted.
151+
152+
This mirrors the traditional `backgroundSelectedColor` behavior on views when
153+
used with modern button configurations.
154+
type: [String, Titanium.UI.Color]
155+
156+
examples:
157+
- title: Basic Button Configuration
158+
example: |
159+
``` js
160+
const button = Ti.UI.createButton({
161+
configuration: Ti.UI.iOS.createButtonConfiguration({
162+
style: 'filled',
163+
title: 'Sign In',
164+
subtitle: 'with your account',
165+
backgroundColor: '#007AFF',
166+
color: 'white'
167+
})
168+
});
169+
```
170+
171+
- title: Button with Image and Padding
172+
example: |
173+
``` js
174+
const button = Ti.UI.createButton({
175+
configuration: Ti.UI.iOS.createButtonConfiguration({
176+
style: 'borderedTinted',
177+
title: 'Upload',
178+
image: 'upload-icon.png',
179+
imagePlacement: 'leading',
180+
imagePadding: 8,
181+
padding: {
182+
top: 12,
183+
left: 20,
184+
bottom: 12,
185+
right: 20
186+
}
187+
})
188+
});
189+
```
190+
191+
- title: Prominent Button Style
192+
example: |
193+
``` js
194+
const button = Ti.UI.createButton({
195+
configuration: Ti.UI.iOS.createButtonConfiguration({
196+
style: 'borderedProminent',
197+
title: 'Get Started',
198+
backgroundColor: '#34C759'
199+
})
200+
});
201+
```
202+
203+
- title: Typography and Alignment
204+
example: |
205+
``` js
206+
const button = Ti.UI.createButton({
207+
configuration: Ti.UI.iOS.createButtonConfiguration({
208+
style: 'filled',
209+
title: 'Continue',
210+
font: { fontSize: 18, fontWeight: 'semibold' },
211+
textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER
212+
})
213+
});
214+
```
215+
216+
- title: Highlighted Background Color
217+
example: |
218+
``` js
219+
const button = Ti.UI.createButton({
220+
configuration: Ti.UI.iOS.createButtonConfiguration({
221+
style: 'filled',
222+
title: 'Tap Me',
223+
backgroundColor: '#007AFF',
224+
backgroundSelectedColor: '#005BBB' // shown while pressed
225+
})
226+
});
227+
```

0 commit comments

Comments
 (0)