ursus
02/16/2024, 3:21 PMswitch checkState {
case .checking,
.checked(isVerified: true):
ProgressView()
.controlSize(.large)
case .checked(isVerified: false):
InlineErrorView(
title: "...",
message: "...",
onRetryTapped: onRetry
)
case .checkFailed(let errorDetails):
InlineErrorView(
errorDetails: errorDetails,
onRetryTapped: onRetry
)
}
what is the neatest way I can rewrite this in kotlin?
key thing that compiler check I have consumed all the branches
note that this is UI which has "positional" identity or whatever is called = I cannot have 2 branches returning ProgressView
, as declaration UI frameworks will consider those being 2 different viewsYoussef Shoaib [MOD]
02/16/2024, 3:50 PMchecked
into checkedAndVerified
and checkedButNotVerified
would be the idiomatic way.
If this is SwiftUI code I don't think Kotlin supports it though, so be aware of thatursus
02/16/2024, 3:52 PMYoussef Shoaib [MOD]
02/16/2024, 3:53 PMursus
02/16/2024, 3:55 PMursus
02/16/2024, 3:56 PMursus
02/16/2024, 3:57 PMYoussef Shoaib [MOD]
02/16/2024, 3:57 PMwhen (checkState) {
is Checking, is CheckedAndVerified -> ...
is CheckedButNotVerified -> ...
is CheckFailed -> InlineErrorView(checkState.errorDetails, onRetry) // magic of smart casts
}
Youssef Shoaib [MOD]
02/16/2024, 3:58 PMursus
02/16/2024, 11:18 PM