Giter VIP home page Giter VIP logo

bs-react-native's Introduction

Getting started

Great that you want to use Reason with React Native! To get everything running are just a couple of steps. Let's assume that you already have a React Native project. Otherwise follow the React Native instructions until you have your app running.

  1. Install Bucklescript (the Reason -> JS compiler), Reason-React and bs-react-native:
# substitute yarn with npm if you prefer
yarn add bs-platform reason-react https://github.com/BuckleTypes/bs-react-native.git
  1. Create a re folder (there will be your Reason code)
  2. Create a bsconfig.json with the following content file in your project root
{
    "name": "my-awesome-app",
    "reason": {
        "react-jsx": 2
    },
    "bs-dependencies": ["bs-react-native", "reason-react"],
    "sources": [{
        "dir": "re"
    }]
}
  1. You are nearly done, the last configuration before we get to the fun stuff. In your package.json add to the "scripts" section two scripts:
"scripts": {
  ...
  "build": "bsb -make-world -clean-world",
  "watch": "bsb -make-world -clean-world -w"
}
  1. Now you can build all your (so far nonexsisting) Reason in two modes:
  • yarn run build performs a single build
  • yarn run watch enters the watch mode
  1. Now we come to the fun stuff! Create a new file re/app.re and make it look like this:
open ReactNative;

let app () => 
  <View style=Style.(style [flex 1., justifyContent `center, alignItems `center])>
    <Text value="Reason is awesome!" />
  </View>;

and start the watcher with yarn run watch if you haven't done it yet.

  1. We are nearly done! We now have to adopt the index.ios.js / index.android.js to look like this
import { app } from "./lib/js/re/app.js";
import React from "react";
import {
  AppRegistry
} from 'react-native';

AppRegistry.registerComponent('MyAwesomeProject', () => app);

Note: Make sure that the first argument to AppRegistry.registerComponent is your correct project name.

  1. Now go to a new tab and start your app with react-native run-ios or react-native run-android.

  2. Great you are all set up! Check the source of bs-react-native to find out more about the implemented APIs and Components. If you get stuck just ask on our Discord Server! Happy Hacking!

Here are some more things which will be proabbyl useful for you:

Disclaimer

This is work in progress. There are many missing APIs and the existing ones are not guaranteed to work. Contributions of Components and APIs are very welcome!

The bindings are targeted to React Native 0.44+.

Style

Since we have a proper type system we can make styles typesafe! Therefore styles are a little bit different declared than in JavaScript:

open ReactNative;

/* inline styles */
<View
  style=(
          Style.style [
            Style.flexDirection `column,
            Style.backgroundColor "#6698FF",
            Style.marginTop 5
          ]
        )
/>;

/* inline styles with a local open */
<View style=Style.(style [flexDirection `column, backgroundColor "#6698FF", marginTop 5]) />;

/* StyleSheets with a local open */
let styles =
  StyleSheet.create
    Style.({"wrapper": style [flexDirection `column, backgroundColor "#6698FF", marginTop 5]});

<View style=styles##wrapper />;

Status

You can find an overview of the implemented components and APIs here

bs-react-native's People

Contributors

chenglou avatar cullophid avatar saschatimme avatar wokalski avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.