-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #380 from kiwicom/progressbar-animation
Add back LinearProgressIndicator's animation
- Loading branch information
Showing
5 changed files
with
101 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
ui/src/test/kotlin/kiwi/orbit/compose/ui/controls/LinearProgressIndicatorTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |