• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Indicator
2
3The **Indicator** component provides two types of navigation indicators: dot indicators and digit indicators.
4
5It extracts the existing capabilities of the [Indicator](ts-container-swiper.md#indicator) from the existing [Swiper](ts-container-swiper.md) component and makes them available as a standalone component. You can use the **Indicator** component independently or bind it to a **Swiper** component through **IndicatorComponentController**.
6
7When multiple **Indicator** components are bound to a single **Swiper**, only the last bound **Indicator** is active.
8
9Similarly, if an **Indicator** is bound to multiple **Swiper** components, only the last bound **Swiper** works with the **Indicator**.
10
11>  **NOTE**
12>
13> This component is supported since API version 15. Updates will be marked with a superscript to indicate their earliest API version.
14
15
16## Child Components
17
18Not supported
19
20## APIs
21
22IndicatorComponent(controller?: IndicatorComponentController)
23
24A constructor used to create an **Indicator** component. You can optionally pass a controller to manage the **Indicator** component.
25
26**Widget capability**: This API can be used in ArkTS widgets since API version 15.
27
28**Atomic service API**: This API can be used in atomic services since API version 15.
29
30**System capability**: SystemCapability.ArkUI.ArkUI.Full
31
32**Parameters**
33
34|Name|Type|Mandatory|Description|
35| ----- | ----- | -- |  --- |
36| controller |  [IndicatorComponentController](#indicatorcomponentcontroller) | No| Controller to manage the **Indicator** component.|
37
38## Attributes
39
40In addition to the [universal attributes](ts-component-general-attributes.md), the following attributes are supported.
41
42### style
43
44style(indicatorStyle: DotIndicator | DigitIndicator)
45
46Sets the style of the navigation indicator.
47
48**Widget capability**: This API can be used in ArkTS widgets since API version 15.
49
50**Atomic service API**: This API can be used in atomic services since API version 15.
51
52**System capability**: SystemCapability.ArkUI.ArkUI.Full
53
54**Parameters**
55
56| Name| Type                                                        | Mandatory| Description                                                        |
57| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
58| indicatorStyle  | [DotIndicator](ts-container-swiper.md#dotindicator10) \| [DigitIndicator](ts-container-swiper.md#digitindicator10) | Yes  | Style of the navigation indicator.<br> \- **DotIndicator**: dot style.<br> \- **DigitIndicator**: digit style.<br>  Default style: **DotIndicator**|
59
60### count
61
62count(totalCount: number)
63
64Sets the total number of navigation points.
65
66When the **Indicator** component is used with a **Swiper** component, the count is subject to the number of pages in the **Swiper** component.
67
68**Widget capability**: This API can be used in ArkTS widgets since API version 15.
69
70**Atomic service API**: This API can be used in atomic services since API version 15.
71
72**System capability**: SystemCapability.ArkUI.ArkUI.Full
73
74**Parameters**
75
76| Name| Type  | Mandatory| Description                                            |
77| ------ | ------ | ---- | ------------------------------------------------ |
78| totalCount  | number | Yes  |  Total number of navigation points.<br>Default value: **2**|
79
80### initialIndex
81
82initialIndex(index: number)
83
84Sets the initial index of the navigation indicator when it first appears. If the value is less than 0 or greater than or equal to the total count, the default value **0** is used.
85
86This attribute does not take effect when the **Indicator** component is bound to a **Swiper** component.
87
88**Widget capability**: This API can be used in ArkTS widgets since API version 15.
89
90**Atomic service API**: This API can be used in atomic services since API version 15.
91
92**System capability**: SystemCapability.ArkUI.ArkUI.Full
93
94**Parameters**
95
96| Name| Type  | Mandatory| Description                                            |
97| ------ | ------ | ---- | ------------------------------------------------ |
98| index  | number | Yes  | Initial index of the navigation indicator when it first appears.<br>Default value: **0**|
99
100### loop
101
102loop(isLoop: boolean)
103
104Sets whether to enable looping. The value **true** means to enable looping.
105
106This attribute does not take effect when the **Indicator** component is bound to a **Swiper** component.
107
108**Widget capability**: This API can be used in ArkTS widgets since API version 15.
109
110**Atomic service API**: This API can be used in atomic services since API version 15.
111
112**System capability**: SystemCapability.ArkUI.ArkUI.Full
113
114**Parameters**
115
116| Name| Type   | Mandatory| Description                           |
117| ------ | ------- | ---- | ------------------------------- |
118| isLoop  | boolean | Yes  | Whether to enable looping.<br>Default value: **true**|
119
120### vertical
121
122vertical(isVertical: boolean)
123
124Sets whether the navigation is vertical.
125
126This attribute does not take effect when the **Indicator** component is bound to a **Swiper** component.
127
128**Widget capability**: This API can be used in ArkTS widgets since API version 15.
129
130**Atomic service API**: This API can be used in atomic services since API version 15.
131
132**System capability**: SystemCapability.ArkUI.ArkUI.Full
133
134**Parameters**
135
136| Name| Type   | Mandatory| Description                              |
137| ------ | ------- | ---- | ---------------------------------- |
138| isVertical  | boolean | Yes  | Whether the navigation is vertical.<br>Default value: **false**|
139
140## Events
141
142In addition to the [universal events](ts-component-general-events.md), the following events are supported.
143
144### onChange
145
146onChange(event: Callback\<number>)
147
148Triggered when the currently selected navigation index changes. The callback provides the new index.
149
150**Widget capability**: This API can be used in ArkTS widgets since API version 15.
151
152**Atomic service API**: This API can be used in atomic services since API version 15.
153
154**System capability**: SystemCapability.ArkUI.ArkUI.Full
155
156**Parameters**
157
158| Name| Type  | Mandatory| Description                |
159| ------ | ------ | ---- | -------------------- |
160| event  | [Callback](./ts-types.md#callback12)\<number> | Yes  | Callback triggered when the index changes.|
161
162## IndicatorComponentController
163
164Implements a controller for the **Indicator** component, allowing you to control navigation.
165
166### constructor
167
168constructor()
169
170A constructor used to create an **IndicatorComponentController** object.
171
172**Widget capability**: This API can be used in ArkTS widgets since API version 15.
173
174**Atomic service API**: This API can be used in atomic services since API version 15.
175
176**System capability**: SystemCapability.ArkUI.ArkUI.Full
177
178### showNext
179
180showNext(): void
181
182Moves to the next navigation point.
183
184**Widget capability**: This API can be used in ArkTS widgets since API version 15.
185
186**Atomic service API**: This API can be used in atomic services since API version 15.
187
188**System capability**: SystemCapability.ArkUI.ArkUI.Full
189
190### showPrevious
191
192showPrevious(): void
193
194Moves to the previous navigation point.
195
196**Widget capability**: This API can be used in ArkTS widgets since API version 15.
197
198**Atomic service API**: This API can be used in atomic services since API version 15.
199
200**System capability**: SystemCapability.ArkUI.ArkUI.Full
201
202### changeIndex
203
204changeIndex(index: number, useAnimation?: boolean): void
205
206Moves to a specific navigation index.
207
208**Widget capability**: This API can be used in ArkTS widgets since API version 15.
209
210**Atomic service API**: This API can be used in atomic services since API version 15.
211
212**System capability**: SystemCapability.ArkUI.ArkUI.Full
213
214**Parameters**
215
216| Name     | Type      | Mandatory | Description    |
217| -------- | ---------- | ---- | -------- |
218| index| number | Yes   | Target navigation index.|
219| useAnimation| boolean | No   | Whether to use an animation for when the target index is reached. The value **true** means to use an animation, and **false** means the opposite.<br>Default value: **false**|
220
221## Example
222
223### Example 1: Using a Dot Indicator with a Swiper Component
224This example shows how to bind a dot-style **Indicator** component to a **Swiper **component using **IndicatorComponentController**.
225```
226@Entry
227@Component
228struct DotIndicatorDemo {
229  private indicatorController: IndicatorComponentController = new IndicatorComponentController()
230  private swiperController: SwiperController = new SwiperController()
231  @State list: number[] = []
232  aboutToAppear(): void {
233    for (let i = 1; i <= 6; i++) {
234      this.list.push(i);
235    }
236  }
237
238  build() {
239    Column() {
240      Swiper(this.swiperController) {
241        ForEach(this.list, (item: string) => {
242          Text(item.toString())
243            .width('100%')
244            .height(160)
245            .backgroundColor(0xAFEEEE)
246            .textAlign(TextAlign.Center)
247            .fontSize(30)
248        }, (item: string) => item)
249      }
250      .cachedCount(2)
251      .index(0)
252      .autoPlay(true)
253      .interval(2000)
254      .indicator(this.indicatorController)
255      .loop(true)
256      .duration(1000)
257      .itemSpace(0)
258      .curve(Curve.Linear)
259      .onChange((index: number) => {
260        console.info(index.toString())
261      })
262
263      IndicatorComponent(this.indicatorController)
264        .initialIndex(0)
265        .style(
266          new DotIndicator()
267            .itemWidth(15)
268            .itemHeight(15)
269            .selectedItemWidth(15)
270            .selectedItemHeight(15)
271            .color(Color.Gray)
272            .selectedColor(Color.Blue))
273        .loop(true)
274        .count(6)
275        .vertical(true)
276        .onChange((index: number) => {
277          console.log("current index: " + index )
278        })
279    }
280  }
281}
282```
283![bindIndicatorDotStyle](figures/bindIndicatorDotStyle.gif)
284
285### Example 2: Using a Digit Indicator with a Swiper Component
286
287This example shows how to bind a digit-style **Indicator** component to a **Swiper **component using **IndicatorComponentController**.
288
289```
290@Entry
291@Component
292struct DigitIndicatorDemo {
293  private indicatorController: IndicatorComponentController = new IndicatorComponentController()
294  private swiperController: SwiperController = new SwiperController()
295  @State list: number[] = []
296  aboutToAppear(): void {
297    for (let i = 1; i <= 6; i++) {
298      this.list.push(i);
299    }
300  }
301
302  build() {
303    Column() {
304      Swiper(this.swiperController) {
305        ForEach(this.list, (item: string) => {
306          Text(item.toString())
307            .width('100%')
308            .height(160)
309            .backgroundColor(0xAFEEEE)
310            .textAlign(TextAlign.Center)
311            .fontSize(30)
312        }, (item: string) => item)
313      }
314      .cachedCount(2)
315      .index(0)
316      .autoPlay(true)
317      .interval(2000)
318      .indicator(this.indicatorController)
319      .loop(true)
320      .duration(1000)
321      .itemSpace(0)
322      .curve(Curve.Linear)
323      .onChange((index: number) => {
324        console.info(index.toString())
325      })
326
327      IndicatorComponent(this.indicatorController)
328        .initialIndex(0)
329        .style(Indicator.digit()
330          .fontColor(Color.Gray)
331          .selectedFontColor(Color.Gray)
332          .digitFont({ size: 20, weight: FontWeight.Bold })
333          .selectedDigitFont({ size: 20, weight: FontWeight.Normal }))
334        .loop(true)
335        .count(6)
336        .vertical(true)
337        .onChange((index: number) => {
338          console.log("current index: " + index )
339        })
340    }
341  }
342}
343```
344
345![bindIndicatorDigitStyle](figures/bindIndicatorDigitStyle.gif)
346