refactor: replace hardcode resources files to compose vector

This commit is contained in:
2023-11-11 00:59:30 +08:00
parent 9b85f77892
commit 46c5a23681
7 changed files with 116 additions and 21 deletions

View File

@@ -32,8 +32,6 @@ kotlin {
implementation(compose.foundation)
// TODO: We need to remove this and replace with "material-ripple"
implementation(compose.material)
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
implementation(compose.components.resources)
}
}
val androidMain by getting

View File

@@ -53,9 +53,9 @@ import androidx.compose.ui.unit.dp
import com.highcapable.flexiui.LocalColors
import com.highcapable.flexiui.LocalSizes
import com.highcapable.flexiui.interaction.clickable
import com.highcapable.flexiui.resources.IconRes
import com.highcapable.flexiui.resources.Icons
import com.highcapable.flexiui.resources.icon.CheckMark
import com.highcapable.flexiui.utils.borderOrNot
import org.jetbrains.compose.resources.painterResource
@Immutable
data class CheckBoxColors(
@@ -116,7 +116,7 @@ fun CheckBox(
scaleX = animatedContentLayer,
scaleY = animatedContentLayer
),
painter = painterResource(IconRes.CHECKMARK),
imageVector = Icons.CheckMark,
tint = colors.contentColor
)
}

View File

@@ -23,7 +23,4 @@
package com.highcapable.flexiui.resources
object IconRes {
const val CHECKMARK = "ic-checkmark.xml"
}
object Icons

View File

@@ -0,0 +1,51 @@
/*
* Flexi UI - A flexible and useful UI component library.
* Copyright (C) 2019-2023 HighCapable
* https://github.com/BetterAndroid/FlexiUI
*
* Apache License Version 2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file is created by fankes on 2023/11/11.
*/
@file:Suppress("unused")
package com.highcapable.flexiui.resources.builder
import androidx.compose.ui.graphics.BlendMode
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.DefaultGroupName
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.Dp
internal fun buildImageVector(
name: String = DefaultGroupName,
defaultWidth: Dp,
defaultHeight: Dp,
viewportWidth: Float,
viewportHeight: Float,
tintColor: Color = Color.Unspecified,
tintBlendMode: BlendMode = BlendMode.SrcIn,
autoMirror: Boolean = false,
builder: ImageVector.Builder.() -> Unit
) = ImageVector.Builder(
name = name,
defaultWidth = defaultWidth,
defaultHeight = defaultHeight,
viewportWidth = viewportWidth,
viewportHeight = viewportHeight,
tintColor = tintColor,
tintBlendMode = tintBlendMode,
autoMirror = autoMirror
).apply(builder).build()

View File

@@ -0,0 +1,59 @@
/*
* Flexi UI - A flexible and useful UI component library.
* Copyright (C) 2019-2023 HighCapable
* https://github.com/BetterAndroid/FlexiUI
*
* Apache License Version 2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file is created by fankes on 2023/11/11.
*/
@file:Suppress("unused")
package com.highcapable.flexiui.resources.icon
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.PathFillType
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.graphics.StrokeJoin
import androidx.compose.ui.graphics.vector.path
import androidx.compose.ui.unit.dp
import com.highcapable.flexiui.resources.Icons
import com.highcapable.flexiui.resources.builder.buildImageVector
val Icons.CheckMark by lazy {
buildImageVector(
name = "checkmark",
defaultWidth = 32.dp,
defaultHeight = 32.dp,
viewportWidth = 48f,
viewportHeight = 48f
) {
path(
fillAlpha = 1.0f,
stroke = SolidColor(Color.White),
strokeAlpha = 1.0f,
strokeLineWidth = 7f,
strokeLineCap = StrokeCap.Round,
strokeLineJoin = StrokeJoin.Round,
strokeLineMiter = 1.0f,
pathFillType = PathFillType.NonZero
) {
moveTo(43f, 11f)
lineTo(16.875f, 37f)
lineTo(5f, 25.1818f)
}
}
}

View File

@@ -1,12 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:pathData="M43,11L16.875,37L5,25.182"
android:strokeWidth="7"
android:strokeColor="#FFFFFFFF"
android:strokeLineCap="round"
android:strokeLineJoin="round" />
</vector>

View File

@@ -64,6 +64,8 @@ android {
compileSdk = property.project.android.compileSdk
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
sourceSets["main"].res.srcDirs("src/androidMain/res")
sourceSets["main"].resources.srcDirs("src/commonMain/resources")
defaultConfig {
minSdk = property.project.android.minSdk