Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9625e73

Browse files
committedAug 20, 2020
[Rally] README
Change-Id: I652f659f08609bd77cd0c7c4d002a847bcd2958b
1 parent 8faa91a commit 9625e73

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed
 

Diff for: ‎Rally/README.md

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Rally sample
2+
3+
This sample is a [Jetpack Compose][compose] implementation of [Rally][rally], a Material Design study. This sample showcases:
4+
5+
* [Material theming][materialtheming]
6+
* Custom layouts and reusable elements
7+
* Charts and tables
8+
* Animations
9+
10+
<img src="screenshots/rally.gif"/>
11+
12+
### Status: 🚧 In progress
13+
14+
This sample is still in under development, and some features are not yet implemented.
15+
16+
## Features
17+
18+
### Purpose
19+
This sample is a simple introduction to Material Design in Compose and it focuses on creating custom layouts and reusable elements. It uses a very simple architecture with a single activity and some hard-coded sample data. The navigation mechanism is implemented as a placeholder for an eventual official implementation using [Android Architecture Components Navigation](https://developer.android.com/guide/navigation).
20+
21+
### Custom layouts and reusable elements
22+
Rally contains screens that have very similar elements, which allows for reusing a lot of code and implementing composables that are "styled" programmatically as needed.
23+
24+
For example, [AccountsScreen](app/src/main/java/com/example/compose/rally/ui/accounts/AccountsScreen.kt) and [BillsScreen](app/src/main/java/com/example/compose/rally/ui/bills/BillsScreen.kt) wrap the same [`StatementBody`](app/src/main/java/com/example/compose/rally/ui/components/DetailsScreen.kt) composable which takes a list of _items_, their colors, amounts and even a slot to compose the item itself. Instead of passing lists with all this meta information, it's much more convenient, reusable and performant to pass functions and delegate how to fetch this information to each caller, making `StatementBody` completely generic:
25+
26+
```kotlin
27+
@Composable
28+
fun <T> StatementBody(
29+
items: List<T>,
30+
colors: (T) -> Color,
31+
amounts: (T) -> Float,
32+
rows: @Composable (T) -> Unit
33+
...
34+
```
35+
36+
```kotlin
37+
@Composable
38+
fun AccountsBody(accounts: List<Account>) {
39+
StatementBody(
40+
items = accounts,
41+
colors = { account -> account.color },
42+
amounts = { account -> account.balance },
43+
rows = { account -> AccountRow(...) }
44+
...
45+
```
46+
47+
### Theming
48+
Rally follows [Material Design][materialtheming], customizing [colors](app/src/main/java/com/example/compose/rally/ui/theme/Color.kt) and [typography](app/src/main/java/com/example/compose/rally/ui/theme/Theme.kt) used in the app via the [RallyTheme](app/src/main/java/com/example/compose/rally/ui/theme/Theme.kt). Rally's design only contains a dark theme, therefore the theme does not contain any light colors.
49+
50+
### Charts and animations
51+
This sample features a donut chart that combines drawing using [`Canvas`](https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Canvas) with animations combining two animated parameters: `AngleOffset` and `Shift`. This creates the animation with minimum boilerplate:
52+
53+
```kotlin
54+
private enum class AnimatedCircleProgress { START, END }
55+
56+
private val CircularTransition = transitionDefinition<AnimatedCircleProgress> {
57+
state(AnimatedCircleProgress.START) {
58+
this[AngleOffset] = 0f
59+
this[Shift] = 0f
60+
}
61+
state(AnimatedCircleProgress.END) {
62+
this[AngleOffset] = 360f
63+
this[Shift] = 30f
64+
}
65+
transition(fromState = AnimatedCircleProgress.START, toState = AnimatedCircleProgress.END) {
66+
AngleOffset using tween(
67+
delayMillis = 500,
68+
durationMillis = 900,
69+
easing = CubicBezierEasing(0f, 0.75f, 0.35f, 0.85f)
70+
)
71+
Shift using tween(
72+
delayMillis = 500,
73+
durationMillis = 900,
74+
easing = LinearOutSlowInEasing
75+
)
76+
}
77+
}
78+
```
79+
80+
<img src="screenshots/donut.gif"/>
81+
82+
## License
83+
```
84+
Copyright 2020 The Android Open Source Project
85+
86+
Licensed under the Apache License, Version 2.0 (the "License");
87+
you may not use this file except in compliance with the License.
88+
You may obtain a copy of the License at
89+
90+
https://www.apache.org/licenses/LICENSE-2.0
91+
92+
Unless required by applicable law or agreed to in writing, software
93+
distributed under the License is distributed on an "AS IS" BASIS,
94+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
95+
See the License for the specific language governing permissions and
96+
limitations under the License.
97+
```
98+
99+
[compose]: https://developer.android.com/jetpack/compose
100+
[rally]: https://material.io/design/material-studies/rally.html
101+
[materialtheming]: https://material.io/design/material-theming/overview.html#material-theming

Diff for: ‎Rally/screenshots/donut.gif

76.7 KB
Loading

Diff for: ‎Rally/screenshots/rally.gif

1.08 MB
Loading

0 commit comments

Comments
 (0)
Failed to load comments.