Skip to content

Commit 018e1fb

Browse files
author
Ankit Kumar
committed
circular icons added
1 parent 3e137aa commit 018e1fb

File tree

13 files changed

+143
-58
lines changed

13 files changed

+143
-58
lines changed

.idea/compiler.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ android {
4848
}
4949

5050
dependencies {
51-
51+
implementation 'com.github.lazycoder-21:ComposeFontAwesome:v1.0.0'
52+
implementation "com.github.lostankit7:AndroidCustomViews:1.2"
5253
implementation 'androidx.core:core-ktx:1.7.0'
5354
implementation 'androidx.appcompat:appcompat:1.4.1'
5455
implementation 'com.google.android.material:material:1.6.0'
@@ -57,7 +58,7 @@ dependencies {
5758
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
5859
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1'
5960
implementation 'androidx.activity:activity-compose:1.4.0'
60-
implementation project(path: ':font_awesome')
61+
6162
testImplementation 'junit:junit:4.+'
6263
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
6364
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

app/src/main/java/lazycoder21/droid/fontawesome/MainActivity.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ class MainActivity : ComponentActivity() {
1919
setContent {
2020
FontAwesomeComposeTheme {
2121
Surface(color = MaterialTheme.colors.background) {
22-
FontAwesomeIcon(
23-
faIconType = FaIcons.AddressBook
24-
)
22+
2523
}
2624
}
2725
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package lazycoder21.droid.compose
2+
3+
import androidx.compose.foundation.background
4+
import androidx.compose.foundation.border
5+
import androidx.compose.foundation.clickable
6+
import androidx.compose.foundation.layout.padding
7+
import androidx.compose.foundation.layout.wrapContentWidth
8+
import androidx.compose.foundation.shape.CircleShape
9+
import androidx.compose.foundation.text.BasicText
10+
import androidx.compose.runtime.Composable
11+
import androidx.compose.ui.Modifier
12+
import androidx.compose.ui.draw.clip
13+
import androidx.compose.ui.graphics.Color
14+
import androidx.compose.ui.platform.LocalConfiguration
15+
import androidx.compose.ui.semantics.Role
16+
import androidx.compose.ui.text.TextStyle
17+
import androidx.compose.ui.unit.Dp
18+
import androidx.compose.ui.unit.dp
19+
20+
@Composable
21+
fun CircularFontAwesomeIcon(
22+
modifier: Modifier = Modifier,
23+
icon: FaIcon,
24+
size: Dp = 22.dp,
25+
tint: Color = Color.Unspecified,
26+
textStyle: TextStyle = TextStyle.Default,
27+
padding: Dp = 5.dp,
28+
strokeWidth: Dp = 1.dp,
29+
strokeColor: Color = Color(0xFFA39696),
30+
backgroundColor: Color = Color.Transparent,
31+
enabled: Boolean = true,
32+
onClickLabel: String? = null,
33+
role: Role? = null,
34+
onClick: (() -> Unit)? = null,
35+
) {
36+
37+
val scaleFactor = LocalConfiguration.current.fontScale
38+
val fontSize = size.scaleIndependentFontSize
39+
40+
val faTextStyle = textStyle.copy(
41+
color = tint,
42+
fontFamily = icon.fontFamily,
43+
fontSize = fontSize
44+
)
45+
46+
BasicText(
47+
text = icon.icon,
48+
modifier = modifier
49+
.wrapContentWidth()
50+
.clip(CircleShape)
51+
.border(
52+
width = strokeWidth,
53+
color = strokeColor,
54+
shape = CircleShape
55+
)
56+
.background(color = backgroundColor)
57+
.clickable(enabled, onClickLabel, role) { onClick?.invoke() }
58+
.padding(padding),
59+
style = faTextStyle,
60+
)
61+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package lazycoder21.droid.compose
2+
3+
sealed class FaIcon(val src: Int) {
4+
data class Solid(private val icon: Int) : FaIcon(icon)
5+
data class Regular(private val icon: Int) : FaIcon(icon)
6+
data class Brand(private val icon: Int) : FaIcon(icon)
7+
}

font_awesome/src/main/java/lazycoder21/droid/compose/FaIconType.kt

Lines changed: 0 additions & 7 deletions
This file was deleted.

font_awesome/src/main/java/lazycoder21/droid/compose/FaIcons.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package lazycoder21.droid.compose
22

3-
import lazycoder21.droid.compose.FaIconType.*
3+
import lazycoder21.droid.compose.FaIcon.*
44

55
object FaIcons {
66

0 commit comments

Comments
 (0)