Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging to master #34

Merged
merged 4 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ implementation 'io.github.linx64:reusablecomponents:<version>'
Version Catalog:

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

## Components
Expand Down Expand Up @@ -68,9 +68,9 @@ ScrollableScreen {
}
```

And that's it! You have a scrollable screen with a few buttons
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 the buttons.
You can customize the container by passing your `modifier` to it. The same goes for the buttons.

**Important note:** To use the Preview components, you'll need to add your theme first, then use the
components to create your UI.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.client.reusablecomponents.containers.ScrollableScreen
import com.client.reusablecomponents.previews.AppScreenComponent
import com.client.reusablecomponents.previews.MultiThemePreviews
import com.client.reusablecomponents.spacers.FillHeightSpacer
import com.client.reusablecomponents.spacers.FillHorizontalHeight
import com.client.reusablecomponents.spacers.HorizontalSpacer

@Composable
fun HomeScreen() {
Expand All @@ -26,15 +26,15 @@ fun HomeScreen() {

FillHeightSpacer()

FillHorizontalHeight()
HorizontalSpacer()

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

FillHorizontalHeight()
HorizontalSpacer()

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

FillHorizontalHeight()
HorizontalSpacer()

SecondaryButton(text = R.string.app_name, onClick = {})
}
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ org.gradle.caching=true
org.gradle.configuration-cache.problems=warn
org.gradle.configureondemand=false
org.gradle.parallel=true
org.gradle.configuration-cache=true

GROUP=io.github.linx64
VERSION_NAME=1.0
Expand All @@ -29,4 +30,4 @@ POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/LinX64/Reusable.git

POM_DEVELOPER_ID=LinX64
POM_DEVELOPER_NAME=Mohsen
POM_DEVELOPER_URL=https://github.com/LinX64/
POM_DEVELOPER_URL=https://github.com/LinX64/
2 changes: 1 addition & 1 deletion reusablecomponents/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ dependencies {
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)

implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.ui)
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.compose.material3)
implementation(libs.androidx.compose.material.iconsExtended)

debugImplementation(libs.androidx.ui.test.manifest)
debugImplementation(libs.androidx.ui.tooling)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fun CenteredColumn(

@Preview(showBackground = true)
@Composable
private fun CenterColumnPreview() {
private fun CenteredColumnPreview() {
AppScreenComponent {
CenteredColumn {
Text(text = "Text in center")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.client.reusablecomponents.dialogs

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Error
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import io.github.linx64.reusablecomponents.R

@Composable
fun BaseErrorDialog(
modifier: Modifier = Modifier,
title: String,
message: String,
icon: ImageVector = Icons.Default.Error,
iconTint: Color = MaterialTheme.colorScheme.error,
shouldShowDismiss: Boolean = false
) {
val shouldShowDialog = remember { mutableStateOf(true) }
if (shouldShowDialog.value) {
AlertDialog(
modifier = modifier,
icon = { Icon(icon, iconTint) },
title = { Text(text = title) },
text = { Text(text = message) },
onDismissRequest = { shouldShowDialog.value = false },
confirmButton = { ConfirmButton(shouldShowDialog) },
dismissButton = { DismissButton(shouldShowDismiss, shouldShowDialog) }
)
}
}

@Composable
private fun Icon(
icon: ImageVector,
iconTint: Color
) {
Icon(
modifier = Modifier.size(48.dp),
imageVector = icon,
contentDescription = null,
tint = iconTint
)
}

@Composable
private fun ConfirmButton(shouldShowDialog: MutableState<Boolean>) {
TextButton(
onClick = {
shouldShowDialog.value = false
}
) {
Text(text = stringResource(R.string.ok))
}
}

@Composable
private fun DismissButton(
shouldShowDismiss: Boolean,
shouldShowDialog: MutableState<Boolean>
) {
if (shouldShowDismiss) {
TextButton(
onClick = {
shouldShowDialog.value = false
}
) {
Text(text = "Dismiss")
}
}
}

@Preview(showBackground = true)
@Composable
private fun BaseErrorDialogPreview() {
Column(
modifier = Modifier.fillMaxSize()
) {
BaseErrorDialog(
title = "Error",
message = "Please enter valid email and password!"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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.
* A component that wraps the content in a [Surface] and then centers it
* The content is placed in a [Column].
* IMPORTANT: Remember to add your own Theme while using this component.
*/
Expand All @@ -20,16 +20,12 @@ fun AppScreenComponent(
content: @Composable () -> Unit,
) {
Surface(
modifier = Modifier.fillMaxSize(),
modifier = Modifier
.fillMaxSize()
.then(modifier),
) {
Column(
modifier = Modifier
.fillMaxSize()
.then(modifier),
) {
CenteredColumn {
content()
}
CenteredColumn {
content()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

@Composable
fun FillHorizontalHeight() = Spacer(modifier = Modifier.height(16.dp))
fun HorizontalSpacer() = Spacer(modifier = Modifier.height(16.dp))

/**
* Spacers for Column
Expand Down
2 changes: 1 addition & 1 deletion reusablecomponents/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="ok">Ok</string>
<string name="ok">OK</string>
<string name="dismiss">Dismiss</string>
<string name="cancel">Cancel</string>
</resources>