Paul Woitaschek
04/10/2021, 7:23 PM@Compsable fun Counter()
But now I need to separate the logic and UI and need to create a counter class that is the actual counter and not the ui.
Intuitively I'd call that counter class Counter
.
Now having both of these named the same is obviously a bad idea, but what's the solution to this?
Consistently suffixing every composable ui function as CounterUI
? Or CounterView
? How do you handle this?Arkadii Ivanov
04/10/2021, 7:31 PMPaul Woitaschek
04/10/2021, 7:31 PMArkadii Ivanov
04/10/2021, 7:32 PMArkadii Ivanov
04/10/2021, 7:32 PMcurioustechizen
04/10/2021, 7:35 PMCounterState
.Paul Woitaschek
04/10/2021, 7:38 PMPaul Woitaschek
04/10/2021, 7:47 PMArkadii Ivanov
04/10/2021, 7:50 PMPaul Woitaschek
04/10/2021, 7:50 PMArkadii Ivanov
04/10/2021, 7:52 PMPaul Woitaschek
04/10/2021, 8:21 PMdewildte
04/10/2021, 11:00 PMdewildte
04/10/2021, 11:03 PM@Composable
fun HomeScreenUI(
state: HomeScreenUIState
) {
...
}
Colton Idle
04/11/2021, 1:33 AMephemient
04/11/2021, 5:02 AMimport some.package.foo.Counter as FooCounter
import other.package.bar.Counter as BarCounter
and use both of them in the same file without having to fully-qualify either of them.ephemient
04/11/2021, 5:05 AMPaul Woitaschek
04/11/2021, 7:15 AMimport androidx.compose.runtime.Composable as Compostable
๐งHalil Ozercan
04/11/2021, 5:05 PMPaul Woitaschek
04/11/2021, 7:14 PMColton Idle
04/12/2021, 11:01 AMadding a suffix on the composable based on the presentationOoh. I do like that too. But do any of you have a Ui data class? Let's say I have a Person that has like 9 fields. And a PersonCardData class has 4 fields (some are straight mappings from Person, but some are formatted (e.g. think First Name + Get Middle Initial + last name)) Then I want to display PersonCardData in a PersonCard composable? Does that sound reasonable?
Paul Woitaschek
04/12/2021, 11:02 AMSean McQuillan [G]
04/12/2021, 11:56 PMpublic interface CounterState
// default impl with default state policy
private class CounterStateImpl: CounterState()
public fun CounterState(): CounterState = CounterStateImp()
@Composable
public fun Counter(
state: CounterState = remember { CounterState() }
) {
...
}
Seems to be the default naming convention for this esp. if the class is a state-like object. You can do without the interface, but showing the full pattern as it's often useful in letting you have more control without restricting callers ability to specialize behavior.Sean McQuillan [G]
04/12/2021, 11:58 PMSean McQuillan [G]
04/13/2021, 12:11 AMSean McQuillan [G]
04/13/2021, 12:15 AMSean McQuillan [G]
04/13/2021, 12:27 AM@Composable
fun makeCounterState()
Prefer
fun CounterState()
The exception to this rule is if CounterState
must always be remembered, you can add a convenience remember-constructor
@Composable
fun rememberCounterState() = remember { CounterState() }
But if there's any chance you'll ever want to instantiate one outside of compose, provide another mechanism ๐.