Menu Actions - lazaronixon/react-native-turbolinks GitHub Wiki

This Wiki show you how to implement a simple menu.

Basic Usage

import React, { Component } from 'react'
import Turbolinks from 'react-native-turbolinks'

const baseUrl = 'http://MYIP:9292'

export default class App extends Component {

  componentDidMount() {
    Turbolinks.addEventListener('turbolinksVisit', this.handleVisit)
    Turbolinks.addEventListener('turbolinksError', this.handleError)
    Turbolinks.addEventListener('turbolinksActionPress', this.handleActionPress)
    Turbolinks.startSingleScreenApp({url: baseUrl, actions: [{id: 0, title: 'Page One'}, {id: 1, title: 'Page Two'}]})
  }

  handleVisit = (data) => {
    Turbolinks.visit({url: data.url, action: data.action})
  }

  handleError = (data) => {
    alert(data.description)
  }

  handleActionPress = (actionId) => {
    switch (actionId) {
      case 0:
        Turbolinks.visit({url: baseUrl + '/one'})
        break
      case 1:
        Turbolinks.visit({url: baseUrl + '/two'})
        break
    }
  }

  render() {
    return null
  }
}