|
1 | 1 | ---
|
2 | 2 | title: Progress
|
| 3 | +description: UI component to indicate the progress of a task. |
| 4 | +contributors: |
| 5 | + - rigor789 |
| 6 | + - Ombuweb |
3 | 7 | ---
|
4 | 8 |
|
5 | 9 | `<Progress>` is a UI component that shows a bar to indicate the progress of a task.
|
6 | 10 |
|
7 | 11 | See also: [ActivityIndicator](/ui/activity-indicator).
|
8 | 12 |
|
9 |
| ---- |
10 |
| - |
11 | 13 | <DeviceFrame type="ios">
|
12 |
| -<img src="https://raw.githubusercontent.com/nativescript-vue/nativescript-vue-ui-tests/master/screenshots/ios-simulator103iPhone6/Progress.png"/> |
| 14 | +<img src="../screenshots/ios/Progress.png"/> |
13 | 15 | </DeviceFrame>
|
14 | 16 | <DeviceFrame type="android">
|
15 |
| -<img src="https://raw.githubusercontent.com/nativescript-vue/nativescript-vue-ui-tests/master/screenshots/android23/Progress.png" /> |
| 17 | +<img src="../screenshots/android/Progress.png"/> |
16 | 18 | </DeviceFrame>
|
17 | 19 |
|
18 |
| -### Creating a Progress |
19 |
| - |
20 |
| -<!-- /// flavor plain --> |
21 |
| - |
22 |
| -```xml |
23 |
| -<Progress |
24 |
| - width="100%" |
25 |
| - value="{{ progressValue }}" |
26 |
| - maxValue="{{ progressMaxValue }}" |
27 |
| - loaded="onProgressLoaded" |
28 |
| -/> |
29 |
| -``` |
30 |
| - |
31 |
| -```ts |
32 |
| -import { |
33 |
| - Observable, |
34 |
| - Page, |
35 |
| - Progress, |
36 |
| - PropertyChangeData, |
37 |
| -} from '@nativescript/core' |
38 |
| - |
39 |
| -export function onNavigatingTo(args) { |
40 |
| - const page = args.object as Page |
41 |
| - vm.set('progressValue', 10) // Initial value |
42 |
| - vm.set('progressMaxValue', 100) // Maximum value |
43 |
| - // Forcing progress value change (for demonstration) |
44 |
| - setInterval(() => { |
45 |
| - const value = vm.get('progressValue') |
46 |
| - vm.set('progressValue', value + 2) |
47 |
| - }, 300) |
48 |
| - page.bindingContext = vm |
49 |
| -} |
50 |
| -export function onProgressLoaded(args) { |
51 |
| - const myProgressBar = args.object as Progress |
52 |
| - myProgressBar.on('valueChange', (pargs: PropertyChangeData) => { |
53 |
| - // TIP: args (for valueChange of Progress) is extending EventData with oldValue & value parameters |
54 |
| - console.log(`Old Value: ${pargs.oldValue}`) |
55 |
| - console.log(`New Value: ${pargs.value}`) |
56 |
| - }) |
57 |
| -} |
58 |
| -``` |
59 |
| - |
60 |
| -<!-- /// |
| 20 | +<<< @/../examples/src/ui/Progress/template.xml#example |
61 | 21 |
|
62 |
| -/// flavor angular |
| 22 | +## Example |
63 | 23 |
|
64 |
| -```xml |
65 |
| -<progress value="25" maxValue="100" (valueChanged)="onValueChanged($event)"></progress> |
66 |
| -``` |
67 |
| -
|
68 |
| -```ts |
69 |
| -import { Component, OnInit } from '@angular/core' |
70 |
| -
|
71 |
| -@Component({ |
72 |
| - moduleId: module.id, |
73 |
| - templateUrl: './styling.component.html', |
74 |
| - styleUrls: ['./styling.component.css'] |
75 |
| -}) |
76 |
| -export class StylingComponent implements OnInit { |
77 |
| - public progressValue: number |
78 |
| -
|
79 |
| - ngOnInit() { |
80 |
| - this.progressValue = 25 |
81 |
| - } |
82 |
| -} |
83 |
| -``` |
84 |
| -
|
85 |
| -/// |
| 24 | +### Styling the Progress bar |
86 | 25 |
|
87 |
| -/// flavor react |
| 26 | +To style the Progress bar, set the `backgroundColor` and `color`. |
88 | 27 |
|
89 |
| -```tsx |
90 |
| -function getTaskCompletionPercent() { |
91 |
| - // Just a stub method to illustrate the concept. |
92 |
| - return 10 |
93 |
| -} |
94 |
| -
|
95 |
| -;<progress value={getTaskCompletionPercent()} maxValue={100} /> |
96 |
| -``` |
97 |
| -
|
98 |
| -/// |
99 |
| -
|
100 |
| -/// flavor vue |
| 28 | +The `backgroundColor` will be applied to the track, and the `color` will be applied to the bar itself. |
101 | 29 |
|
102 | 30 | ```xml
|
103 |
| -<progress :value="currentProgress" /> |
104 |
| -``` |
105 |
| -
|
106 |
| -/// |
107 |
| -
|
108 |
| -/// flavor svelte |
109 |
| -
|
110 |
| -```xml |
111 |
| -<progress value="{currentProgress}" /> |
112 |
| -``` |
113 |
| -
|
114 |
| -/// --> |
115 |
| - |
116 |
| -### Styling Progress |
117 |
| - |
118 |
| -Using `backgroundColor` (**CSS**: `background-color`) & color to change the Progress style. |
119 |
| - |
120 |
| -:::tip Note |
121 |
| -`backgroundColor` will work only on `iOS`; on `Android` the background will be the color with applied opacity. |
122 |
| -::: |
123 |
| - |
124 |
| -```xml |
125 |
| -<progress |
126 |
| - value="50" |
127 |
| - maxValue="100" |
128 |
| - backgroundColor="red" |
129 |
| - color="green" |
130 |
| -></progress> |
131 |
| -<!-- Using @nativescript/tailwind to change the Progress style --> |
132 |
| -<progress value="25" maxValue="100" class="bg-red-500 text-red-900"></progress> |
| 31 | +<Progress |
| 32 | + value="75" |
| 33 | + backgroundColor="#fff" |
| 34 | + color="#000" |
| 35 | +/> |
133 | 36 | ```
|
134 | 37 |
|
135 | 38 | ## Props
|
136 | 39 |
|
137 | 40 | ### value
|
138 | 41 |
|
139 |
| -```xml |
140 |
| -<Progress value="{{ progressValue }}" /> |
| 42 | +```ts |
| 43 | +value: number |
141 | 44 | ```
|
142 | 45 |
|
143 |
| -ets or sets the current value of the progress bar. Must be within the range of 0 to [maxValue](#maxvalue). |
| 46 | +Gets or sets the current value of the progress bar. |
144 | 47 |
|
145 |
| ---- |
| 48 | +Must be within the range of 0 to [maxValue](#maxValue). |
146 | 49 |
|
147 |
| -### maxValue |
| 50 | +### maxValue {#maxValue} |
148 | 51 |
|
149 |
| -```xml |
150 |
| -<Progress maxValue="{{ progressMaxValue }}" /> |
| 52 | +```ts |
| 53 | +maxValue: number |
151 | 54 | ```
|
152 | 55 |
|
153 |
| -Gets or sets the maximum value of the progress bar. Defaults to: `100`. |
| 56 | +Gets or sets the maximum value of the progress bar. |
154 | 57 |
|
155 |
| ---- |
| 58 | +Defaults to: `100`. |
156 | 59 |
|
157 | 60 | ### ...Inherited
|
158 | 61 |
|
159 |
| -For additional inherited properties, refer to the [API Reference](https://docs.nativescript.org/api-reference/classes/progress) |
160 |
| - |
161 |
| -## Events |
162 |
| - |
163 |
| -### valueChange |
164 |
| - |
165 |
| -Emitted when the `value` property changes. |
166 |
| - |
167 |
| ---- |
| 62 | +For additional inherited properties, refer to the [API Reference](/api/class/Progress) |
168 | 63 |
|
169 | 64 | ## Native Component
|
170 | 65 |
|
|
0 commit comments