-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Koa-4921 Created Bpk Fab in Compose (#1233)
* Create component for FAB in Compose * Create a FAB story for demo app and update component registry * Create snapshot test for FAB * Change dimensions for snapshot test * Create readme file for the component * Delete unnecessary imports and code * Update DocsRegistry * Correct error in DocsRegistry * Update screenshots * Update Lint rules * Fix properties in BpkFab.kt * Review PR comments * Fix typo * Review PR comments * Review further PR comments * Fix trailing lambda issue in Readme * Updated the snapshots. * Remove fab examples from Themestory.kt Co-authored-by: bvitaliyg <[email protected]>
- Loading branch information
1 parent
6a9b48e
commit ca44797
Showing
14 changed files
with
213 additions
and
15 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions
46
app/src/androidTest/java/net/skyscanner/backpack/compose/fab/BpkFabTest.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,46 @@ | ||
/* | ||
* Backpack for Android - Skyscanner's Design System | ||
* | ||
* Copyright 2018 Skyscanner Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package net.skyscanner.backpack.compose.fab | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import net.skyscanner.backpack.BpkSnapshotTest | ||
import net.skyscanner.backpack.compose.icon.BpkIcon | ||
import net.skyscanner.backpack.compose.tokens.Search | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class BpkFabTest : BpkSnapshotTest() { | ||
|
||
@Before | ||
fun setup() { | ||
setDimensions(height = 80, width = 80) | ||
} | ||
|
||
@Test | ||
fun default() = composed { | ||
BpkFab( | ||
onClick = {}, | ||
icon = BpkIcon.Search, | ||
contentDescription = "Content description", | ||
) | ||
} | ||
} |
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
69 changes: 69 additions & 0 deletions
69
app/src/main/java/net/skyscanner/backpack/demo/compose/BpkFabStory.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,69 @@ | ||
/* | ||
* Backpack for Android - Skyscanner's Design System | ||
* | ||
* Copyright 2018 Skyscanner Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package net.skyscanner.backpack.demo.compose | ||
|
||
import android.content.Context | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.stringResource | ||
import net.skyscanner.backpack.compose.fab.BpkFab | ||
import net.skyscanner.backpack.compose.icon.BpkIcon | ||
import net.skyscanner.backpack.compose.tokens.BpkSpacing | ||
import net.skyscanner.backpack.compose.tokens.Flight | ||
import net.skyscanner.backpack.compose.tokens.Search | ||
import net.skyscanner.backpack.compose.tokens.Star | ||
import net.skyscanner.backpack.demo.R | ||
import net.skyscanner.backpack.toast.BpkToast | ||
|
||
@Composable | ||
fun BpkFabStory() { | ||
Column( | ||
modifier = Modifier.padding(BpkSpacing.Xl), | ||
verticalArrangement = Arrangement.spacedBy(BpkSpacing.Xxl, Alignment.CenterVertically), | ||
) { | ||
val context = LocalContext.current | ||
BpkFab( | ||
onClick = { showGenericMessageToast(context) }, | ||
icon = BpkIcon.Search, | ||
contentDescription = stringResource(R.string.content_description), | ||
) | ||
|
||
BpkFab( | ||
onClick = { showGenericMessageToast(context) }, | ||
icon = BpkIcon.Star, | ||
contentDescription = stringResource(R.string.content_description), | ||
) | ||
|
||
BpkFab( | ||
onClick = { showGenericMessageToast(context) }, | ||
icon = BpkIcon.Flight, | ||
contentDescription = stringResource(R.string.content_description), | ||
) | ||
} | ||
} | ||
|
||
private fun showGenericMessageToast(context: Context) { | ||
BpkToast.makeText(context, context.getString(R.string.generic_message), BpkToast.LENGTH_SHORT).show() | ||
} |
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
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
57 changes: 57 additions & 0 deletions
57
backpack-compose/src/main/kotlin/net/skyscanner/backpack/compose/fab/BpkFab.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,57 @@ | ||
/* | ||
* Backpack for Android - Skyscanner's Design System | ||
* | ||
* Copyright 2018 Skyscanner Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package net.skyscanner.backpack.compose.fab | ||
|
||
import androidx.compose.foundation.interaction.MutableInteractionSource | ||
import androidx.compose.foundation.shape.CircleShape | ||
import androidx.compose.material.FloatingActionButton | ||
import androidx.compose.material.FloatingActionButtonDefaults | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import net.skyscanner.backpack.compose.icon.BpkIcon | ||
import net.skyscanner.backpack.compose.icon.BpkIconSize | ||
import net.skyscanner.backpack.compose.theme.BpkTheme | ||
import net.skyscanner.backpack.compose.tokens.BpkElevation | ||
|
||
@Composable | ||
fun BpkFab( | ||
onClick: () -> Unit, | ||
icon: BpkIcon, | ||
contentDescription: String, | ||
modifier: Modifier = Modifier, | ||
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, | ||
) { | ||
FloatingActionButton( | ||
onClick = onClick, | ||
interactionSource = interactionSource, | ||
modifier = modifier, | ||
shape = CircleShape, | ||
backgroundColor = BpkTheme.colors.coreAccent, | ||
contentColor = BpkTheme.colors.textPrimaryInverse, | ||
elevation = FloatingActionButtonDefaults.elevation(BpkElevation.Xl, BpkElevation.Xl, BpkElevation.Xl, BpkElevation.Xl), | ||
) { | ||
BpkIcon( | ||
icon = icon, | ||
contentDescription = contentDescription, | ||
size = BpkIconSize.Large, | ||
) | ||
} | ||
} |
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,21 @@ | ||
# Floating Action Button | ||
|
||
## Installation | ||
|
||
Backpack Compose is available through [Maven Central](https://search.maven.org/artifact/net.skyscanner.backpack/backpack-compose). Check the main [Readme](https://github.com/skyscanner/backpack-android#installation) for a complete installation guide. | ||
|
||
## Usage | ||
|
||
Example of a `BpkFab`: | ||
|
||
```Kotlin | ||
import net.skyscanner.backpack.compose.fab.BpkFab | ||
import net.skyscanner.backpack.compose.icon.BpkIcon | ||
import net.skyscanner.backpack.compose.tokens.Search | ||
|
||
BpkFab( | ||
onClick = {}, | ||
icon = BpkIcon.Search, | ||
contentDescription = "Content description", | ||
) | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.