Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PC-92] Matching 화면 UI 구현 #11

Merged
merged 12 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ dependencies {
implementation(project(":core:designsystem"))
implementation(project(":core:domain"))
implementation(project(":core:navigation"))
implementation(project(":core:common-ui"))
// implementation(project(":core:analytics"))
// implementation(project(":core:common-ui"))

val libs = project.extensions.libs
implementation(libs.findLibrary("kotlinx.serialization.json").get())
Expand Down
1 change: 1 addition & 0 deletions core/common-ui/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
12 changes: 12 additions & 0 deletions core/common-ui/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
plugins {
id("piece.android.library")
id("piece.android.compose")
}

android {
namespace = "com.puzzle.common.ui"
}

dependencies {
implementation(projects.core.designsystem)
}
Empty file.
21 changes: 21 additions & 0 deletions core/common-ui/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.puzzle.common.ui

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.puzzle.common.ui.test", appContext.packageName)
}
}
4 changes: 4 additions & 0 deletions core/common-ui/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
102 changes: 102 additions & 0 deletions core/common-ui/src/main/java/com/puzzle/common/ui/ModifierUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package com.puzzle.common.ui

import androidx.compose.animation.core.Spring.StiffnessMediumLow
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.spring
import androidx.compose.animation.core.tween
import androidx.compose.foundation.clickable
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableLongStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.focus.FocusManager
import androidx.compose.ui.geometry.CornerRadius
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.puzzle.designsystem.foundation.PieceTheme

fun Modifier.addFocusCleaner(
focusManager: FocusManager,
onFocusCleared: () -> Unit = {},
): Modifier {
return this.pointerInput(Unit) {
detectTapGestures(
onTap = {
onFocusCleared()
focusManager.clearFocus()
},
)
}
}

@Composable
fun Modifier.throttledClickable(
throttleTime: Long,
onClick: () -> Unit,
enabled: Boolean = true,
): Modifier = composed {
var lastClickTime by remember { mutableLongStateOf(0L) }

this.clickable(enabled = enabled) {
val currentTime = System.currentTimeMillis()
if (currentTime - lastClickTime >= throttleTime) {
onClick()
lastClickTime = currentTime
}
}
}

@Composable
fun Modifier.verticalScrollbar(
state: LazyListState,
width: Dp = 6.dp,
color: Color = PieceTheme.colors.light2,
): Modifier {

val targetAlpha = if (state.isScrollInProgress) .7f else 0f
val duration = if (state.isScrollInProgress) 150 else 1000

val alpha by animateFloatAsState(
targetValue = targetAlpha,
animationSpec = tween(durationMillis = duration)
)

val firstIndex by animateFloatAsState(
targetValue = state.layoutInfo.visibleItemsInfo.firstOrNull()?.index?.toFloat() ?: 0f,
animationSpec = spring(stiffness = StiffnessMediumLow)
)

val lastIndex by animateFloatAsState(
targetValue = state.layoutInfo.visibleItemsInfo.lastOrNull()?.index?.toFloat() ?: 0f,
animationSpec = spring(stiffness = StiffnessMediumLow)
)

return drawWithContent {
drawContent()

val itemsCount = state.layoutInfo.totalItemsCount

if (itemsCount > 0 && alpha > 0f) {
val scrollbarTop = firstIndex / itemsCount * size.height
val scrollBottom = (lastIndex + 1f) / itemsCount * size.height
val scrollbarHeight = scrollBottom - scrollbarTop
drawRoundRect(
color = color,
cornerRadius = CornerRadius(0.1f),
topLeft = Offset(size.width - width.toPx(), scrollbarTop),
size = Size(width.toPx(), scrollbarHeight),
alpha = alpha
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.puzzle.common.ui

import org.junit.Test

import org.junit.Assert.*

/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}
4 changes: 1 addition & 3 deletions core/designsystem/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ android {
namespace = "com.puzzle.designsystem"
}

dependencies {
implementation(libs.lottie.compose)
}
dependencies {}
Loading
Loading