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

React Native talk

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.

React Native talk

Avatar for Agapov Alex

Agapov Alex

December 08, 2017
Tweet

More Decks by Agapov Alex

Other Decks in Programming

Transcript

  1. Topics 1. ! React Native basics 2. " Components 3.

    # Redux 4. $ Tools 5. % Unit testing 6. & Android, iOS builds (+ CI) Saritasa 2
  2. ! 1. React Native ! Javascript language ! React.js as

    a view layer ! Native components (+predefined) ! iOS, Android, tvOS used in Facebook, Instagram, WiX, Artsy, Airbnb Saritasa 3
  3. ! 1. React Native ! One code for platforms (reusable)

    ! Fast development (Hot reloading, js, live reload) " Different OS (iOS vs Android written in js) " Young Saritasa 4
  4. ! 2. Components // Basic class View extends React.Component {

    render() { return ( <View> <Text>Hello world</Text> </View> ) } } Saritasa 5
  5. ! 2. Components // Lifecycle class View extends React.Component {

    // props from parent, state is inside constructor(props) {} shouldComponentUpdate(nextProps, nextState) {} componentWillMount() {} componentDidMount() {} // ... render() {} } Saritasa 6
  6. ! 3. Redux // State const initialState = { todos:

    { list: [ { text: 'Mess with React Native', isDone: true }, { text: 'Tell everyone how cool redux is', isDone: false } ] } } Saritasa 9
  7. ! 3. Redux // Action Creator const addTodo(text) { return

    { type: 'ADD_TODO', payload: { todo: { text: text, isDone: false } } } } Saritasa 10
  8. ! 3. Redux // Reducer const todosReducer = (state =

    initialState.todos, action) { switch action.type { case 'ADD_TODO': return { ...state, list: [ ...state.list, action.payload.todo // Append todo item ] } default: return state } } Saritasa 11
  9. 4. Tools. Language Why not Typescript? ! Full type control

    (compiler) ! Enums! 'default'/'disabled' ! Long integration ! Overhead sometimes ! Libraries without typescript headers ! Javascript is evolving, and sometimes is OK Saritasa 13
  10. 4. Tools. Persistence // It was realm at first import

    { persistStore } from 'redux-persist'; import storage from 'redux-persist-filesystem-storage'; const config = { storage }; const reducer = persistReducer(config, rootReducer); const store = createStore(reducer, initialState); const persistor = persistStore(store); Saritasa 14
  11. 5. Unit tests THEY'RE GREAT! Use jest, custom matchers !

    Runs in node process ! TDD approved ! Pure functions are testable. (Redux) Test reducers, action creators, utils. If you want - components are testable too. Saritasa 15
  12. ! 6. Build Android => Build for Android :) Use

    gradle and /android folder. iOS => Build for iOS :) Use fastlane and /ios folder. Saritasa 17
  13. 6. Build # Before anything: npm install ☎ Android Setup

    profiles + IDs Gradle! All setup in build.gradle ./gradlew clean assembleRelease ! iOS Setup profiles + IDs Same as we do on Jenkins Saritasa 18
  14. # Sum up. ! React Native is OK for simple

    apps. ! Integration with native modules (i.e. Bluetooth) is pain in the ass. ! After iOS - Hot reloading & VS Code is SOOOO GOOD! ! Code reuse & Developer-friendly (front-end should feel good in RN, cause it's mainly React + Redux + JS) Saritasa 19