Skip to content

Commit

Permalink
Added ability to skip @Preview functions (#401)
Browse files Browse the repository at this point in the history
* Added ability to skip vanilla preview functions

* Upgrade detekt and fix new issues

* Fix more detekt issues

* Fix lint error

* Change name of option config

* Fix new detekt error

* Update name of arg based on feedback
  • Loading branch information
vinaygaba authored Dec 15, 2024
1 parent 9c3d6fc commit 30137ac
Show file tree
Hide file tree
Showing 64 changed files with 371 additions and 165 deletions.
10 changes: 6 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ buildscript {
'composeActivity' : '1.9.0',
'composeConstraintLayout': '1.0.1',
'composeNavigation' : '2.5.1',
'detekt' : '1.7.4',
'detekt' : '1.23.6',
'espresso' : '3.2.0',
'gradle' : '8.1.1',
'gradle' : '8.3.1',
'junit' : '4.13.2',
'junitImplementation' : '1.1.2',
'kotlin' : '1.9.23',
Expand Down Expand Up @@ -100,14 +100,13 @@ buildscript {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}"
classpath "com.karumi:shot:${versions.shot}"
classpath "com.vanniktech:gradle-maven-publish-plugin:${versions.mavenPublish}"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

plugins {
id "io.gitlab.arturbosch.detekt" version "1.7.4"
id "io.gitlab.arturbosch.detekt" version "1.23.6"
id "com.google.devtools.ksp" version "$KSP_VERSION"
id "com.vanniktech.maven.publish" version "$MAVEN_PUBLISH_VERSION"
}
Expand All @@ -119,4 +118,7 @@ allprojects {
mavenCentral()
jcenter()
}
dependencies {
detektPlugins "io.gitlab.arturbosch.detekt:detekt-formatting:${versions.detekt}"
}
}
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Sep 19 07:58:34 PDT 2023
#Wed Dec 11 15:39:25 IST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import com.airbnb.android.showkase.ui.padding4x
fun CreditCardComponent(cardName: String) {
MaterialTheme {
Column(
modifier = Modifier.fillMaxSize(),
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Expand Down Expand Up @@ -112,7 +112,6 @@ fun CreditCardComponentPreview(
CreditCardComponent(text)
}


data class BankHeader(
val name: String,
val age: Int
Expand All @@ -127,7 +126,6 @@ class NewParameterProvider : PreviewParameterProvider<BankHeader> {

override val count: Int
get() = super.count

}

@Preview(group = "Payments")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ fun BasicChipBluePreview() {
)
}


@ShowkaseComposable(name = "Basic Chip Grey Light", group = "Chips")
@ShowkaseComposable(name = "Basic Chip Grey Dark", group = "Chips")
@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.airbnb.android.showkasesample
import androidx.compose.ui.graphics.Color
import com.airbnb.android.showkase.annotation.ShowkaseColor


class WrapperClass {
@ShowkaseColor("Primary", "Light Colors")
val primary = Color(0xFF6200EE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import com.airbnb.android.showkase.annotation.ShowkaseRoot
import com.airbnb.android.showkase.annotation.ShowkaseRootModule

@ShowkaseRoot
class RootModule: ShowkaseRootModule
class RootModule : ShowkaseRootModule
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ fun BottomLabelRow(title: String, subtitle: String, label: String) {
)
)
Surface(
shape = RoundedCornerShape(padding1x/2),
shape = RoundedCornerShape(padding1x / 2),
color = MaterialTheme.colors.primary
) {
Text(
Expand Down Expand Up @@ -194,7 +194,6 @@ fun ProductCardRow(imageUrl: String, title: String, subtitle: String) {
color = MaterialTheme.colors.onSurface
)
)

}
}
}
Expand All @@ -211,7 +210,7 @@ fun BottomLabelRowPreview() {
}

/**
* Use this card when you want to render a product with a hero image at the top.
* Use this card when you want to render a product with a hero image at the top.
*
* Example usage:
*
Expand Down Expand Up @@ -259,6 +258,5 @@ fun TitleSubtitleThumbnailRowWithBackHandlingPreview() {
Column {
TitleSubtitleThumbnailRow()
}
BackHandler(onBack = { })
BackHandler(onBack = {})
}

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ fun VerticalScrollPreview() {
VerticalScrollSample()
}


// This preview was only meant for the Android Studio preview and we want to avoid displaying this
// in the ShowkaseBrowser. In order to do this, I used the ShowkaseComposable annotation along with
// the skip property set to true.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import com.airbnb.android.showkase.ui.padding4x
import com.airbnb.android.submodule.showkasesample.LocalePreview

/**
* This component shows some static text in cursive text style.
*
* This component shows some static text in cursive text style.
*
* Example usage:
*
* ```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ package com.airbnb.android.showkase.annotation
import kotlin.reflect.KClass

/**
* Used by the annotation processor internally to generate metadata files. This won't ever be
* needed by any users of Showkase.
*
* Used by the annotation processor internally to generate metadata files. This won't ever be
* needed by any users of Showkase.
*
* @param packageSimpleName Name of the module that the @Composable function belongs to
* @param packageName Name of the package that the @Composable function was declared in
* @param showkaseElementName Method name of the @Composable function
* @param showkaseName User defined name for the @Composable component to render inside
* the Showkase browser
* @param showkaseGroup User defined grouping key that will be used to group it with
* @param showkaseGroup User defined grouping key that will be used to group it with
* other @Composable functions.
* @param enclosingClass If the @Composable function is defined inside a class, the KClass of the
* wrapper class is stored in the array. Otherwise the array is empty.
* @param showkaseWidthDp The width that your component will be rendered in inside the
* @param showkaseWidthDp The width that your component will be rendered in inside the
* Showkase browser. Use this to restrict the size of your preview inside the Showkase browser.
* @param showkaseHeightDp The height that your component will be rendered in inside the
* Showkase browser. Use this to restrict the size of your preview inside the Showkase browser.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ package com.airbnb.android.showkase.annotation
*
* @ShowkaseColor(name = "Name", group = "Group")
* val redColor = Color.Red
*
*
* @ShowkaseColor("Primary", "Light Colors")
* val primaryColor = Color(0xFF6200EE)
*
* @param name The name that should be used to describe your `Color` fields. If you don't pass
* @param name The name that should be used to describe your `Color` fields. If you don't pass
* any value, the name of the color field is used as the name.
* @param group The grouping key that will be used to group it with other `Color` fields. This is
* useful for better organization and discoverability of your colors. If you don't pass any value
* for the group, the name of the class that wraps this field is used as the group name. If the
* for the group, the name of the class that wraps this field is used as the group name. If the
* field is a top level field, the color is added to a "Default Group".
*/
@MustBeDocumented
Expand Down
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
package com.airbnb.android.showkase.annotation

/**
* Used to annotate @Composable functions that should be displayed inside the
* Used to annotate @Composable functions that should be displayed inside the
* Showkase browser. Here's how you would use it with your @Composable function:
*
*
* @ShowkaseComposable(name = "Name", group = "Group")
* @Composable
* fun MyComposable() {
* .......
* .......
* }
*
*
* <p>
* Note: Make sure that you add this annotation to only those functions that don't accept any
* parameters. If your function accepts a parameters, wrap it inside another function that doesn't
* accept any parameters.
*
* Note: Make sure that you add this annotation to only those functions that don't accept any
* parameters. If your function accepts a parameters, wrap it inside another function that doesn't
* accept any parameters.
*
* For example, here is a @Composable function that requires parameters -
*
* @Composable
* fun MyComposable(name: String) {
* .......
* .......
* }
*
* In order to make this function compatible with Showkase, you could further wrap this function
*
* In order to make this function compatible with Showkase, you could further wrap this function
* inside a method that doesn't accept a parameters in the following way:
*
*
* @ShowkaseComposable(name = "Name", group = "Group")
* @Composable
* fun MyComposablePreview() {
* MyComposable("Name")
* }
*
* This requirement is even needed by the @Preview functions of Jetpack Compose.
*
*
* This requirement is even needed by the @Preview functions of Jetpack Compose.
*
* @param name The name that should be used to describe your `@Composable` function. If you don't
* pass any value, the name of the composable function is used as the name.
* @param group The grouping key that will be used to group it with other `@Composable` functions
* . This is useful for better organization and discoverability of your components. If you don't
* pass any value for the group, the name of the class that wraps this function is used as the
* . This is useful for better organization and discoverability of your components. If you don't
* pass any value for the group, the name of the class that wraps this function is used as the
* group name. If the function is a top level function, the composable is added to a "Default Group".
* @param widthDp The width that your component will be rendered in inside the Showkase browser.
* @param widthDp The width that your component will be rendered in inside the Showkase browser.
* Use this to restrict the size of your preview inside the Showkase browser.
* @param heightDp The height that your component will be rendered in inside the Showkase browser.
* Use this to restrict the size of your preview inside the Showkase browser.
* @param skip Use this boolean when you want to skip this composable from the Showkase browser. A
* @param skip Use this boolean when you want to skip this composable from the Showkase browser. A
* use case of this might be when you want a composable that's annotated with @Preview to show previews
* in Android Studio but don't want to necessary show it in the component browser that's autogenerated
* by Showkase
* @param defaultStyle Used to represent a composable function is the default style variant of a given
* @param defaultStyle Used to represent a composable function is the default style variant of a given
* composable. More information on how Showkase allows you to represent component styles in this section -
* https://github.com/airbnb/Showkase#representing-component-styles-in-showkase
* @param tags Various string values that will be propagated to the Showkase browser to allow additional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ package com.airbnb.android.showkase.annotation

/**
* Used to annotate the [ShowkaseRootModule] implementation class. This is needed to let Showkase
* know more about the module that is going to be the root module for aggregating all the Showkase
* supported UI elements across all the different modules(if you are using a multi-module
* project). If you are only using a single module in your project, add it to that module. You
* know more about the module that is going to be the root module for aggregating all the Showkase
* supported UI elements across all the different modules(if you are using a multi-module
* project). If you are only using a single module in your project, add it to that module. You
* are allowed to have only one @ShowkaseRoot per module.
*
*
* <p>
* Here's an example of how you would use it:
*
* @ShowkaseRoot
* fun MyRootModule: ShowkaseRootModule
*
*
* <p>
* The root module that you declare is also important to start the Showkase browser in order to
* The root module that you declare is also important to start the Showkase browser in order to
* view your composables. You will have to pass in the canonical name of this implementation when
* starting the [ShowkaseBrowserActiity]. Here's is how you would do it:
*
*
* startActivity(ShowkaseBrowserActivity.getIntent(this, MyRootModule::class.java.canonicalName!!))
*/
@MustBeDocumented
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.airbnb.android.showkase.annotation
/**
* Interface used to declare the root class for a module. This is needed to let Showkase
* know more about the module that is going to be the root module for aggregating all the Showkase
* supported UI elements across all the different modules(if you are using a multi-module
* project). If you are only using a single module in your project, add it to that module. You
* supported UI elements across all the different modules(if you are using a multi-module
* project). If you are only using a single module in your project, add it to that module. You
* are allowed to have only one @ShowkaseRoot per module.
*
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.airbnb.android.showkase.annotation

import kotlin.reflect.KClass


/**
* Used to annotate the [ShowkaseScreenshotTest] implementation class. This is needed to let
* Showkase know that it needs to generate screenshot tests for your UI elements that are integrated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ package com.airbnb.android.showkase.annotation
* letterSpacing = (-1.5).sp
* )
*
* @param name The name that should be used to describe your `TextStyle` fields. If you don't
* @param name The name that should be used to describe your `TextStyle` fields. If you don't
* pass any value, the name of the textStyle field is used as the name.
* @param group The grouping key that will be used to group it with other `TextStyle` fields.
* This is useful for better organization and discoverability of your typography. If you don't
* @param group The grouping key that will be used to group it with other `TextStyle` fields.
* This is useful for better organization and discoverability of your typography. If you don't
* pass any value for the group, the name of the class that wraps this field is used as the group
* name. If the field is a top level field, the textStyle is added to a "Default Group".
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@file:Suppress("PackageNaming")
@file:Suppress("PackageName")

package com.vinaygaba.showkase_browser_testing_submodule.two

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@file:Suppress("PackageNaming")
@file:Suppress("PackageName")

package com.vinaygaba.showkase_browser_testing_submodule

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@file:Suppress("PackageNaming")
@file:Suppress("PackageName")

package com.vinaygaba.showkase_browser_testing_submodule

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@file:Suppress("PackageNaming")
@file:Suppress("PackageName")
package com.airbnb.android.showkase_browser_testing

import androidx.compose.ui.graphics.Color
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@file:Suppress("PackageNaming")
@file:Suppress("PackageName")
package com.airbnb.android.showkase_browser_testing

import android.content.res.Configuration
Expand Down Expand Up @@ -69,7 +69,6 @@ fun TestComposable8() {
BasicText(text = "Test Composable9and10")
}


@Preview(
name = "Custom Text Light",
group = "Button",
Expand Down Expand Up @@ -107,7 +106,6 @@ fun PreviewText() {
BasicText(text = "Some text")
}


@EnglishLocalePreview
@Composable
fun PreviewEnglishText() {
Expand All @@ -121,4 +119,4 @@ private fun PrivateTextComposable() {
}

@ShowkaseRoot
class MyRootModule: ShowkaseRootModule
class MyRootModule : ShowkaseRootModule
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@file:Suppress("PackageNaming")
@file:Suppress("PackageName")
package com.airbnb.android.showkase_browser_testing

import androidx.compose.ui.text.TextStyle
Expand Down
Loading

0 comments on commit 30137ac

Please sign in to comment.