Last active
July 13, 2020 16:20
-
-
Save alin-turcu/38b25e1469e4897e7d7b1aedb3fd2e8a to your computer and use it in GitHub Desktop.
jetpack vs SwiftUi
This file contains 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 MyApp extends State<MyHomePage> { | |
int count = 0; | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: Column(children: <Widget>[ | |
Text('count $count',), | |
FlatButton(child: Text("Increment",), onPressed: () { setState(() { count++; });}), | |
FlatButton(child: Text("Decrement",), onPressed: () { setState(() { count--; });}), | |
])); | |
} | |
} |
This file contains 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 AppBody() { | |
val count = +state { 0 } | |
Center { | |
Column { | |
Text("count: ${count.value}") | |
Button("Increment", onClick = { count.value++ }) | |
Button("Decrement", onClick = { count.value-- }) | |
} | |
} | |
} |
This file contains 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
struct AppBody : View { | |
@State var count = 0 | |
var body: some View { | |
VStack { | |
Text("count: \(count)") | |
Button("Increment") { self.count += 1 } | |
Button("Decrement") { self.count -= 1 } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment