Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Flutter or React Native, a cross-platform dilemma | DevFest Pisa 2019

Flutter or React Native, a cross-platform dilemma | DevFest Pisa 2019

Nowadays the hype around Flutter is raising a lot. But what about the "(not so) old-fashioned" React Native? In this talk, we will see the basics and the differences between the two frameworks and which to choose. All this journey is based on the true story of an Android Developer that he wanted to explore the cross-platform jungle.

Marco Gomiero

April 13, 2019
Tweet

More Decks by Marco Gomiero

Other Decks in Programming

Transcript

  1. WHO I AM Software & Data Engineer @ Uniwhere MARCO

    GOMIERO COMPUTER ENGINEER Co-Leader @ GDG Venezia
  2. History JANUARY 2015 First public preview MAY 2015 Open sourced

    and launched officially SUMMER 2013 First version developed during an internal hackathon 2013 2015 2015 React Native
  3. History JANUARY 2015 First public preview MAY 2015 Open sourced

    and launched officially SUMMER 2013 First version developed during an internal hackathon 2013 2015 2015 Flutter React Native MAY 2017 Alpha Release DECEMBER 2018 First 1.0 version APRIL 2015 Unveiled at Dart Dev Summit 2015 2018 2017
  4. React Native • Javascript • ☠ for Object Oriented Devs:

    • Type Conversion • Sometimes silently fails • Prototype based inheritance • Ecosystem Confusion
  5. Flutter • Dart, invented by Google in 2011 • Object

    Oriented friendly • e.g strongly typed but type can be inferred • Flat learning curve for OO devs • Mobile -> compiles to ARM and x86 code • Web -> transpiles to Javascript
  6. UI

  7. // React Native import React from "react"; import { StyleSheet,

    Text, View } from "react-native"; export default class App extends React.Component { render() { return ( <View style={styles.container}> <Text>Hello world!</Text> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: "#fff", alignItems: "center", justifyContent: "center" } });
  8. // React Native import React from "react"; import { StyleSheet,

    Text, View } from "react-native"; export default class App extends React.Component { render() { return ( <View style={styles.container}> <Text>Hello world!</Text> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: "#fff", alignItems: "center", justifyContent: "center" } }); // Flutter import 'package:flutter/material.dart'; void main() { runApp( Center( child: Text( 'Hello, world!', textDirection: TextDirection.ltr, ), ), ); }
  9. // React Native import React from "react"; import { StyleSheet,

    Text, View } from "react-native"; export default class App extends React.Component { render() { return ( <View style={styles.container}> <Text>Hello world!</Text> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: "#fff", alignItems: "center", justifyContent: "center" } }); // Flutter import 'package:flutter/material.dart'; void main() { runApp( Center( child: Text( 'Hello, world!', textDirection: TextDirection.ltr, ), ), ); }
  10. // React Native import React from "react"; import { StyleSheet,

    Text, View } from "react-native"; export default class App extends React.Component { render() { return ( <View style={styles.container}> <Text>Hello world!</Text> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: "#fff", alignItems: "center", justifyContent: "center" } });
  11. // React Native import React from "react"; import { StyleSheet,

    Text, View } from "react-native"; export default class App extends React.Component { render() { return ( <View style={styles.container}> <Text>Hello world!</Text> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: "#fff", alignItems: "center", justifyContent: "center" } });
  12. // React Native import React from "react"; import { StyleSheet,

    Text, View } from "react-native"; export default class App extends React.Component { render() { return ( <View style={styles.container}> <Text>Hello world!</Text> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: "#fff", alignItems: "center", justifyContent: "center" } });
  13. // React Native import React from "react"; import { StyleSheet,

    Text, View } from "react-native"; export default class App extends React.Component { render() { return ( <View style={styles.container}> <Text>Hello world!</Text> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: "#fff", alignItems: "center", justifyContent: "center" } });
  14. // React Native import React from "react"; import { StyleSheet,

    Text, View } from "react-native"; export default class App extends React.Component { render() { return ( <View style={styles.container}> <Text>Hello world!</Text> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: "#fff", alignItems: "center", justifyContent: "center" } }); Components • Basic UI building blocks • Fit together to form a custom component • Domain specific language called JSX • Customisable with CSS • Or better “usually match how CSS works on the web”
  15. // React Native import React from "react"; import { StyleSheet,

    Text, View } from "react-native"; export default class App extends React.Component { render() { return ( <View style={styles.container}> <Text>Hello world!</Text> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: "#fff", alignItems: "center", justifyContent: "center" } }); // Flutter import 'package:flutter/material.dart'; void main() { runApp( Center( child: Text( 'Hello, world!', textDirection: TextDirection.ltr, ), ), ); }
  16. // Flutter import 'package:flutter/material.dart'; void main() { runApp( Center( child:

    Text( 'Hello, world!', textDirection: TextDirection.ltr, ), ), ); }
  17. // Flutter import 'package:flutter/material.dart'; void main() { runApp( Center( child:

    Text( 'Hello, world!', textDirection: TextDirection.ltr, ), ), ); }
  18. // Flutter import 'package:flutter/material.dart'; void main() { runApp( Center( child:

    Text( 'Hello, world!', textDirection: TextDirection.ltr, ), ), ); }
  19. // Flutter import 'package:flutter/material.dart'; void main() { runApp( Center( child:

    Text( 'Hello, world!', textDirection: TextDirection.ltr, ), ), ); } • Basic UI building blocks • Takes inspiration from RN • Everything is a Widget Widgets
  20. Components vs Widgets: Summary • React Native: jumps from Javascript

    to JSX • Flutter: remains in the Dart context • Possibility of UI modularisation
  21. Components vs Widgets: Summary • React Native: jumps from Javascript

    to JSX • Flutter: remains in the Dart context • Possibility of UI modularisation
  22. React Native • Core: an infrastructure, aka “Bridge” built at

    runtime • It lets native code call JS and viceversa • Your code run inside a JS Virtual Machine: JavaScriptCore • Event driven
  23. • Event driven Event Serialized Payload Process Event Process Command

    Serialized Response Call native methods App opening [1, 1, [‘My App’, {}]] [[2, 3, [2, ‘View’, {…}]],
 [2, 3, [3, ‘View’, {…}]]] val view = View()
 val view = TextView() Render new Views
  24. • Event driven • Calls passed between JS to Native

    in a “batched asynchronous way” • quequed in the MessageQueue -> flushed every 5 ms by default
  25. New RN Architecture • React Native team is working on

    a new architecture: Fabric • High priority UI updates synchronously • More info: https://www.youtube.com/watch?v=UcqRXTriUVI
  26. Flutter • Dart code compiled into native, ARM and x86

    libraries • Widgets are managed and rendered using a C++ engine Framework (Dart) Engine (C++) Skia Dart Text Material Cupertino Widgets Rendering Animation Painting Gestures Foundation
  27. Flutter • Dart code compiled into native, ARM and x86

    libraries • Widgets are managed and rendered using a C++ engine • All elements are rendered with Skia, a 2-d graphics library • Pro: take advantage of the GPU • Cons: app size is larger
  28. Recap • Components translated to native • Use Native components

    • Delay due to Bridge initialisation and runtime translation • Widget independent of the OS • No translation time needed • Include its own widgets
  29. Crossplatform • Crossplatform is not bad but… IS NOT better

    than native • It’s a choice with compromises based on specific situation • If trouble became higher than benefits, make a step back
  30. React Native or Flutter ? • Right now, React Native

    is more stable and solid • Flutter is the future • If Google does not drop it $ • Better performance that other framework • Dart is a more modern language
  31. Bibliography / Useful Links • https://flutter.dev/docs/development/ui/widgets-intro • https://flutter.dev/docs/get-started/flutter-for/react-native-devs • https://facebook.github.io/react-native/docs/components-and-apis.html

    • https://levelup.gitconnected.com/wait-what-happens-when-my-react-native-application-starts-an-in-depth-look-inside-react- native-5f306ef3250f • https://flutter.dev/docs/resources/faq • https://flutter.dev/docs/resources/technical-overview • https://speakerdeck.com/mkonicek/under-the-hood-of-react-native • https://speakerdeck.com/frantic/react-native-under-the-hood • https://www.youtube.com/watch?v=rReCzR6DMEM • https://medium.com/snapp-mobile/multi-vs-cross-platform-in-the-age-of-flutter-6e76920028b6 • https://medium.com/dartlang/announcing-dart-2-80ba01f43b6 • https://medium.com/airbnb-engineering/sunsetting-react-native-1868ba28e30a