I just added a tool to my site that let's you comp...
# compose
v
I just added a tool to my site that let's you compare the various declarative frameworks like Compose, React, Flutter and SwiftUI. Check it out - https://www.jetpackcompose.app/compare-declarative-frameworks/JetpackCompose-vs-React-vs-SwiftUI
👍 17
👍🏽 1
👍🏾 1
👍🏻 2
p
I like how swiftui encapsulates the State within a View struct itself. In compose it has to be remembered or hosted outside the function.
l
One comment on the conditionals: I noticed that the Flutter demo uses a ternary to decide text, but the others have separate branches for the different text values. The way it's done for the Flutter example doesn't necessarily show the general case of 'I want to show this or that', in the same way the compose or SwiftUI samples do.
m
@Pablichjenkov True, but it's confusing sometimes, you need to deal with
@State
@Binding
@Published
, in compose we just have a state and we need to remember it if we are inside a Composable, it's more flexible and straight forward.
v
@Landry Norris Could you share the more accurate syntax. I'm happy to update it
Fun fact: Compose used to have a
state
syntax as well which internally just did
remember
and
mutableStateOf
. Before the 1.0 release, that was removed from the API to ensure that developers weren't skipping out learning about
remember
and
mutableStateOf
which were important concepts to grasp themselves.
l
It's been a while, but I believe the more general syntax for the Flutter sample would be
Copy code
class ConditionalComponent extends StatelessWidget {
  final bool condition;

  ConditionalComponent({required this.condition});

  @override
  Widget build(BuildContext context) {
    if(condition) {
      return Text("Condition is true");
    } else {
      return Text("Condition is false");
  }
}

// Usage
ConditionalComponent(condition: true)
That puts it more in line with the other frameworks in showing 'display this or that' as opposed to 'show this text or that text', which is subtly different.
v
I see what you mean, fair enough! I'll update it!
m
He is talking about states there, it needs to be a
StatefullWidget
and a
remember
mutableStateOf
for Compose. But for
StatelessWidget
could just be compared with a Composable containing some params without mutable states.
z
omg this is so cool
p
@mohamed rejeb I agree with you, at the end it is a matter of state management preference. iOS colleagues see compose too functional because they got used to the struct design already.
c
I did not even know there are these many concepts in a declarative UI framework!