• This repository has been archived on 21/Oct/2022
  • Stars
    star
    193
  • Rank 201,081 (Top 4 %)
  • Language
    Java
  • License
    MIT License
  • Created almost 7 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

React Native adapter for building hybrid apps with Turbolinks 5

React Native Turbolinks

A implementation of Turbolinks for iOS and Turbolinks Android for React Native.

React Native Turbolinks

Getting started

yarn add react-native-webview react-native-turbolinks
cd ios && pod install && cd .. # CocoaPods on iOS needs this extra step

Warning

  • This component only applies to projects made with react-native init or to those made with expo-cli which have since ejected. For more information about ejecting, please see the guide on Expo docs.

  • On android you should use Volume UP to show Developer Menu instead ⌘ M.

  • React Native Turbolinks doesn't support Fast Refresh, please disable it on React Native developer menu ⌘ D.

  • Start rails with rails s -b 0.0.0.0.

Basic Usage

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

export default class App extends Component {

  componentDidMount() {
    Turbolinks.addEventListener('turbolinksVisit', this.handleVisit)
    Turbolinks.addEventListener('turbolinksError', this.handleError)
    Turbolinks.startSingleScreenApp({url: 'http://MYIP:9292'})
  }

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

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

  render() { return null }
}

Running the Demo

This repository includes a demo application to show off features of the framework. The demo bundles a simple HTTP server that serves a Turbolinks 5 web app on localhost at port 9292.

To run the demo, clone this repository to your computer and change into its directory. Then, Open file Example/app.json and change baseUrl with your IP and start the demo server by running Example/demo-server from the command line.

Once you’ve started the demo server, explore the demo application in the Simulator by running react-native run-ios or react-native run-android on Example folder.

React Native Turbolinks Demo Application

Methods

startSingleScreenApp(route, appOption = {})

Start a Single Screen App. Use it instead visit for first visit.

startSplitScreenApp(primaryComponent, secondaryRoute, appOption = {})

Start a Splitted Screen App. Use it instead visit for first visit. It is a good choice for iPad. (iOS Only)

visit(route)

Visit a URL or Component.

replaceWith(route)

Replace current visitable with a component. With the same route param like to visit a component.

reloadVisitable()

Reload current visitable. For example when a connection error view is launched and you want to retry.

reloadSession()

Reload current session.

removeAllCookies()

Remove all cookies. Return a promise.

dismiss(animated = true)

Dismiss a overlaped view presented by visiting a component with modal option. Return a promise.

popToRoot(animated = true)

Back until to root view. Return a promise.

back(animated = true)

Trigger a native back event. For example if you using a custom navbar and need to provide a back button. Return a promise.

renderTitle(title, subtitle = null)

Change title of current view. For example if you want to get title from page source.

renderActions(actions)

Change actions of current view. For example if you want to mount a menu looking for data-attributes on page source.

renderNavBarStyle(navBarStyle)

Change navbarStyle on run time. For example if you want to provide a way for the user to choose a theme.

injectJavaScript(script)

Function that accepts a string that will be passed to the WebView and executed immediately as JavaScript. Return a promise.

addEventListener(eventName, handler)

Adds an event handler. Supported events:

  • turbolinksVisit: Fires when you tap a Turbolinks-enabled link. The argument to the event handler is an object with keys: url, path, action.
  • turbolinksError: Fires when your visit’s network request fails.The argument to the event handler is an object with keys: code, statusCode, description.
  • turbolinksMessage: Fires when you send messages from JavaScript to your native application. The argument to the event handler is a string with the message.
  • turbolinksTitlePress: Fire when title is tapped. The arguments to the event handler is an object with keys: url, path, component.
  • turbolinksActionPress: Fire when a action is tapped. The arguments to the event handler is an object with keys: url, path, component, actionId.
  • turbolinksLeftButtonPress: Fire when left button item is tapped. The arguments to the event handler is an object with keys: url, path, component. (iOS Only)
  • turbolinksRightButtonPress: Fire when right button item is tapped. The arguments to the event handler is an object with keys: url, path, component. (iOS Only)
  • turbolinksVisitCompleted: Fire when the request has been fulfilled successfully and the page fully rendered, Here you can parse html and create a dynamic menu for example. The arguments to the event handler is url, path.

removeEventListener(eventName, handler)

Removes the listener for given event.

Objects

Route

  • Url properties
    • url: Url to visit. (Required)
  • Component properties
    • component: Component to visit. (Required)
    • modal: A boolean to show a view without navbar and backbutton. (Default false)
    • dismissable: When true is possible dismiss modal. (Default false)
    • passProps: Passes this in as props to the rendered component.
  • Common properties
    • title: The default value is the title of the Web page.
    • subtitle: A subtitle for visitable view.
    • visibleDropDown: Show a small arrow next to title.
    • hidesNavBar: Hide navigation bar. (Default false)
    • hidesShadow: Indicates whether to hide the navigation 1px hairline shadow. (Default false) (iOS Only)
    • leftButtonText/leftButtonIcon: A left button text/icon. (iOS Only)
    • rightButtonText/rightButtonIcon: A right button text/icon. (iOS Only)
    • actions: A Array of action objects to mount a menu.
    • action: If action is 'advance', so it will perform a animated push, if "replace" will perform a pop without animation. (Default 'advance')

AppOption

  • userAgent: You can check for this string on the server and use it to send specialized markup or assets to your application.
  • messageHandler: You can register a Message Handler to send messages from JavaScript to your application.
  • loadingView: Set a custom loadingView using a react component.
  • navBarStyle: {titleTextColor, subtitleTextColor, barTintColor, tintColor, menuIcon}.
  • injectedJavaScript: Set this to provide JavaScript that will be injected into the web page when the view loads.

Action

  • id: A integer identifier for the action. (Required)
  • title: A title for the action.
  • icon: A icon for the action.
  • button: A boolean to show action inside menu or in toolbar. (Default false) (Android Only)

Constants

Turbolinks.Constants.ErrorCode.httpFailure: 0

Turbolinks.Constants.ErrorCode.networkFailure: 1

Turbolinks.Constants.Action.advance: 'advance'

Turbolinks.Constants.Action.replace: 'replace'

Turbolinks.Constants.Action.restore: 'restore'

Android Style

For android set your style on android/app/src/main/res/values/styles.xml.

TODO

Resources

More Repositories

1

authentication-zero

An authentication system generator for Rails applications.
Ruby
1,530
star
2

react-native-qrcode-reader

JavaScript
250
star
3

the_construct

A Modern Rails Template
CSS
214
star
4

trix-extensions

Trix Extensions
JavaScript
193
star
5

administration-zero

An administration system generator for Rails applications.
HTML
107
star
6

react-native-date-range-picker

Simple date range picker extended from react-native-calendars
JavaScript
105
star
7

turbo-native-initializer

Turbo IOS/Android project generator
Swift
80
star
8

css-zero

An opinionated CSS starter kit for your "nobuild" application
CSS
61
star
9

sass-zero

A CSS framework for custom UI development. (Ruby on Rails)
SCSS
39
star
10

react-native-turbo

React Native framework for making Turbo native apps
Objective-C
28
star
11

strada-rails

Use Strada in your Ruby on Rails app
Ruby
28
star
12

rinha_de_backend

Ruby
23
star
13

css-properties-counter

The 35 CSS properties you must know to do 80% of the work.
CSS
19
star
14

active-persistence

Active Persistence is a implementation of Active Record Query Interface for JPA that makes it easy and fun.
Java
16
star
15

stimulus-web-authn

JavaScript
13
star
16

corona-prophet

Profeta do corona - Using facebook prophet to predict corona vírus
Ruby
11
star
17

jsf-perfect-crud

A modern and sofisticated start template for JSF/JAVAEE
Java
10
star
18

documentation-zero

A rest api documentation generator for rails applications using markdown
Ruby
9
star
19

prime-rails

prime-rails
CSS
7
star
20

react-native-turbo-poc

Objective-C
5
star
21

react-native-form-sheet

Native dialog solution for React Native
Objective-C
2
star
22

prime-rails-showcase

Prime-Rails Showcase
JavaScript
1
star
23

primefaces-mobile

JavaScript
1
star
24

all-hallows-eve-theme

Atom All Hallows Eve Theme
CSS
1
star
25

ksroute-csv

Integração do Ksroute por arquivos csv
Java
1
star
26

lazaronixon-web-programming-exercise

Ruby
1
star
27

rinha-de-backend-2

Ruby
1
star