|
1 | | -# Orchestra |
2 | | -🎺 Compatible libraries by Balloon, ColorPickerView, PowerSpinner for use in Jetpack Compose. |
| 1 | + |
| 2 | +<h1 align="center">Orchestra</h1></br> |
| 3 | + |
| 4 | +<p align="center"> |
| 5 | + <a href="https://opensource.org/licenses/Apache-2.0"><img alt="License" src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"/></a> |
| 6 | + <a href="https://android-arsenal.com/api?level=21"><img alt="API" src="https://img.shields.io/badge/API-21%2B-brightgreen.svg?style=flat"/></a> |
| 7 | + <a href="https://github.com/skydoves"><img alt="Profile" src="https://skydoves.github.io/badges/skydoves.svg"/></a> |
| 8 | +</p> |
| 9 | + |
| 10 | +<p align="center"> |
| 11 | +🎺 Jetpack Compose compatible libraries using Balloon, ColorPickerView, PowerSpinner. |
| 12 | +</p> |
| 13 | +<p align="center"> |
| 14 | +<img src="https://user-images.githubusercontent.com/24237865/61194943-f9d70380-a6ff-11e9-807f-ba1ca8126f8a.gif" width="32%"/> |
| 15 | +<img src="https://user-images.githubusercontent.com/24237865/95007367-d58b7d80-0649-11eb-857b-9e0187be70d1.gif" width="30.4%"/> |
| 16 | +<img src="https://user-images.githubusercontent.com/24237865/71962685-534a6600-323d-11ea-9e1e-df1f68cb2181.gif" width="32%"/> |
| 17 | +</p> |
| 18 | + |
| 19 | +<img src="https://user-images.githubusercontent.com/24237865/95007576-3caa3180-064c-11eb-815b-b995f45bb18a.gif" align="right" width="32%"/> |
| 20 | + |
| 21 | +## Balloon |
| 22 | +And add a dependency code to your **module**'s `build.gradle` file. |
| 23 | +```gradle |
| 24 | +dependencies { |
| 25 | + implementation "com.github.skydoves:orchestra-balloon:1.0.0" |
| 26 | +} |
| 27 | +``` |
| 28 | + |
| 29 | +### Usage |
| 30 | +`BalloonAnchor` composable can be used in `ConstraintLayout` and it receives a constraint reference. In the below, `BalloonAnchor` references `image` composable. When clicked the `image` composable, balloon popup will be shown. |
| 31 | +```kotlin |
| 32 | +ConstraintLayout { |
| 33 | + val (image, title, content, message) = createRefs() |
| 34 | + |
| 35 | + // image, title, content, message // |
| 36 | + |
| 37 | + BalloonAnchor( |
| 38 | + reference = image, |
| 39 | + modifier = Modifier.aspectRatio(0.8f), |
| 40 | + balloon = BalloonUtils.getTitleBalloon( |
| 41 | + context = context, |
| 42 | + title = poster.name, |
| 43 | + lifecycle = lifecycleOwner |
| 44 | + ), |
| 45 | + onAnchorClick = { balloon, anchor -> balloon.show(anchor) }, |
| 46 | + onClickIndication = RippleIndication(color = purple500) |
| 47 | + ) |
| 48 | +``` |
| 49 | +Or we can create a `BalloonAnchor` composable using [Balloon.Factory](https://github.com/skydoves/balloon#lazy-initialization). |
| 50 | +```kotlin |
| 51 | +BalloonAnchor( |
| 52 | + reference = image, |
| 53 | + modifier = Modifier.aspectRatio(0.8f), |
| 54 | + factory = MyBalloonFactory::class, |
| 55 | + onAnchorClick = { balloon, anchor -> balloon.show(anchor) }, |
| 56 | + onBalloonClick = { }, |
| 57 | + onBalloonDismiss = { }, |
| 58 | + onBalloonInitialized = { content -> }, |
| 59 | + onBalloonOutsideTouch = { content, event -> }, |
| 60 | + onClickIndication = RippleIndication(color = purple500) |
| 61 | +) |
| 62 | +``` |
| 63 | + |
| 64 | +<img src="https://user-images.githubusercontent.com/24237865/95007577-416ee580-064c-11eb-92b7-ad30c5b36da0.gif" align="right" width="32%"/> |
| 65 | + |
| 66 | +## ColorPicker |
| 67 | +And add a dependency code to your **module**'s `build.gradle` file. |
| 68 | +```gradle |
| 69 | +dependencies { |
| 70 | + implementation "com.github.skydoves:orchestra-colorpicker:1.0.0" |
| 71 | +} |
| 72 | +``` |
| 73 | +
|
| 74 | +### Usage |
| 75 | +`ColorPicker` composable implements a color picker with `AlphaSlideBar` and `BrightnessSlideBar`. We can create an alpha sidebar and brightness sidebar for changing saturation and lightness by tapping on the desired color. They should be used in `children` inner composable in `ColorPicker`, and they receive a `colorPickerView` as a parameter. |
| 76 | +```kotlin |
| 77 | +val (selectedColor, setSelectedColor) = remember { mutableStateOf(ColorEnvelope(0)) } |
| 78 | +ColorPicker( |
| 79 | + modifier = modifier.constrainAs(colorPicker) { |
| 80 | + centerHorizontallyTo(parent) |
| 81 | + }.fillMaxWidth().height(400.dp), |
| 82 | + onColorListener = { envelope, _ -> |
| 83 | + setSelectedColor(envelope) |
| 84 | + }, |
| 85 | + initialColor = purple500, |
| 86 | + children = { colorPickerView -> |
| 87 | + Column(modifier = Modifier.padding(top = 32.dp)) { |
| 88 | + Box(modifier = Modifier.padding(vertical = 6.dp)) { |
| 89 | + AlphaSlideBar( |
| 90 | + modifier = Modifier.fillMaxWidth().height(30.dp) |
| 91 | + .clip(RoundedCornerShape(4.dp)), |
| 92 | + colorPickerView = colorPickerView |
| 93 | + ) |
| 94 | + } |
| 95 | + Box(modifier = Modifier.padding(vertical = 6.dp)) { |
| 96 | + BrightnessSlideBar( |
| 97 | + modifier = Modifier.fillMaxWidth().height(30.dp) |
| 98 | + .clip(RoundedCornerShape(4.dp)), |
| 99 | + colorPickerView = colorPickerView |
| 100 | + ) |
| 101 | + } |
| 102 | + } |
| 103 | + } |
| 104 | + ) |
| 105 | +``` |
| 106 | +### AlphaTileBox |
| 107 | +In a normal View, it can not represent ARGB colors accurately. Because a color will be mixed with the parent's background-color. For resolving it we can use `AlphaTileBox` composable. `AlphaTileBox` composable reflects ARGB colors. |
| 108 | +```kotlin |
| 109 | +AlphaTileBox( |
| 110 | + modifier = modifier.constrainAs(square) { |
| 111 | + bottom.linkTo(parent.bottom) |
| 112 | + centerHorizontallyTo(parent) |
| 113 | + }.size(64.dp).clip(RoundedCornerShape(4.dp)) |
| 114 | +) { |
| 115 | + it.setBackgroundColor(selectedColor.color) |
| 116 | +} |
| 117 | +``` |
| 118 | + |
| 119 | +<img src="https://user-images.githubusercontent.com/24237865/95007578-42a01280-064c-11eb-9081-e5567274c9ba.gif" align="right" width="32%"/> |
| 120 | + |
| 121 | +## Spinner |
| 122 | +And add a dependency code to your **module**'s `build.gradle` file. |
| 123 | +```gradle |
| 124 | +dependencies { |
| 125 | + implementation "com.github.skydoves:orchestra-spinner:1.0.0" |
| 126 | +} |
| 127 | +``` |
| 128 | +
|
| 129 | +### Usage |
| 130 | +`Spinner` composable implements a lightweight dropdown popup spinner. Here is an example for creating a spinner using a sting array resource. We should use the String generic type for creating a spinner when we us a string array resource. |
| 131 | +
|
| 132 | +```kotlin |
| 133 | + val (selectedItem0, setSelectedItem0) = remember { mutableStateOf("Choose a question") } |
| 134 | + Spinner<String>( |
| 135 | + text = selectedItem0, |
| 136 | + modifier = Modifier.fillMaxWidth().padding(16.dp) |
| 137 | + .background(blue200) |
| 138 | + .align(Alignment.CenterHorizontally), |
| 139 | + itemListRes = R.array.list_spinner, |
| 140 | + color = Color.White, |
| 141 | + style = MaterialTheme.typography.body2, |
| 142 | + textAlign = TextAlign.Center, |
| 143 | + showDivider = true, |
| 144 | + dividerColor = white87, |
| 145 | + overflow = TextOverflow.Ellipsis, |
| 146 | + maxLines = 1, |
| 147 | + spinnerPadding = 16.dp, |
| 148 | + spinnerBackgroundColor = MaterialTheme.colors.onBackground, |
| 149 | + onSpinnerItemSelected = { index, item -> |
| 150 | + setSelectedItem0(item) |
| 151 | + } |
| 152 | + ) |
| 153 | +``` |
| 154 | +Here is an another example using a List for creating a spinner. In this case, we don't need to decide a generic type of Spinner. |
| 155 | + |
| 156 | +```kotlin |
| 157 | + val coffeeList = remember { listOf("Americano", "Cold Brew", "Espresso", "Latte") } |
| 158 | + val (selectedItem1, setSelectedItem1) = remember { mutableStateOf("Choose your coffee") } |
| 159 | + Spinner( |
| 160 | + text = selectedItem1, |
| 161 | + modifier = Modifier.fillMaxWidth().padding(16.dp) |
| 162 | + .background(amber700) |
| 163 | + .align(Alignment.CenterHorizontally), |
| 164 | + itemList = coffeeList, |
| 165 | + color = Color.White, |
| 166 | + style = MaterialTheme.typography.body2, |
| 167 | + textAlign = TextAlign.Center, |
| 168 | + dividerColor = white87, |
| 169 | + overflow = TextOverflow.Ellipsis, |
| 170 | + maxLines = 1, |
| 171 | + spinnerPadding = 16.dp, |
| 172 | + spinnerBackgroundColor = MaterialTheme.colors.onBackground, |
| 173 | + onSpinnerItemSelected = { index, item -> |
| 174 | + setSelectedItem1(item) |
| 175 | + } |
| 176 | + ) |
| 177 | +``` |
| 178 | + |
| 179 | +## Find this repository useful? :heart: |
| 180 | +Support it by joining __[stargazers](https://github.com/skydoves/Orchestra/stargazers)__ for this repository. :star: <br> |
| 181 | +And __[follow](https://github.com/skydoves)__ me for my next creations! 🤩 |
| 182 | + |
| 183 | +# License |
| 184 | +```xml |
| 185 | +Designed and developed by 2020 skydoves (Jaewoong Eum) |
| 186 | + |
| 187 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 188 | +you may not use this file except in compliance with the License. |
| 189 | +You may obtain a copy of the License at |
| 190 | + |
| 191 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 192 | + |
| 193 | +Unless required by applicable law or agreed to in writing, software |
| 194 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 195 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 196 | +See the License for the specific language governing permissions and |
| 197 | +limitations under the License. |
| 198 | +``` |
0 commit comments