안드로이드(28)
-
Avoiding recomposition
Recomposition 입력 매개변수 또는 외부 상태의 변경에 따라 함수를 재구성하고 호출 하는 것. compose의 기본 개념 Stable parametersString, Int, Float, ImmutableList Unstable parametersList, Map, Set , var ( Data classes) Avoiding Recomposition@Stable 사용값이 관찰 가능해지며, 값이 변경되면 알림이 전송됨@Stable data class Contact(var flag: MutableState = mutableStateOf(false))→ flag변수의 값이 변경될 때만 recomposition @Immutable 사용값이 절대 변경되지 않을 것이라고 약속하는 annotation항목이..
2023.11.01 -
UI Testing (with Jetpack Compose)
종속성 추가 dependencies { [...] testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.compose.ui:ui-test-junit4' debugImplementation 'androidx.compose.ui:ui-test-manifest' } 테스트 클래스 만들기 테스트하려는 기능을 마우스 오른쪽 버튼으로 클릭 UI 요소를 테스트할 예정이므로 androidTest 패키지 에 작성해야함 클래스 생성 완료 테스트 작성 아래는 @RunWith(), @Before, @Get, @Text를 사용한 예제이다. 클래스의 첫 번째 주석을 활용하여 JUnit 4로 실행하고, 두 번째 주석을 사용하여 구성 가능한 구성 요소..
2023.10.23 -
자주 까먹는 compose modifiers
1). border Modifier@Composable fun MakeBorder( modifier: Modifier = Modifier ) { Box(modifier = modifier.fillMaxSize(), contentAlignment = Alignment.Center) { Spacer( modifier = Modifier .border( color = Color.Red, width = 2.dp, shape = CircleShape ) .size(100.dp) ) } }2). horizontalScroll Modifier@Composable fun HorizontalScroll( modifier: Modifier = Modifier ) { val scrollState = rememberScrol..
2023.10.23 -
Data store vs Shared preference
DataStoreSharedPreference는 동기적으로 동작. 특히 이의 apply()는 ui스레드를 차단하여 잠재적인 성능 문제를야기할 수 있음 → 대안책 Dispatchers.IO 옵션을 사용하면 ui스레드 안전성을 보장받을 수 있음Proto DataStore코루틴과 플로우를 활용함Preferences DataStore키-밸류 쌍 관리sharedPreferencs의 완벽한 대응책 Interface DataStoreAPIinterface DataStoreAPI { suspend fun getPreferenceValue(key: Preferences.Key,defaultValue: T):T suspend fun putPreferenceValue(key: Preferences.Key,value:T) s..
2023.10.23 -
to clean code (in Kotlin)
Kotlin ContractsCallsInPlace컴파일러가 람다 함수가 호출되는 방식과 해당 매개변수와 상호작용 하는 방식을 이해하는데 도움이 됨AT_MOST_ONCEAT_LEAST_ONCEEXACTLY_ONCEUNKNOWNinline fun customRun(block: () -> T): T { contract { callsInPlace(block, AT_MOST_ONCE) } return block() } InvocationKind호출시 함수가 작동하는 방식을 지정. 옵션은 아래 두 개returns(true)implies(this ≠ null)fun getUserById(id: Int?): User? { contract { returns(true) implies (id != null) } // Yo..
2023.10.23 -
Deligation을 통한 상태관리 단순화
솔루션: Delegate Classes 🛠️ 우려 사항 분리: 각 기능에 대한 delegate 클래스를 제작함으로써 각 구성 요소를 개별적으로 작업할 수 있어, 테스트 및 개발이 더 쉬워진다 🛠️ 공유 상태 관리: 메인 ViewModel이 중재자 역할을 하고. 분리된 부분을 연결하여 퍼즐을 완성할 수 있다는 것을 알고있음. 이를 통해 오래된 데이터를 무효화하거나, 대규모 저장소를 구축하는 것에 대한 걱정 없이 상태 데이터를 공유할 수 있음 classInRideViewModel ( privateval rideDelegate: RideDelegate, privateval NavigationDelegate: NavigationDelegate ) : ViewModel(), NavigationDelegateby ..
2023.10.23