This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
custom-rules: | |
ManualEffectHandling: | |
active: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
your.package.name.MyCustomRuleSetProvider |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyCustomRuleSetProvider : RuleSetProvider { | |
override val ruleSetId: String = "custom-rules" | |
override fun instance(config: Config) = | |
RuleSet(ruleSetId, listOf(LaunchedEffectWithEffectParamRule(config))) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LaunchedEffectWithEffectParamRule(config: Config) : Rule(config) { | |
// ... | |
override fun visitCallExpression(expression: KtCallExpression) { | |
super.visitCallExpression(expression) | |
val calleeName = expression.calleeExpression?.text ?: return | |
if (calleeName != "LaunchedEffect") return |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LaunchedEffectWithEffectParamRule(config: Config) : Rule(config) { | |
private val effectNameCandidates = setOf( | |
"effect", "effects", "viewEffect", "uiEffect", "event", "viewEvent", | |
"viewModel.effect", "viewModel.effects", "viewModel.viewEffect", | |
"viewModel.event", "viewModel.viewEvent", "viewModel.uiEffect", | |
) | |
override val issue = Issue( | |
id = "ManualEffectHandling", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins { | |
kotlin("jvm") version "2.1.0" // Use version catalog | |
} | |
dependencies { | |
// Use version catalog instead | |
compileOnly("io.gitlab.arturbosch.detekt:detekt-api:1.23.8") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed interface UserProfileEvent { | |
data object DeleteAccount : UserProfileEvent | |
data object ConsumeEffect : UserProfileEvent | |
} | |
sealed interface UserProfileEffect { | |
data class ShowError(val message: String) : UserProfileEffect | |
data object NavigateToLogin : UserProfileEffect | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun UserProfileScreen( | |
viewModel: UserProfileViewModel = hiltViewModel() | |
) { | |
// ... | |
EffectHandler(viewModel.viewEffect, viewModel::processEvent) | |
} | |
@Composable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun <EFFECT> LaunchedUiEffectHandler( | |
effectFlow: Flow<EFFECT?>, | |
onEffect: suspend (EFFECT) -> Unit, | |
onConsumeEffect: () -> Unit, | |
) { | |
val effect by effectFlow.collectAsStateWithLifecycle(null) | |
val currentOnEffect by rememberUpdatedState(onEffect) | |
val currentOnConsumeEffect by rememberUpdatedState(onConsumeEffect) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun deleteAccount() { | |
viewModelScope.launch { | |
// ... | |
try { | |
userRepository.deleteAccount() | |
_uiState.update { | |
it.copy( | |
isLoading = false, | |
effect = UserProfileEffect.NavigateToLogin |
NewerOlder