@nativescript-community/ui-segmentedbar 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## 1.0.0 (2026-10-18)
7
+
8
+ ### Features
9
+
10
+ * native-api-usage.json for every package on Android and iOS ([cfd7dcc](https://github.com/nativescript-community/ui-native-components/commit/cfd7dcc4b996b02319cfacee233bc56c29df70e4))
11
+ * **segmentedbar:** add ui-segmentedbar with icon items (MaterialButtonToggleGroup / UISegmentedControl) ([df8b6fb](https://github.com/nativescript-community/ui-native-components/commit/df8b6fb0e5d966f9113b4207af3dd0c5548fc728))
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,195 @@
1
- # Temporary Holding Version
1
+ <!-- ⚠️ This README has been generated from the file(s) "blueprint.md" ⚠️-->
2
+ <!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
4
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
8
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
9
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
11
+ DO NOT EDIT THIS READEME DIRECTLY! Edit "bluesprint.md" instead.
12
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
13
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
14
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
15
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
16
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
17
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
18
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
19
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
20
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
21
+ <h1 align="center">@nativescript-community/ui-segmentedbar</h1>
22
+ <p align="center">
23
+ <a href="https://npmcharts.com/compare/@nativescript-community/ui-segmentedbar?minimal=true"><img alt="Downloads per month" src="https://img.shields.io/npm/dm/@nativescript-community/ui-segmentedbar.svg" height="20"/></a>
24
+ <a href="https://www.npmjs.com/package/@nativescript-community/ui-segmentedbar"><img alt="NPM Version" src="https://img.shields.io/npm/v/@nativescript-community/ui-segmentedbar.svg" height="20"/></a>
25
+ </p>
2
26
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
27
+ <p align="center">
28
+ <b>Segmented control: MaterialButtonToggleGroup on Android, native UISegmentedControl on iOS, with icon items.</b></br>
29
+ <sub><sub>
30
+ </p>
31
+
32
+ <br />
33
+
34
+
35
+ | iOS | Android |
36
+ | --- | --- |
37
+ | <img src="https://github.com/nativescript-community/ui-native-components/raw/master/images/ui-segmentedbar-ios.png" height="500" /> | <img src="https://github.com/nativescript-community/ui-native-components/raw/master/images/ui-segmentedbar-android.png" height="500" /> |
38
+
39
+
40
+ [](#table-of-contents)
41
+
42
+ ## Table of Contents
43
+
44
+ * [Installation](#installation)
45
+ * [Usage](#usage)
46
+ * [API](#api)
47
+ * [Demos and Development](#demos-and-development)
48
+ * [Repo Setup](#repo-setup)
49
+ * [Build](#build)
50
+ * [Demos](#demos)
51
+ * [Contributing](#contributing)
52
+ * [Update repo ](#update-repo-)
53
+ * [Update readme ](#update-readme-)
54
+ * [Update doc ](#update-doc-)
55
+ * [Publish](#publish)
56
+ * [modifying submodules](#modifying-submodules)
57
+ * [Questions](#questions)
58
+
59
+ | Android | iOS |
60
+ |---|---|
61
+ | `MaterialButtonToggleGroup` | `UISegmentedControl` |
62
+
63
+
64
+ [](#installation)
65
+
66
+ ## Installation
67
+
68
+ ```bash
69
+ npm install @nativescript-community/ui-segmentedbar
70
+ ```
71
+
72
+ The Android components use **Material 3**: see the [repository README](https://github.com/nativescript-community/ui-native-components#installation) for the theme.
73
+
74
+
75
+ [](#usage)
76
+
77
+ ## Usage
78
+
79
+ ```xml
80
+ <SegmentedBar selectedIndex="0">
81
+ <SegmentedBarItem title="Day" />
82
+ <SegmentedBarItem src="sys://list.bullet" />
83
+ </SegmentedBar>
84
+ ```
85
+
86
+
87
+ [](#api)
88
+
89
+ ## API
90
+
91
+ Same API as the core `SegmentedBar`, and `SegmentedBarItem` adds:
92
+
93
+ | Property | |
94
+ |---|---|
95
+ | `src` | icon: file, resource, url, `font://`, `sys://` (SF Symbol), an ImageSource or a FormattedString (spans drawn into an icon) |
96
+ | `formattedText` | spans. On iOS they are drawn as an image (`UISegmentedControl` only shows plain titles). Uses `@nativescript-community/text` when installed (optional) |
97
+
98
+
99
+ [](#demos-and-development)
100
+
101
+ ## Demos and Development
102
+
103
+
104
+ ### Repo Setup
105
+
106
+ The repo uses submodules. If you did not clone with ` --recursive` then you need to call
107
+ ```
108
+ git submodule update --init
109
+ ```
110
+
111
+ The package manager used to install and link dependencies must be `pnpm` or `yarn`. `npm` wont work.
112
+
113
+ To develop and test:
114
+ if you use `yarn` then run `yarn`
115
+ if you use `pnpm` then run `pnpm i`
116
+
117
+ **Interactive Menu:**
118
+
119
+ To start the interactive menu, run `npm start` (or `yarn start` or `pnpm start`). This will list all of the commonly used scripts.
120
+
121
+ ### Build
122
+
123
+ ```bash
124
+ npm run build.all
125
+ ```
126
+ WARNING: it seems `yarn build.all` wont always work (not finding binaries in `node_modules/.bin`) which is why the doc explicitly uses `npm run`
127
+
128
+ ### Demos
129
+
130
+ ```bash
131
+ npm run demo.[ng|react|svelte|vue].[ios|android]
132
+
133
+ npm run demo.svelte.ios # Example
134
+ ```
135
+
136
+ Demo setup is a bit special in the sense that if you want to modify/add demos you dont work directly in `demo-[ng|react|svelte|vue]`
137
+ Instead you work in `demo-snippets/[ng|react|svelte|vue]`
138
+ You can start from the `install.ts` of each flavor to see how to register new demos
139
+
140
+
141
+ [](#contributing)
142
+
143
+ ## Contributing
144
+
145
+ ### Update repo
146
+
147
+ You can update the repo files quite easily
148
+
149
+ First update the submodules
150
+
151
+ ```bash
152
+ npm run update
153
+ ```
154
+
155
+ Then commit the changes
156
+ Then update common files
157
+
158
+ ```bash
159
+ npm run sync
160
+ ```
161
+ Then you can run `yarn|pnpm`, commit changed files if any
162
+
163
+ ### Update readme
164
+ ```bash
165
+ npm run readme
166
+ ```
167
+
168
+ ### Update doc
169
+ ```bash
170
+ npm run doc
171
+ ```
172
+
173
+ ### Publish
174
+
175
+ The publishing is completely handled by `lerna` (you can add `-- --bump major` to force a major release)
176
+ Simply run
177
+ ```shell
178
+ npm run publish
179
+ ```
180
+
181
+ ### modifying submodules
182
+
183
+ The repo uses https:// for submodules which means you won't be able to push directly into the submodules.
184
+ One easy solution is t modify `~/.gitconfig` and add
185
+ ```
186
+ [url "ssh://git@github.com/"]
187
+ pushInsteadOf = https://github.com/
188
+ ```
189
+
190
+
191
+ [](#questions)
192
+
193
+ ## Questions
194
+
195
+ If you have any questions/issues/comments please feel free to create an issue or start a conversation in the [NativeScript Community Discord](https://nativescript.org/discord).
@@ -0,0 +1,35 @@
1
+ import { FormattedString, ImageSource, Label, Property } from '@nativescript/core';
2
+ import { SegmentedBarBase, SegmentedBarItemBase } from '@nativescript/core/ui/segmented-bar/segmented-bar-common';
3
+ export { SegmentedBarBase, SegmentedBarItemBase };
4
+ /**
5
+ * Segment of the bar: a title and/or an icon.
6
+ * `src` is a file, resource, url, `sys://` (SF Symbol, iOS) or `font://` (font icon, uses the font of the item) path, or an ImageSource.
7
+ */
8
+ export declare class SegmentedBarItem extends SegmentedBarItemBase {
9
+ src: string | ImageSource | FormattedString;
10
+ /**
11
+ * @internal true for the icons drawn from spans: they keep their colors
12
+ */
13
+ imageIsOriginal: boolean;
14
+ /**
15
+ * @internal loaded icon, always a white (template) image for the font icons
16
+ */
17
+ image: ImageSource;
18
+ private mLabel;
19
+ /**
20
+ * Label used to create the native rich text (spans) of the item and as the owner of the formattedText.
21
+ * @internal
22
+ */
23
+ get textOwner(): Label;
24
+ /**
25
+ * Rich text (spans) of the segment, it wins over the title.
26
+ * Uses `@nativescript-community/text` when it is installed.
27
+ * On iOS the text is drawn as an image (the native control only shows plain titles), so the colors are the ones of the spans.
28
+ */
29
+ get formattedText(): FormattedString;
30
+ set formattedText(value: FormattedString);
31
+ _addChildFromBuilder(name: string, value: any): void;
32
+ loadImage(value: string | ImageSource | FormattedString): Promise<void>;
33
+ _update(): void;
34
+ }
35
+ export declare const srcProperty: Property<SegmentedBarItem, string | ImageSource | FormattedString>;
@@ -0,0 +1,101 @@
1
+ import { renderFormattedTextToImageSource } from '@nativescript-community/ui-core/formatted-text';
2
+ import { Color, FormattedString, ImageSource, Label, Property, Span, Utils } from '@nativescript/core';
3
+ import { SegmentedBarBase, SegmentedBarItemBase } from '@nativescript/core/ui/segmented-bar/segmented-bar-common';
4
+ export { SegmentedBarBase, SegmentedBarItemBase };
5
+ /**
6
+ * Segment of the bar: a title and/or an icon.
7
+ * `src` is a file, resource, url, `sys://` (SF Symbol, iOS) or `font://` (font icon, uses the font of the item) path, or an ImageSource.
8
+ */
9
+ export class SegmentedBarItem extends SegmentedBarItemBase {
10
+ constructor() {
11
+ super(...arguments);
12
+ /**
13
+ * @internal true for the icons drawn from spans: they keep their colors
14
+ */
15
+ this.imageIsOriginal = false;
16
+ }
17
+ /**
18
+ * Label used to create the native rich text (spans) of the item and as the owner of the formattedText.
19
+ * @internal
20
+ */
21
+ get textOwner() {
22
+ if (!this.mLabel) {
23
+ this.mLabel = new Label();
24
+ }
25
+ return this.mLabel;
26
+ }
27
+ /**
28
+ * Rich text (spans) of the segment, it wins over the title.
29
+ * Uses `@nativescript-community/text` when it is installed.
30
+ * On iOS the text is drawn as an image (the native control only shows plain titles), so the colors are the ones of the spans.
31
+ */
32
+ get formattedText() {
33
+ return this.mLabel?.formattedText;
34
+ }
35
+ set formattedText(value) {
36
+ this.textOwner.formattedText = value;
37
+ this._update();
38
+ }
39
+ _addChildFromBuilder(name, value) {
40
+ if (value instanceof Span) {
41
+ if (!this.formattedText) {
42
+ this.formattedText = new FormattedString();
43
+ }
44
+ this.formattedText.spans.push(value);
45
+ this._update();
46
+ }
47
+ else if (value instanceof FormattedString) {
48
+ this.formattedText = value;
49
+ }
50
+ }
51
+ async loadImage(value) {
52
+ let source;
53
+ this.imageIsOriginal = false;
54
+ if (value instanceof FormattedString) {
55
+ // an icon drawn from spans (font icons, emojis...)
56
+ source = renderFormattedTextToImageSource(value, this.textOwner);
57
+ this.imageIsOriginal = true;
58
+ }
59
+ else if (typeof value === 'string') {
60
+ value = value.trim();
61
+ if (Utils.isFontIconURI(value)) {
62
+ source = ImageSource.fromFontIconCodeSync(value.split('//')[1], this.style.fontInternal, new Color('white'));
63
+ }
64
+ else if (value.indexOf(Utils.SYSTEM_PREFIX) === 0) {
65
+ source = await ImageSource.fromSystemImage(value.slice(Utils.SYSTEM_PREFIX.length));
66
+ }
67
+ else if (Utils.isFileOrResourcePath(value)) {
68
+ source = value.indexOf(Utils.RESOURCE_PREFIX) === 0 ? await ImageSource.fromResource(value.slice(Utils.RESOURCE_PREFIX.length)) : await ImageSource.fromFile(value);
69
+ }
70
+ else {
71
+ source = await ImageSource.fromUrl(value);
72
+ }
73
+ if (this.src !== value) {
74
+ // changed while loading
75
+ return;
76
+ }
77
+ }
78
+ else {
79
+ source = value;
80
+ }
81
+ this.image = source;
82
+ this._update();
83
+ }
84
+ _update() {
85
+ this.parent?.updateItem?.(this);
86
+ }
87
+ }
88
+ export const srcProperty = new Property({
89
+ name: 'src',
90
+ valueChanged: (target, oldValue, newValue) => {
91
+ if (newValue) {
92
+ target.loadImage(newValue);
93
+ }
94
+ else {
95
+ target.image = null;
96
+ target._update();
97
+ }
98
+ }
99
+ });
100
+ srcProperty.register(SegmentedBarItem);
101
+ //# sourceMappingURL=index-common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-common.js","sourceRoot":"","sources":["../../src/ui-segmentedbar/index-common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,gDAAgD,CAAC;AAClG,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACvG,OAAO,EAAE,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AM,CAAC;YACJ,MAAM,GAAG,KAAK,CAAC;QACnB,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC;QACpB,IAAI,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC;IAED,OAAO;QACF,IAAI,CAAC,MAAc,EAAE,UAAU,EAAE,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC;CACJ;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,QAAQ,CAA2D;IAC9F,IAAI,EAAE,KAAK;IACX,YAAY,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE;QACzC,IAAI,QAAQ,EAAE,CAAC;YACX,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QAC/B,CAAC;aAAM,CAAC;YACJ,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC;YACpB,MAAM,CAAC,OAAO,EAAE,CAAC;QACrB,CAAC;IACL,CAAC;CACJ,CAAC,CAAC;AACH,WAAW,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { itemsProperty, selectedIndexProperty } from '@nativescript/core/ui/segmented-bar/segmented-bar-common';
2
+ import { SegmentedBarBase, SegmentedBarItem } from './index-common';
3
+ export { SegmentedBarItem };
4
+ type ToggleGroup = com.google.android.material.button.MaterialButtonToggleGroup & {
5
+ listener: com.google.android.material.button.MaterialButtonToggleGroup.OnButtonCheckedListener;
6
+ };
7
+ /**
8
+ * Android: Material 3 segmented buttons (MaterialButtonToggleGroup with outlined buttons).
9
+ */
10
+ export declare class SegmentedBar extends SegmentedBarBase {
11
+ [selectedIndexProperty.getDefault]: () => number;
12
+ [selectedIndexProperty.setNative]: (value: number) => void;
13
+ [itemsProperty.getDefault]: () => SegmentedBarItem[];
14
+ [itemsProperty.setNative]: (value: SegmentedBarItem[]) => void;
15
+ nativeViewProtected: ToggleGroup;
16
+ items: SegmentedBarItem[];
17
+ createNativeView(): com.google.android.material.button.MaterialButtonToggleGroup;
18
+ initNativeView(): void;
19
+ disposeNativeView(): void;
20
+ private applyItem;
21
+ updateItem(item: SegmentedBarItem): void;
22
+ private insertItem;
23
+ }
@@ -0,0 +1,104 @@
1
+ import { createNativeFormattedText } from '@nativescript-community/ui-core/formatted-text';
2
+ import { Utils } from '@nativescript/core';
3
+ import { itemsProperty, selectedIndexProperty } from '@nativescript/core/ui/segmented-bar/segmented-bar-common';
4
+ import { SegmentedBarBase, SegmentedBarItem } from './index-common';
5
+ export { SegmentedBarItem };
6
+ // Material 3 segmented buttons are 40dp high
7
+ const SEGMENT_HEIGHT = 40;
8
+ /**
9
+ * Android: Material 3 segmented buttons (MaterialButtonToggleGroup with outlined buttons).
10
+ */
11
+ export class SegmentedBar extends SegmentedBarBase {
12
+ createNativeView() {
13
+ return new com.google.android.material.button.MaterialButtonToggleGroup(this._context);
14
+ }
15
+ initNativeView() {
16
+ super.initNativeView();
17
+ const nativeView = this.nativeViewProtected;
18
+ nativeView.setSingleSelection(true);
19
+ nativeView.setSelectionRequired(true);
20
+ // the segments keep the same height whatever their text
21
+ nativeView.setBaselineAligned(false);
22
+ const owner = new WeakRef(this);
23
+ const listener = new com.google.android.material.button.MaterialButtonToggleGroup.OnButtonCheckedListener({
24
+ onButtonChecked(group, checkedId, isChecked) {
25
+ const _owner = owner.get();
26
+ if (_owner && isChecked) {
27
+ const newIndex = group.indexOfChild(group.findViewById(checkedId));
28
+ if (newIndex !== _owner.selectedIndex) {
29
+ _owner.selectedIndex = newIndex;
30
+ }
31
+ }
32
+ }
33
+ });
34
+ nativeView.addOnButtonCheckedListener(listener);
35
+ nativeView.listener = listener;
36
+ }
37
+ disposeNativeView() {
38
+ const nativeView = this.nativeViewProtected;
39
+ if (nativeView?.listener) {
40
+ nativeView.removeOnButtonCheckedListener(nativeView.listener);
41
+ nativeView.listener = null;
42
+ }
43
+ super.disposeNativeView();
44
+ }
45
+ applyItem(button, item) {
46
+ const formatted = item.formattedText;
47
+ if (formatted && !item.textOwner.fontSize) {
48
+ // spans without size: the size of the Material button text
49
+ item.textOwner.fontSize = 14;
50
+ }
51
+ const title = formatted ? formatted.toString() : item.title;
52
+ button.setText(formatted ? createNativeFormattedText(formatted, item.textOwner) || title : title || '');
53
+ const image = item.image?.android;
54
+ if (image) {
55
+ button.setIcon(new android.graphics.drawable.BitmapDrawable(Utils.android.getApplicationContext().getResources(), image));
56
+ button.setIconGravity(com.google.android.material.button.MaterialButton.ICON_GRAVITY_TEXT_START);
57
+ button.setIconPadding(title ? Utils.layout.toDevicePixels(8) : 0);
58
+ }
59
+ else {
60
+ button.setIcon(null);
61
+ }
62
+ }
63
+ updateItem(item) {
64
+ const index = this.items?.indexOf(item) ?? -1;
65
+ const button = index >= 0 ? this.nativeViewProtected?.getChildAt(index) : null;
66
+ if (button) {
67
+ this.applyItem(button, item);
68
+ }
69
+ }
70
+ insertItem(item) {
71
+ const R = com.google.android.material.R;
72
+ const button = new com.google.android.material.button.MaterialButton(this._context, null, R.attr.materialButtonOutlinedStyle);
73
+ const height = Utils.layout.toDevicePixels(SEGMENT_HEIGHT);
74
+ // no touch target insets
75
+ button.setInsetTop(0);
76
+ button.setInsetBottom(0);
77
+ button.setMinHeight(height);
78
+ button.setMinimumHeight(height);
79
+ this.applyItem(button, item);
80
+ // the segments share the width of the group
81
+ this.nativeViewProtected.addView(button, new android.widget.LinearLayout.LayoutParams(0, height, 1));
82
+ }
83
+ [selectedIndexProperty.getDefault]() {
84
+ return -1;
85
+ }
86
+ [selectedIndexProperty.setNative](value) {
87
+ const button = value >= 0 ? this.nativeViewProtected.getChildAt(value) : null;
88
+ if (button) {
89
+ this.nativeViewProtected.check(button.getId());
90
+ }
91
+ else {
92
+ this.nativeViewProtected.clearChecked();
93
+ }
94
+ }
95
+ [itemsProperty.getDefault]() {
96
+ return null;
97
+ }
98
+ [itemsProperty.setNative](value) {
99
+ this.nativeViewProtected.removeAllViews();
100
+ value?.forEach((item) => this.insertItem(item));
101
+ selectedIndexProperty.coerce(this);
102
+ }
103
+ }
104
+ //# sourceMappingURL=index.android.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.android.js","sourceRoot":"","sources":["../../src/ui-segmentedbar/index.android.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gDAAgD,CAAC;AAC3F,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,0DAA0D,CAAC;AAChH,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEpE,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAI5B,6CAA6C;AAC7C,MAAM,cAAc,GAAG,EAAE,CAAC;AAE1B;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,gBAAgB;IAIvC,gBAAgB;QACnB,OAAO,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,yBAAyB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC3F,CAAC;IAEM,cAAc;QACjB,KAAK,CAAC,cAAc,EAAE,CAAC;QACvB,MAAM,UAAU,GAAG,IAAI,CAAC,mBAAmB,CAAC;QAC5C,UAAU,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;QACpC,UAAU,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC;QACtC,wDAAwD;QACxD,UAAU,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;QACrC,MAAM,KAAK,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;QAChC,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,yBAAyB,CAAC,uBAAuB,CAAC;YACtG,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS;gBACvC,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,EAAE,C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CAAC;QAC1C,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;QAChD,qBAAqB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;CACJ"}
package/index.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * SegmentedBar component: core SegmentedBar augmented with icon items (`src`, SF Symbols with `sys://`, font icons with `font://`).
3
+ * Android uses MaterialButtonToggleGroup. iOS uses the native UISegmentedControl.
4
+ * @module @nativescript-community/ui-segmentedbar
5
+ */
6
+
7
+ import { FormattedString, ImageSource, SegmentedBar as CoreSegmentedBar, SegmentedBarItemBase } from '@nativescript/core';
8
+
9
+ export class SegmentedBarItem extends SegmentedBarItemBase {
10
+ /**
11
+ * Icon of the segment: file, resource, url, `sys://` (SF Symbol, iOS) or `font://` (font icon) path, an ImageSource, or a FormattedString (spans drawn into an icon).
12
+ * On iOS a segment shows either the title or the icon (the title wins).
13
+ */
14
+ src: string | ImageSource | FormattedString;
15
+ /**
16
+ * Rich text (spans) of the segment, it wins over the title.
17
+ * `@nativescript-community/text` is used when installed (optional).
18
+ * On iOS the spans are drawn into an image (UISegmentedControl only shows plain titles).
19
+ */
20
+ formattedText: FormattedString;
21
+ }
22
+
23
+ export class SegmentedBar extends CoreSegmentedBar {}
package/index.ios.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { SegmentedBar as CoreSegmentedBar } from '@nativescript/core';
2
+ import { itemsProperty } from '@nativescript/core/ui/segmented-bar/segmented-bar-common';
3
+ import { SegmentedBarItem } from './index-common';
4
+ export { SegmentedBarItem };
5
+ export declare class SegmentedBar extends CoreSegmentedBar {
6
+ [itemsProperty.setNative]: (value: SegmentedBarItem[]) => void;
7
+ items: SegmentedBarItem[];
8
+ updateItem(item: SegmentedBarItem): void;
9
+ }
package/index.ios.js ADDED
@@ -0,0 +1,48 @@
1
+ import { createNativeFormattedText, renderAttributedStringToImage } from '@nativescript-community/ui-core/formatted-text';
2
+ import { SegmentedBar as CoreSegmentedBar } from '@nativescript/core';
3
+ import { itemsProperty, selectedIndexProperty } from '@nativescript/core/ui/segmented-bar/segmented-bar-common';
4
+ import { SegmentedBarItem } from './index-common';
5
+ export { SegmentedBarItem };
6
+ /**
7
+ * Puts the title or the icon of the item at its position in the control.
8
+ */
9
+ function applyItem(control, item, index, insert = false) {
10
+ let title = item.title;
11
+ // a template image: tinted by the selection state
12
+ let image = item.image?.ios ? item.image.ios.imageWithRenderingMode(item.imageIsOriginal ? 1 /* UIImageRenderingMode.AlwaysOriginal */ : 2 /* UIImageRenderingMode.AlwaysTemplate */) : null;
13
+ if (item.formattedText) {
14
+ // the spans are drawn into an image: UISegmentedControl only shows plain titles
15
+ const spansImage = renderAttributedStringToImage(createNativeFormattedText(item.formattedText, item.textOwner));
16
+ if (spansImage) {
17
+ image = spansImage;
18
+ title = null;
19
+ }
20
+ else {
21
+ title = item.formattedText.toString();
22
+ }
23
+ }
24
+ if (title) {
25
+ insert ? control.insertSegmentWithTitleAtIndexAnimated(title, index, false) : control.setTitleForSegmentAtIndex(title, index);
26
+ }
27
+ else if (image) {
28
+ insert ? control.insertSegmentWithImageAtIndexAnimated(image, index, false) : control.setImageForSegmentAtIndex(image, index);
29
+ }
30
+ else if (insert) {
31
+ control.insertSegmentWithTitleAtIndexAnimated('', index, false);
32
+ }
33
+ }
34
+ export class SegmentedBar extends CoreSegmentedBar {
35
+ updateItem(item) {
36
+ const index = this.items?.indexOf(item) ?? -1;
37
+ if (this.ios && index >= 0) {
38
+ applyItem(this.ios, item, index);
39
+ }
40
+ }
41
+ [itemsProperty.setNative](value) {
42
+ const control = this.ios;
43
+ control.removeAllSegments();
44
+ value?.forEach((item, index) => applyItem(control, item, index, true));
45
+ selectedIndexProperty.coerce(this);
46
+ }
47
+ }
48
+ //# sourceMappingURL=index.ios.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.ios.js","sourceRoot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yB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAClI,CAAC;SAAM,IAAI,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,qCAAqC,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,yBAAyB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAClI,CAAC;SAAM,IAAI,MAAM,EAAE,CAAC;QAChB,OAAO,CAAC,qCAAqC,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IACpE,CAAC;AACL,CAAC;AAED,MAAM,OAAO,YAAa,SAAQ,gBAAgB;IAG9C,UAAU,CAAC,IAAsB;QAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC9C,IAAI,IAAI,CAAC,GAAG,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;YACzB,SAAS,CAAC,IAAI,CAAC,GAAyB,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QAC3D,CAAC;IACL,CAAC;IAED,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,KAAyB;QAC/C,MAAM,OAAO,GAAG,IAAI,CAAC,GAAyB,CAAC;QAC/C,OAAO,CAAC,iBAAiB,EAAE,CAAC;QAC5B,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;QACvE,qBAAqB,CAAC,MAAM,CAAC,IAAW,CAAC,CAAC;IAC9C,CAAC;CACJ"}
package/package.json CHANGED
@@ -1,6 +1,50 @@
1
1
  {
2
- "name": "@nativescript-community/ui-segmentedbar",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@nativescript-community/ui-segmentedbar",
3
+ "version": "1.0.0",
4
+ "description": "Segmented control: MaterialButtonToggleGroup on Android, native UISegmentedControl on iOS, with icon items.",
5
+ "main": "./index",
6
+ "sideEffects": false,
7
+ "typings": "./index.d.ts",
8
+ "scripts": {
9
+ "tsc": "cpy '**/*.d.ts' '../../packages/ui-segmentedbar' --parents --cwd=../../src/ui-segmentedbar && tsc --build",
10
+ "readme": "readme generate -c ../../tools/readme/blueprint.json",
11
+ "build": "npm run tsc && npm run readme",
12
+ "build.watch": "npm run tsc -- -w",
13
+ "build.all": "npm run build",
14
+ "clean": "bin/rimraf ./*.d.ts ./*.js ./*.js.map ./*.tsbuildinfo ./*.mjs ./*.mjs.map ./angular ./svelte ./vue* ./react"
15
+ },
16
+ "nativescript": {
17
+ "platforms": {
18
+ "android": "6.2.0",
19
+ "ios": "6.2.0"
20
+ }
21
+ },
22
+ "keywords": [
23
+ "NativeScript",
24
+ "JavaScript",
25
+ "Android",
26
+ "iOS"
27
+ ],
28
+ "author": {
29
+ "name": "Martin Guillon",
30
+ "email": "martin@akylas.fr"
31
+ },
32
+ "bugs": {
33
+ "url": "https://github.com/nativescript-community/ui-native-components/issues"
34
+ },
35
+ "license": "Apache-2.0",
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "homepage": "https://github.com/nativescript-community/ui-native-components/tree/master/packages/ui-segmentedbar#readme",
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "https://github.com/nativescript-community/ui-native-components.git",
43
+ "directory": "packages/ui-segmentedbar"
44
+ },
45
+ "readmeFilename": "README.md",
46
+ "dependencies": {
47
+ "@nativescript-community/ui-core": "^1.0.0"
48
+ },
49
+ "gitHead": "237dd97d2b9e0f62ea9d9810169bb800dd531f7b"
50
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "uses": [
3
+ "android.graphics.drawable:BitmapDrawable",
4
+ "android.graphics:Bitmap",
5
+ "android.widget:LinearLayout.LayoutParams",
6
+ "com.google.android.material.button:MaterialButton",
7
+ "com.google.android.material.button:MaterialButtonToggleGroup",
8
+ "com.google.android.material.button:MaterialButtonToggleGroup.OnButtonCheckedListener"
9
+ ]
10
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "uses": [
3
+ "CoreFoundation*",
4
+ "CoreGraphics*",
5
+ "Darwin*",
6
+ "Foundation*",
7
+ "ObjectiveC*",
8
+ "QuartzCore*",
9
+ "UIKit*"
10
+ ]
11
+ }
@@ -0,0 +1 @@
1
+ {"root":["../../src/ui-segmentedbar/index-common.ts","../../src/ui-segmentedbar/index.android.ts","../../src/ui-segmentedbar/index.d.ts","../../src/ui-segmentedbar/index.ios.ts","../../references.d.ts","../../tools/references.d.ts","../../src/references.d.ts"],"version":"5.8.3"}