Skip to content

Commit

Permalink
Merge pull request #26 from LinX64/develop
Browse files Browse the repository at this point in the history
Release v1.1.2
  • Loading branch information
LinX64 authored Apr 5, 2024
2 parents 0649c4f + ef0d26f commit 60b24e6
Show file tree
Hide file tree
Showing 15 changed files with 171 additions and 70 deletions.
58 changes: 34 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,44 @@

![master CI](https://github.com/LinX64/Reusable/actions/workflows/publish.yaml/badge.svg)
![develop CI](https://github.com/LinX64/Reusable/actions/workflows/ci.yaml/badge.svg)
[![Maven Central](https://img.shields.io/maven-central/v/io.github.linx64/reusablecomponents.svg)](https://central.sonatype.com/artifact/io.github.linx64/reusablecomponents/overview)

This library is a treasure trove of reusable components tailored for Jetpack Compose, designed to simplify the creation of complex interfaces. It's your go-to toolkit for crafting visually stunning UIs effortlessly. So, let's cut to the chase and unleash the magic! 😃
This library is a treasure trove of reusable components tailored for Jetpack Compose, designed to
simplify the creation of complex interfaces. It's your go-to toolkit for crafting visually stunning
UIs effortlessly. So, let's cut to the chase and unleash the magic! 😃

## Installation

To use the library, add the following line of code to your `build.gradle` file if you are using
Kotlin DSL:

```Kotlin
implementation("io.github.linx64:reusablecomponents:<version>")
```

Or this for Groovy:

```Groovy
implementation 'io.github.linx64:reusablecomponents:<version>'
```

Version Catalog:

```Kotlin-dsl
reusablecomponents_version = <version>
reusableComponents = { group = "io.github.linx64", name = "reusablecomponents", version.ref = "reuseableComponents" }
```

## Components

Currently, the library contains the following components:

- Containers
- Buttons
- Columns
- TODO: Preview
- TODO: Spacers
- [Containers](https://github.com/LinX64/Reusable/tree/develop/reusablecomponents/src/main/kotlin/com/client/reusablecomponents/containers)
- [Buttons](https://github.com/LinX64/Reusable/tree/develop/reusablecomponents/src/main/kotlin/com/client/reusablecomponents/buttons)
- [Columns](https://github.com/LinX64/Reusable/blob/develop/reusablecomponents/src/main/kotlin/com/client/reusablecomponents/containers/CenteredColumn.kt)
- [Preview](https://github.com/LinX64/Reusable/tree/develop/reusablecomponents/src/main/kotlin/com/client/reusablecomponents/previews)
- [Spacers](https://github.com/LinX64/Reusable/tree/develop/reusablecomponents/src/main/kotlin/com/client/reusablecomponents/spacers)
- Other necessary components will be added soon.

## Usage

Expand All @@ -23,32 +49,16 @@ let's say you want to have a Scrollable screen with a few Buttons:
```kotlin
ScrollableScreen {
PrimaryButton(text = R.string.app_name, onClick = {})

Spacer(modifier = Modifier.height(16.dp))

PrimaryButton(text = R.string.app_name, onClick = {})

Spacer(modifier = Modifier.height(16.dp))

PrimaryButton(text = R.string.app_name, onClick = {})

Spacer(modifier = Modifier.height(16.dp))

PrimaryButton(text = R.string.app_name, onClick = {})
}
```

And that's it! You have a scrollable screen with a few buttons. You can customize the container by
passing your own `modifier` to it. The same goes for the buttons, you can pass your own `modifier`
to it.

This is how it will look like:

<img src="https://i.imgur.com/9AfnPTk.png" width="250" />

## Installation

...I will add this section once it is published to Maven Central.
**Important note:** To use the Preview components, you'll nned to add your own theme first, then use the
components to create your UI.

## License

Expand Down
6 changes: 4 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ android {
}

dependencies {
implementation(projects.reusablecomponents)

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)
Expand All @@ -77,6 +75,10 @@ dependencies {
implementation(libs.androidx.compose.material3)
implementation(libs.androidx.compose.material.iconsExtended)

// The library
//implementation(libs.reusableComponents)
implementation(project(":reusablecomponents"))

detektPlugins(libs.detekt.formatting)

debugImplementation(libs.androidx.ui.test.manifest)
Expand Down
16 changes: 11 additions & 5 deletions app/src/main/java/com/client/reusable/ui/screens/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import androidx.compose.foundation.layout.height
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.client.reusable.R
import com.client.reusable.ui.theme.ReusableTheme
import com.client.reusablecomponents.buttons.PrimaryButton
import com.client.reusablecomponents.containers.CenteredColumn
import com.client.reusablecomponents.preview.AppScreenComponent
import com.client.reusablecomponents.previews.AppScreenComponent
import com.client.reusablecomponents.previews.MultiThemePreviews
import com.client.reusablecomponents.spacers.FillHeightSpacer

@Composable
fun HomeScreen() {
Expand All @@ -21,15 +23,19 @@ fun HomeScreen() {

Spacer(modifier = Modifier.height(16.dp))

FillHeightSpacer()

PrimaryButton(text = R.string.app_name, onClick = {})
}
}
}

@Preview(showBackground = true)
@MultiThemePreviews
@Composable
private fun HomePreview() {
AppScreenComponent {
HomeScreen()
ReusableTheme {
AppScreenComponent {
HomeScreen()
}
}
}
4 changes: 2 additions & 2 deletions app/src/main/java/com/client/reusable/ui/screens/MyApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.client.reusablecomponents.previews.DevicePreviews

@OptIn(ExperimentalMaterial3Api::class)
@Composable
Expand All @@ -30,7 +30,7 @@ internal fun MyApp() {
}
}

@Preview
@DevicePreviews
@Composable
private fun MyAppPreview() {
MyApp()
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ composeBom = "2024.04.00"
material-3 = "1.2.1"
detekt = "1.23.6"
mavenPublish = "0.28.0"
reuseableComponents = "1.1.1"

[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
Expand All @@ -22,6 +23,7 @@ androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-man
androidx-compose-material-iconsExtended = { group = "androidx.compose.material", name = "material-icons-extended" }
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3", version.ref = "material-3" }
detekt-formatting = { group = "io.gitlab.arturbosch.detekt", name = "detekt-formatting", version.ref = "detekt" }
reusableComponents = { group = "io.github.linx64", name = "reusablecomponents", version.ref = "reuseableComponents" }

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.client.reusablecomponents.containers.CenteredColumn
import com.client.reusablecomponents.previews.MultiThemePreviews
import io.github.linx64.reusablecomponents.R

@Composable
Expand All @@ -34,8 +34,8 @@ fun PrimaryButton(
}
}

@MultiThemePreviews
@Composable
@Preview(showBackground = true)
private fun PrimaryButtonPreview() {
CenteredColumn {
PrimaryButton(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.client.reusablecomponents.containers.CenteredColumn
import io.github.linx64.reusablecomponents.R

@Composable
fun SecondaryButton(
Expand Down Expand Up @@ -45,14 +42,3 @@ fun SecondaryButton(
)
}
}

@Composable
@Preview(showBackground = true)
private fun SecondaryButtonPreview() {
CenteredColumn {
SecondaryButton(
text = R.string.cancel,
onClick = {}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.client.reusablecomponents.preview.AppScreenComponent
import com.client.reusablecomponents.previews.AppScreenComponent

@Composable
fun CenteredColumn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.client.reusablecomponents.preview.AppScreenComponent
import com.client.reusablecomponents.previews.AppScreenComponent

@Composable
fun Screen(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.client.reusablecomponents.preview.AppScreenComponent
import com.client.reusablecomponents.previews.AppScreenComponent

@Composable
fun ScrollableScreen(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
package com.client.reusablecomponents.preview
package com.client.reusablecomponents.previews

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.client.reusablecomponents.buttons.PrimaryButton
import io.github.linx64.reusablecomponents.R

/**
* A component that wraps the content in a [Surface] and applies padding.
* The content is placed in a [Column].
* IMPORTANT: Remember to add your own Theme while using this component.
*/
@Composable
fun AppComponent(
modifier: Modifier = Modifier,
content: @Composable () -> Unit,
) {
Column(
modifier = Modifier
.padding(16.dp)
.then(modifier),
) {
content()
Surface {
Column(
modifier = Modifier
.padding(16.dp)
.then(modifier),
) {
content()
}
}
}

@Preview(showBackground = true)
@MultiThemePreviews
@Composable
private fun AppPreview() {
AppComponent {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
package com.client.reusablecomponents.preview
package com.client.reusablecomponents.previews

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.client.reusablecomponents.buttons.PrimaryButton
import com.client.reusablecomponents.containers.CenteredColumn
import io.github.linx64.reusablecomponents.R

/**
* A component that wraps the content in a [Surface] and centers the content.
* The content is placed in a [Column].
* IMPORTANT: Remember to add your own Theme while using this component.
*/
@Composable
fun AppScreenComponent(
modifier: Modifier = Modifier,
content: @Composable () -> Unit,
) {
Column(
modifier = Modifier
.fillMaxSize()
.then(modifier),
Surface(
modifier = Modifier.fillMaxSize(),
) {
CenteredColumn {
content()
Column(
modifier = Modifier
.fillMaxSize()
.then(modifier),
) {
CenteredColumn {
content()
}
}
}
}

@Preview(showBackground = true)
@MultiThemePreviews
@Composable
private fun AppScreenComponentPreview() {
AppScreenComponent {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.client.reusablecomponents.previews

import androidx.compose.ui.tooling.preview.Preview

/**
* Multi preview annotation that represents various device sizes.
* Add this annotation to a composable to render various devices.
*/

@Preview(
name = "phone",
device = "spec:shape=Normal,width=360,height=640,unit=dp,dpi=480"
)
@Preview(
name = "landscape",
device = "spec:shape=Normal,width=640,height=360,unit=dp,dpi=480"
)
@Preview(
name = "foldable",
device = "spec:shape=Normal,width=673,height=841,unit=dp,dpi=480"
)
@Preview(
name = "tablet",
device = "spec:shape=Normal,width=1280,height=800,unit=dp,dpi=480"
)
annotation class DevicePreviews
Loading

0 comments on commit 60b24e6

Please sign in to comment.