2015-10-18 08:54:09 -07:00
2015-10-18 08:54:09 -07:00
2015-10-17 18:49:21 -07:00
2015-10-18 08:54:09 -07:00
2015-10-17 17:51:30 -07:00
2015-06-09 12:24:08 -07:00
2015-10-17 17:52:01 -07:00
2015-09-08 22:44:27 -07:00
2015-10-18 08:54:09 -07:00
2015-10-18 08:54:09 -07:00

React Native for Web

Build Status npm version

React Native components and APIs for the Web. ~17.7 KB minified and gzipped.

Table of contents

Install

npm install --save react react-dom react-native-web

Example

React Native for Web exports its components and a reference to the React installation. Styles are defined with, and used as JavaScript objects.

Component:

import React, { Image, StyleSheet, Text, View } from 'react-native-web'

const Title = ({ children }) => <Text style={styles.title}>{children}</Text>

const Summary = ({ children }) => (
  <View style={styles.text}>
    <Text style={styles.subtitle}>{children}</Text>
  </View>
)

class App extends React.Component {
  render() {
    return (
      <View style={styles.row}>
        <Image
          source={{ uri: 'http://facebook.github.io/react/img/logo_og.png' }}
          style={styles.image}
        />
        <Title>React Native Web</Title>
        <Summary>Build high quality web apps using React</Summary>
      </View>
    )
  },
})

const styles = StyleSheet.create({
  row: {
    flexDirection: 'row',
    margin: 40
  },
  image: {
    height: 40,
    marginRight: 10,
    width: 40,
  },
  text: {
    flex: 1,
    justifyContent: 'center'
  },
  title: {
    fontSize: '1.25rem',
    fontWeight: 'bold'
  },
  subtitle: {
    fontSize: '1rem'
  }
})

Pre-render styles on the server:

// server.js
import App from './components/App'
import React, { StyleSheet } from 'react-native-web'

const html = React.renderToString(<App />);
const css = StyleSheet.renderToString();

const Html = () => (
  <html>
    <head>
      <style id="react-stylesheet">{css}</style>
    </head>
    <body>
      <div id="react-root" dangerouslySetInnerHTML={{ __html: html }} />
    </body>
  </html>
)

Render styles on the client:

// client.js
import App from './components/App'
import React, { StyleSheet } from 'react-native-web'

React.render(
  <App />,
  document.getElementById('react-root')
)

document.getElementById('stylesheet').textContent = StyleSheet.renderToString()

APIs

StyleSheet

StyleSheet is a style abstraction that transforms inline styles to CSS on the client or the server. It provides a minimal CSS reset.

Components

Image

An accessibile image component with support for image resizing, default image, and child content.

ListView

(TODO)

ScrollView

(TODO)

Text

Displays text as an inline block and supports basic press handling.

TextInput

Accessible single- and multi-line text input via a keyboard.

Touchable

Touch bindings for press and long press.

View

The fundamental UI building block using flexbox for layout.

Styling

React Native for Web relies on styles being defined in JavaScript.

The View component makes it easy to build common layouts with flexbox, such as stacked and nested boxes with margin and padding. See this guide to flexbox.

Styling components can be achieved with inline styles or the use of StyleSheet.

Contributing

Please read the contribution guidelines. Contributions are welcome!

Thanks

Thanks to current and past members of the React and React Native teams (in particular Vjeux and Pete Hunt), and Tobias Koppers for Webpack and CSS loader.

Thanks to react-tappable for backing the current implementation of Touchable.

License

Copyright (c) 2015 Nicolas Gallagher. Released under the MIT license.

Description
No description provided
Readme MIT 24 MiB
Languages
JavaScript 99.7%
HTML 0.2%