Skip to content

Commit

Permalink
UI: Create Text component
Browse files Browse the repository at this point in the history
  • Loading branch information
ksharma-xyz committed Sep 28, 2024
1 parent b75af21 commit 4bd3858
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ApplicationConventionPlugin : Plugin<Project> {
val minSdkVersion = libs.findVersion("minSdk").get().toString().toInt()
val targetSdkVersion = libs.findVersion("targetSdk").get().toString().toInt()
val compileSdkVersion = libs.findVersion("compileSdk").get().toString().toInt()
//val composeCompilerVersion = libs.findPlugin("composeCompiler").get().toString()
val kotlinVersion = libs.findVersion("kotlin").get().toString()

with(pluginManager) {
apply("com.android.application")
Expand Down Expand Up @@ -57,9 +57,10 @@ class ApplicationConventionPlugin : Plugin<Project> {
buildConfig = true
}

/* composeOptions {
kotlinCompilerExtensionVersion = composeCompilerVersion
}*/
composeOptions {
// Kotlin and Compose compiler version is same after K2 is released.
kotlinCompilerExtensionVersion = kotlinVersion
}

packaging {
resources {
Expand Down
7 changes: 4 additions & 3 deletions core/design-system/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ android {

dependencies {
api(platform(libs.compose.bom))
api(libs.compose.foundation)
api(libs.compose.ui)
api(libs.compose.ui.graphics)
implementation(libs.compose.foundation)
implementation(libs.compose.ui)
implementation(libs.compose.ui.graphics)
api(libs.compose.ui.tooling.preview)
implementation(libs.compose.material3) // adding for reading code inspiration.

androidTestImplementation(platform(libs.compose.bom))
debugApi(libs.compose.ui.tooling)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package xyz.ksharma.krail.design.system.components

import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.PreviewLightDark
import xyz.ksharma.krail.design.system.theme.KrailTheme

val LocalTextStyle = compositionLocalOf { TextStyle.Default }
val LocalTextColor = compositionLocalOf { Color.Unspecified }

@Composable
fun Text(
text: String,
modifier: Modifier = Modifier,
style: TextStyle = LocalTextStyle.current,
textAlign: TextAlign = TextAlign.Start,
maxLines: Int = Int.MAX_VALUE,
) {
CompositionLocalProvider(
LocalTextColor provides KrailTheme.colors.onBackground,
LocalTextStyle provides KrailTheme.typography.body,
) {
BasicText(
text = text,
style = style.merge(
color = LocalTextColor.current,
textAlign = textAlign,

),
maxLines = maxLines,
modifier = modifier,
)
}
}

@PreviewLightDark
@Composable
private fun TextPreview() {
KrailTheme {
Text(text = "Hello World!")
Text(text = "Hello World!", style = KrailTheme.typography.displayLarge)
Text(text = "Hello World!", style = KrailTheme.typography.displayMedium)
Text(text = "Hello World!", style = KrailTheme.typography.displaySmall)
}
}
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ compose-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
compose-navigation = { group = "androidx.navigation", name = "navigation-compose", version.ref = "compose-navigation" }
compose-material3 = { group = "androidx.compose.material3", name = "material3", version = "1.3.0" }

#Hilt
hilt-android = { group = "com.google.dagger", name = "hilt-android", version.ref = "hilt" }
Expand Down

0 comments on commit 4bd3858

Please sign in to comment.