Skip to content

Commit

Permalink
add LinearProgressIndicator docs
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed Mar 21, 2023
1 parent 5ff16f5 commit c4c1285
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
47 changes: 47 additions & 0 deletions docs/03-components/10-progress-indicators/loading.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
title: Android
---

## Overview

Orbit Compose offers multiple components to visualize loading::

- [`LinearProgressIndicator`](https://kiwicom.github.io/orbit-compose/ui/kiwi.orbit.compose.ui.controls/-linear-progress-indicator.html)
- [`LinearIndeterminateProgressIndicator`](https://kiwicom.github.io/orbit-compose/ui/kiwi.orbit.compose.ui.controls/-linear-indeterminate-progress-indicator.html)

## Usage

Use `LinearProgressIndicator` composable and define a state a progress value. By default, all progress value changes are animated. Pass a custom animation specification via `progressAnimationSpec`. To disable animation, use `snap()` animation.

```kotlin
@Composable
fun Example(progress: Float) {
LinearProgressIndicator(
progress = progress,
)
}
```

## UI Testing

Use semantic properties and action to set progress and read the state.

```kotlin
composeTestRule.setContent {
LinearProgressIndicator(
progress = 0.4f,
modifier = Modifier.testTag("loader"),
)
}

val progressBarInfo = composeTestRule
.onNodeWithTag("loader")
.fetchSemanticsNode()
.config[SemanticsProperties.ProgressBarRangeInfo]

Assert.assertEquals(0.4f, progressBarInfo.current)
```

## Customization

To change track colors use `color` and `backgroundColor` arguments.
1 change: 1 addition & 0 deletions docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
1. [ButtonPrimitive](03-components/15-primitives/buttonprimitive.mdx)
1. [Button](03-components/01-action/button.mdx)
1. [Card](03-components/02-structure/card.mdx)
1. [Loading / LinearProgressIndicator](03-components/10-progress-indicators/loading.mdx)
1. [Slider](03-components/07-interaction/slider.mdx)
1. [Tabs](03-components/02-structure/tabs.mdx)
1. [Tile](03-components/02-structure/tile.mdx)
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package kiwi.orbit.compose.ui.controls

import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.SemanticsProperties
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import org.junit.Assert
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner

@RunWith(RobolectricTestRunner::class)
internal class LinearProgressIndicatorTest {
@get:Rule
val composeTestRule = createComposeRule()

@Test
fun testBasics() {
composeTestRule.setContent {
LinearProgressIndicator(
progress = 0.4f,
modifier = Modifier.testTag("loader"),
)
}
val progressBarInfo = composeTestRule
.onNodeWithTag("loader")
.fetchSemanticsNode()
.config[SemanticsProperties.ProgressBarRangeInfo]
Assert.assertEquals(0.4f, progressBarInfo.current)
}
}

0 comments on commit c4c1285

Please sign in to comment.