-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Library migration to compose multiplatform
- Add support for iOS platform - Implement expect / actual ScreenWidth.kt for getting screen width. - Replace all occurrences of TextPaint to draw text with drawText accepting TextMeasurer - Utils text measurer measurement to calculate text bounds - Move all classes commonMain modules - Update build files to add support for multiplatform
- Loading branch information
1 parent
bb8faa7
commit 7277296
Showing
63 changed files
with
599 additions
and
425 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,16 @@ | ||
// Top-level build file where you can add configuration options common to all sub-projects/modules. | ||
buildscript { | ||
dependencies { | ||
classpath("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.23.0") | ||
classpath("org.jlleitschuh.gradle:ktlint-gradle:11.3.2") | ||
} | ||
} | ||
|
||
plugins { | ||
id("com.android.application").version("8.2.0") apply false | ||
id("com.android.library").version("8.2.0") apply false | ||
id("org.jetbrains.kotlin.android").version("1.9.21") apply false | ||
kotlin("multiplatform").version("1.9.21") apply false | ||
id("org.jetbrains.compose").version("1.6.11") apply false | ||
id("org.jetbrains.dokka").version("1.9.0") | ||
} |
This file was deleted.
Oops, something went wrong.
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,87 @@ | ||
import com.vanniktech.maven.publish.SonatypeHost | ||
|
||
plugins { | ||
kotlin("multiplatform") | ||
id("com.android.library") | ||
id("org.jetbrains.compose") | ||
id("org.jetbrains.dokka") | ||
id("com.vanniktech.maven.publish") version "0.25.3" | ||
} | ||
|
||
apply("../quality/static-check.gradle") | ||
|
||
kotlin { | ||
androidTarget() { | ||
publishLibraryVariants("release") | ||
} | ||
|
||
listOf( | ||
iosX64(), | ||
iosArm64(), | ||
iosSimulatorArm64() | ||
).forEach { iosTarget -> | ||
iosTarget.binaries.framework { | ||
baseName = "charty" | ||
isStatic = true | ||
} | ||
} | ||
|
||
sourceSets { | ||
val commonMain by getting { | ||
dependencies { | ||
implementation(compose.runtime) | ||
implementation(compose.foundation) | ||
implementation(compose.material3) | ||
implementation(compose.materialIconsExtended) | ||
implementation(compose.ui) | ||
implementation("org.jetbrains.compose.ui:ui-util:1.6.11") | ||
} | ||
} | ||
} | ||
} | ||
|
||
android { | ||
namespace = "com.himanshoe.charty" | ||
compileSdk = 34 | ||
|
||
defaultConfig { | ||
minSdk = 24 | ||
targetSdk = 34 | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles("consumer-rules.pro") | ||
} | ||
|
||
buildTypes { | ||
release { | ||
isMinifyEnabled = false | ||
proguardFiles( | ||
getDefaultProguardFile("proguard-android-optimize.txt"), | ||
"proguard-rules.pro" | ||
) | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_17 | ||
targetCompatibility = JavaVersion.VERSION_17 | ||
} | ||
kotlin { | ||
jvmToolchain(17) | ||
} | ||
} | ||
|
||
mavenPublishing { | ||
publishToMavenCentral(SonatypeHost.S01) | ||
signAllPublications() | ||
} | ||
|
||
dependencies { | ||
debugImplementation("androidx.compose.ui:ui-tooling") | ||
dokkaPlugin("org.jetbrains.dokka:android-documentation-plugin:1.8.20") | ||
lintChecks("com.slack.lint.compose:compose-lint-checks:1.2.0") | ||
|
||
testImplementation("junit:junit:4.13.2") | ||
androidTestImplementation("androidx.test.ext:junit:1.1.5") | ||
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") | ||
|
||
} |
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
135 changes: 135 additions & 0 deletions
135
charty/src/androidMain/kotlin/com/himanshoe/charty/util/Previews.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,135 @@ | ||
package com.himanshoe.charty.util | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.layout.wrapContentSize | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.scale | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import com.himanshoe.charty.circle.CircleChart | ||
import com.himanshoe.charty.circle.model.CircleData | ||
import com.himanshoe.charty.common.toChartDataCollection | ||
import com.himanshoe.charty.gauge.GaugeChart | ||
import com.himanshoe.charty.line.CurveLineChart | ||
import com.himanshoe.charty.line.model.LineData | ||
import com.himanshoe.charty.pie.PieChart | ||
import com.himanshoe.charty.pie.model.PieData | ||
import com.himanshoe.charty.point.PointChart | ||
import com.himanshoe.charty.point.model.PointData | ||
|
||
/* | ||
Collection of all chart previews. This previews are here because KMM does not have support | ||
for previews in the common module. | ||
*/ | ||
@Preview | ||
@Composable | ||
internal fun CircleChartScreen() { | ||
val circleData = listOf( | ||
CircleData(10F, 235F, color = Color(0xFFfafa6e)), | ||
CircleData(10F, 135F, color = Color(0xFFc4ec74)), | ||
CircleData(10F, 315F, color = Color(0xFF92dc7e)), | ||
CircleData(20F, 50F, color = Color(0xFF64c987)), | ||
CircleData(30F, 315F, color = Color(0xFF39b48e)) | ||
) | ||
CircleChart( | ||
modifier = Modifier | ||
.scale(1f) | ||
.size(400.dp) | ||
.padding(20.dp), | ||
dataCollection = circleData.toChartDataCollection(), | ||
) | ||
} | ||
|
||
@Preview | ||
@Composable | ||
internal fun GaugeChartPreview() { | ||
val percentValue = 100 | ||
GaugeChart(percentValue = percentValue) | ||
} | ||
|
||
@Preview | ||
@Composable | ||
internal fun LineChartPreview(modifier: Modifier = Modifier) { | ||
Column(modifier) { | ||
CurveLineChart( | ||
dataCollection = generateMockLineData().toChartDataCollection(), | ||
modifier = Modifier | ||
.size(450.dp), | ||
) | ||
} | ||
} | ||
|
||
internal fun generateMockLineData(): List<LineData> { | ||
return listOf( | ||
LineData(0F, "Jan"), | ||
LineData(10F, "Feb"), | ||
LineData(05F, "Mar"), | ||
LineData(50F, "Apr"), | ||
LineData(03F, "June"), | ||
LineData(9F, "July"), | ||
LineData(40F, "Aug"), | ||
LineData(60F, "Sept"), | ||
LineData(33F, "Oct"), | ||
LineData(11F, "Nov"), | ||
LineData(27F, "Dec"), | ||
LineData(10F, "Jan"), | ||
LineData(13F, "Oct"), | ||
LineData(-10F, "Nov"), | ||
LineData(0F, "Dec"), | ||
LineData(10F, "Jan"), | ||
) | ||
} | ||
|
||
@Preview | ||
@Composable | ||
internal fun PieChartPreview() { | ||
val data = listOf( | ||
PieData(30f, "Category A", Color.Blue), | ||
PieData(20f, "Category B", Color.Red), | ||
PieData(10f, "Category C", Color.Green), | ||
PieData(10f, "Category C", Color.Black), | ||
) | ||
PieChart( | ||
dataCollection = data.toChartDataCollection(), | ||
modifier = Modifier.wrapContentSize() | ||
) | ||
} | ||
|
||
@Preview | ||
@Composable | ||
internal fun PointChartPreview(modifier: Modifier = Modifier) { | ||
Column(modifier) { | ||
PointChart( | ||
dataCollection = generateMockPointData().toChartDataCollection(), | ||
modifier = Modifier | ||
.size(450.dp), | ||
contentColor = Color.Red, | ||
) | ||
} | ||
} | ||
|
||
internal fun generateMockPointData(): List<PointData> { | ||
return listOf( | ||
PointData(-10F, "Jan"), | ||
PointData(10F, "Feb"), | ||
PointData(05F, "Mar"), | ||
PointData(50F, "Apr"), | ||
PointData(03F, "June"), | ||
PointData(9F, "July"), | ||
PointData(40F, "Aug"), | ||
PointData(60F, "Sept"), | ||
PointData(33F, "Oct"), | ||
PointData(11F, "Nov"), | ||
PointData(27F, "Dec"), | ||
PointData(10F, "Jan"), | ||
PointData(73F, "Oct"), | ||
PointData(-20F, "Nov"), | ||
PointData(0F, "Dec"), | ||
PointData(10F, "Jan"), | ||
) | ||
} | ||
|
12 changes: 12 additions & 0 deletions
12
charty/src/androidMain/kotlin/com/himanshoe/charty/util/ScreenWidth.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,12 @@ | ||
package com.himanshoe.charty.util | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.platform.LocalConfiguration | ||
import androidx.compose.ui.platform.LocalDensity | ||
import androidx.compose.ui.unit.dp | ||
|
||
@Composable | ||
actual fun getScreenWidth(): Float { | ||
val wDp = LocalConfiguration.current.screenWidthDp.dp | ||
return with(LocalDensity.current) { wDp.roundToPx().toFloat() } | ||
} |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.