Skip to content

Commit

Permalink
Move sample app to :sample
Browse files Browse the repository at this point in the history
  • Loading branch information
kubode committed Nov 12, 2023
1 parent e267db2 commit e2f4ca5
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 132 deletions.
3 changes: 1 addition & 2 deletions sample/androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ android {
}

dependencies {
implementation(projects.composeBoxshadow)
implementation(projects.composeDropshadow)
implementation(projects.sample.shared)
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.compose.foundation)
implementation(libs.androidx.compose.ui.tooling)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,141 +3,13 @@ package io.github.kubode.compose.shadow.android
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.animateFloat
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.rememberInfiniteTransition
import androidx.compose.animation.core.tween
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.gestures.scrollable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.DpOffset
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import io.github.kubode.compose.boxshadow.boxShadow
import io.github.kubode.compose.dropshadow.DropShadow
import io.github.kubode.compose.shadow.sample.shared.Sample

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Column(
modifier = Modifier
.fillMaxSize()
.background(Color.White)
.padding(16.dp)
.scrollable(
state = rememberScrollState(),
orientation = Orientation.Vertical
),
verticalArrangement = Arrangement.spacedBy(32.dp),
) {
DropShadow(
color = Color.Black.copy(alpha = 0.5f),
offset = DpOffset(2.dp, 2.dp),
radius = 2.dp,
modifier = Modifier
.border(1.dp, Color.Black)
.padding(16.dp),
) {
BasicText(
text = buildAnnotatedString {
withStyle(SpanStyle(color = Color(0xFF37BF6E))) {
append("Compose")
}
append(" ")
withStyle(SpanStyle(color = Color(0xFF041619))) {
append("Shadow")
}
append(" ")
withStyle(SpanStyle(color = Color(0xFF3870B2))) {
append("Alternative")
}
},
style = TextStyle.Default.copy(fontSize = 24.sp)
)
}
DropShadow(
color = DroidColor.copy(alpha = 0.5f),
offset = DpOffset(4.dp, 4.dp),
radius = 8.dp,
) {
Image(
painter = painterResource(id = R.drawable.ic_android_black_24dp),
contentDescription = null,
modifier = Modifier.size(48.dp),
colorFilter = ColorFilter.tint(DroidColor),
)
}
val infiniteTransition = rememberInfiniteTransition(label = "infinite")
val degrees by infiniteTransition.animateFloat(
initialValue = 0f,
targetValue = 360f,
animationSpec = infiniteRepeatable(
animation = tween(durationMillis = 1000, easing = LinearEasing)
),
label = "degrees",
)
DropShadow(
color = DroidColor.copy(alpha = 0.5f),
offset = DpOffset(4.dp, 4.dp),
radius = 8.dp,
drawInvalidationTrigger = { degrees },
) {
Image(
painter = painterResource(id = R.drawable.ic_android_black_24dp),
contentDescription = null,
modifier = Modifier
.size(48.dp)
.rotate(degrees),
colorFilter = ColorFilter.tint(DroidColor),
)
}
Box(
modifier = Modifier
.size(48.dp)
.boxShadow(
color = Color.Black.copy(alpha = 0.5f),
offset = DpOffset(4.dp, 4.dp),
radius = 8.dp,
)
.background(Color.Red)
)
Box(
modifier = Modifier
.size(48.dp)
.boxShadow(
color = Color.Black.copy(alpha = 0.5f),
offset = DpOffset(4.dp, 4.dp),
radius = 8.dp,
shape = CircleShape
)
.background(Color.Red)
)
}
Sample()
}
}
}

private val DroidColor = Color(0xFF3DDC84)
41 changes: 41 additions & 0 deletions sample/shared/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
plugins {
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.compose.multiplatform)
alias(libs.plugins.android.library)
id("io.github.kubode.compose.shadow.kotlin.common")
id("io.github.kubode.compose.shadow.compose.multiplatform")
id("io.github.kubode.compose.shadow.android.common")
}

kotlin {
jvm()
androidTarget()
iosArm64()
iosX64()
iosSimulatorArm64()
macosArm64()
macosX64()
js {
browser()
}

explicitApi()

sourceSets {
commonMain {
dependencies {
implementation(compose.material)
implementation(projects.composeBoxshadow)
}
}
androidMain {
dependencies {
implementation(projects.composeDropshadow)
}
}
}
}

android {
namespace = "io.github.kubode.compose.shadow.sample.shared"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package io.github.kubode.compose.shadow.sample.shared

import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.animateFloat
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.rememberInfiniteTransition
import androidx.compose.animation.core.tween
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.gestures.scrollable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.text.BasicText
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Phone
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.DpOffset
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import io.github.kubode.compose.boxshadow.boxShadow
import io.github.kubode.compose.dropshadow.DropShadow

@Composable
public fun Sample() {
Column(
modifier = Modifier
.fillMaxSize()
.background(Color.White)
.padding(16.dp)
.scrollable(
state = rememberScrollState(),
orientation = Orientation.Vertical
),
verticalArrangement = Arrangement.spacedBy(32.dp),
) {
DropShadow(
color = Color.Black.copy(alpha = 0.5f),
offset = DpOffset(2.dp, 2.dp),
radius = 2.dp,
modifier = Modifier
.border(1.dp, Color.Black)
.padding(16.dp),
) {
BasicText(
text = buildAnnotatedString {
withStyle(SpanStyle(color = Color(0xFF37BF6E))) {
append("Compose")
}
append(" ")
withStyle(SpanStyle(color = Color(0xFF041619))) {
append("Shadow")
}
append(" ")
withStyle(SpanStyle(color = Color(0xFF3870B2))) {
append("Alternative")
}
},
style = TextStyle.Default.copy(fontSize = 24.sp)
)
}
DropShadow(
color = DroidColor.copy(alpha = 0.5f),
offset = DpOffset(4.dp, 4.dp),
radius = 8.dp,
) {
Image(
imageVector = Icons.Outlined.Phone,
contentDescription = null,
modifier = Modifier.size(48.dp),
colorFilter = ColorFilter.tint(DroidColor),
)
}
val infiniteTransition = rememberInfiniteTransition(label = "infinite")
val degrees by infiniteTransition.animateFloat(
initialValue = 0f,
targetValue = 360f,
animationSpec = infiniteRepeatable(
animation = tween(durationMillis = 1000, easing = LinearEasing)
),
label = "degrees",
)
DropShadow(
color = DroidColor.copy(alpha = 0.5f),
offset = DpOffset(4.dp, 4.dp),
radius = 8.dp,
drawInvalidationTrigger = { degrees },
) {
Image(
imageVector = Icons.Outlined.Phone,
contentDescription = null,
modifier = Modifier
.size(48.dp)
.rotate(degrees),
colorFilter = ColorFilter.tint(DroidColor),
)
}
Box(
modifier = Modifier
.size(48.dp)
.boxShadow(
color = Color.Black.copy(alpha = 0.5f),
offset = DpOffset(4.dp, 4.dp),
radius = 8.dp,
)
.background(Color.Red)
)
Box(
modifier = Modifier
.size(48.dp)
.boxShadow(
color = Color.Black.copy(alpha = 0.5f),
offset = DpOffset(4.dp, 4.dp),
radius = 8.dp,
shape = CircleShape
)
.background(Color.Red)
)
}
}

private val DroidColor = Color(0xFF3DDC84)
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ rootProject.name = "compose-shadow-alternative"
include(":compose-boxshadow")
include(":compose-dropshadow")
include(":sample:androidApp")
include(":sample:shared")

0 comments on commit e2f4ca5

Please sign in to comment.