-
Notifications
You must be signed in to change notification settings - Fork 0
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
[컴포즈] NavController 활용한 컴포즈 화면 구성 #52
Changes from all commits
90bda46
8eca830
77890e7
1102579
065bf5d
e167d6c
74f5556
732bdac
a2494e4
b4f8ec9
f9e5852
b3b5427
f35c0a7
b240ca9
8dc5f66
ffac87d
e6b03ea
68bbcc9
4e6828f
9359f54
119fab9
ae2b9e2
05c7c54
78e4066
807b953
32d15d7
8cfe8d3
969a6a8
b4683eb
4d201c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ object Apps { | |
object Versions { | ||
const val retrofit = "2.9.0" | ||
const val lifecycle = "2.6.1" | ||
const val hilt = "2.45" | ||
const val hilt = "2.48" | ||
} | ||
|
||
object AndroidX { | ||
|
@@ -59,10 +59,21 @@ object Retrofit { | |
} | ||
|
||
object Glide { | ||
const val base = "com.github.bumptech.glide:glide:4.16.0" | ||
const val okhttp = "com.github.bumptech.glide:okhttp3-integration:4.16.0" | ||
const val compiler = "com.github.bumptech.glide:ksp:4.16.0" | ||
const val base = "com.github.bumptech.glide:glide:4.13.2" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:property-naming reported by reviewdog 🐶 |
||
const val okhttp = "com.github.bumptech.glide:okhttp3-integration:4.13.2" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:property-naming reported by reviewdog 🐶 |
||
const val compiler = "com.github.bumptech.glide:compiler:4.13.2" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:property-naming reported by reviewdog 🐶 |
||
const val annotations = "com.github.bumptech.glide:annotations:4.13.2" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:property-naming reported by reviewdog 🐶 |
||
const val compose = "com.github.bumptech.glide:compose:1.0.0-beta01" | ||
// const val base = "com.github.bumptech.glide:glide:4.16.0" | ||
// const val okhttp = "com.github.bumptech.glide:okhttp3-integration:4.16.0" | ||
// const val compiler = "com.github.bumptech.glide:ksp:4.16.0" | ||
// const val annotations = "com.github.bumptech.glide:annotations:4.16.0" | ||
// const val compose = "com.github.bumptech.glide:compose:1.0.0-beta01" | ||
// const val base = "com.github.bumptech.glide:glide:5.0.0-rc01" | ||
// const val okhttp = "com.github.bumptech.glide:okhttp3-integration:5.0.0-rc01" | ||
// const val compiler = "com.github.bumptech.glide:ksp:5.0.0-rc01" | ||
// const val annotations = "com.github.bumptech.glide:annotations:5.0.0-rc01" | ||
// const val compose = "com.github.bumptech.glide:compose:1.0.0-beta01" | ||
} | ||
|
||
object KotlinX { | ||
|
@@ -90,6 +101,8 @@ object Compose { | |
const val viewModel = "androidx.lifecycle:lifecycle-viewmodel-compose:2.5.1" | ||
const val constraint = "androidx.constraintlayout:constraintlayout-compose:1.0.1" | ||
const val runtime = "androidx.compose.runtime:runtime" | ||
const val navigation = "androidx.navigation:navigation-compose:2.7.7" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:property-naming reported by reviewdog 🐶 |
||
const val navigationViewModel = "androidx.hilt:hilt-navigation-compose:1.0.0" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:property-naming reported by reviewdog 🐶 |
||
} | ||
|
||
object UnitTest { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
package com.hmju.core.compose | ||
|
||
import androidx.compose.foundation.gestures.detectTapGestures | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.DisposableEffect | ||
import androidx.compose.runtime.MutableState | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.focus.FocusManager | ||
import androidx.compose.ui.input.pointer.pointerInput | ||
import androidx.fragment.app.FragmentActivity | ||
import androidx.lifecycle.LifecycleEventObserver | ||
import androidx.lifecycle.LifecycleOwner | ||
import androidx.lifecycle.SavedStateHandle | ||
import androidx.navigation.NavController | ||
import androidx.navigation.NavHostController | ||
import com.hmju.core.compose.ComposeLifecycleState.Companion.from | ||
|
||
|
||
|
@@ -35,3 +43,45 @@ fun rememberLifecycleUpdatedState( | |
} | ||
return currentState | ||
} | ||
|
||
/** | ||
* 다른데 터치할때 키보드 내리기 위한 유틸 함수 | ||
* @param focusManager LocalFocusManager | ||
*/ | ||
fun Modifier.addFocusCleaner( | ||
focusManager: FocusManager, | ||
doOnClear: () -> Unit = {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶 |
||
): Modifier { | ||
return this.pointerInput(Unit) { | ||
detectTapGestures(onTap = { | ||
doOnClear() | ||
focusManager.clearFocus() | ||
}) | ||
} | ||
} | ||
|
||
fun NavHostController.backPressed() { | ||
if (!popBackStack()) { | ||
val activity = this.context as? FragmentActivity | ||
activity?.finish() | ||
} | ||
} | ||
|
||
inline fun <reified T> NavController.getBundleData(key: String): T? { | ||
val savedStateHandle = currentBackStackEntry?.savedStateHandle ?: return null | ||
return savedStateHandle.get<T>(key) | ||
} | ||
|
||
inline fun NavController.putBundle( | ||
predicate: SavedStateHandle.() -> Unit | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:function-signature reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:function-signature reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶 |
||
) { | ||
val savedStateHandle = currentBackStackEntry?.savedStateHandle ?: return | ||
predicate.invoke(savedStateHandle) | ||
} | ||
|
||
inline fun NavController.prevPutBundle( | ||
predicate: SavedStateHandle.() -> Unit | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:function-signature reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:function-signature reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶 |
||
) { | ||
val savedStateHandle = previousBackStackEntry?.savedStateHandle ?: return | ||
predicate.invoke(savedStateHandle) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.hmju.core.compose | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.MutableState | ||
import androidx.compose.runtime.State | ||
import androidx.compose.runtime.collectAsState | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlin.coroutines.CoroutineContext | ||
import kotlin.coroutines.EmptyCoroutineContext | ||
|
||
/** | ||
* Description : | ||
* | ||
* Created by juhongmin on 4/7/24 | ||
*/ | ||
class MutableStateAdapter<T>( | ||
private val state: State<T>, | ||
private val mutate: (T) -> Unit | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶 |
||
) : MutableState<T> { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-empty-first-line-in-class-body reported by reviewdog 🐶 |
||
override var value: T | ||
get() = state.value | ||
set(value) { | ||
mutate(value) | ||
} | ||
|
||
override fun component1(): T = value | ||
override fun component2(): (T) -> Unit = { value = it } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:blank-line-before-declaration reported by reviewdog 🐶 |
||
} | ||
|
||
@Composable | ||
fun <T> MutableStateFlow<T>.collectAsMutableState( | ||
context: CoroutineContext = EmptyCoroutineContext | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:function-signature reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:function-signature reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶 |
||
): MutableState<T> = MutableStateAdapter( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:multiline-expression-wrapping reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:function-signature reported by reviewdog 🐶 |
||
state = collectAsState(context), | ||
mutate = { value = it } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:trailing-comma-on-call-site reported by reviewdog 🐶 |
||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.hmju.core.compose | ||
|
||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
|
||
/** | ||
* Description : Compose + Flow 전용 List 형태의 Flow | ||
* | ||
* Created by juhongmin on 5/6/24 | ||
*/ | ||
class MutableStateFlowList<T> { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-empty-first-line-in-class-body reported by reviewdog 🐶 |
||
private val _list = mutableListOf<T>() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:backing-property-naming reported by reviewdog 🐶 |
||
private val _stateFlow = MutableStateFlow<List<T>>(emptyList()) | ||
|
||
val stateFlow = _stateFlow.asStateFlow() | ||
|
||
fun add(item: T) { | ||
_list.add(item) | ||
notifyObserver() | ||
} | ||
|
||
fun addAll(items: List<T>?) { | ||
if (items == null) return | ||
_list.addAll(items) | ||
notifyObserver() | ||
} | ||
|
||
fun remove(item: T) { | ||
_list.remove(item) | ||
notifyObserver() | ||
} | ||
|
||
private fun notifyObserver() { | ||
_stateFlow.value = _list.toList() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,8 @@ class TilColor internal constructor( | |
val gray3: Color, | ||
val gray3Light: Color, | ||
val gray4: Color, | ||
val gray5: Color | ||
val gray5: Color, | ||
val defBgColor: Color | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶 |
||
) { | ||
constructor() : this( | ||
white = Color(255, 255, 255), | ||
|
@@ -36,6 +37,7 @@ class TilColor internal constructor( | |
gray3 = Color(204, 204, 204), | ||
gray3Light = Color(229, 229, 229), | ||
gray4 = Color(240, 240, 240), | ||
gray5 = Color(247, 247, 247) | ||
gray5 = Color(247, 247, 247), | ||
defBgColor = Color(245,243,244) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:comma-spacing reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:comma-spacing reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:trailing-comma-on-call-site reported by reviewdog 🐶 |
||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [ktlint] standard:property-naming reported by reviewdog 🐶
Property name should use the screaming snake case notation when the value can not be changed