Skip to content

Commit a40458c

Browse files
committed
website: more getting started docs
1 parent 2b5f79c commit a40458c

6 files changed

Lines changed: 183 additions & 8 deletions

File tree

‎website/docs/cheatsheet.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ title: Cheatsheet
1515

1616
- [Getting Started](/reason-react-native/en/docs/)
1717
- [Installation](/reason-react-native/en/docs/install/)
18+
- [Usage](/reason-react-native/en/docs/usage/)
1819
- [Example](/reason-react-native/en/docs/example/)

‎website/docs/example.md‎

Lines changed: 120 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,125 @@ id: example
33
title: Example
44
---
55

6-
@todo
6+
As soon as you
7+
[installed Reason React Native](/reason-react-native/en/docs/install/) properly
8+
and have you `./package.json` and `./bsconfig.json` ready, you can create two
9+
files:
10+
11+
- [`./App.js`](#appjs): a proxy for React Native to reference Reason compiled
12+
app component
13+
- [`./src/App.re`](#srcappre): the actual React Native entry point, using Reason
14+
15+
_If you used our template as explained in th installation guide, you should
16+
already have theses files._
17+
18+
No worries, you can copy paste this if needed without understanding the content
19+
for now. Documentation will explain everything 😇.
20+
21+
## `./App.js`
22+
23+
This can be you only JavaScript file if you want to be full ReasonML! It's just
24+
a proxy to `App.re` application wrapper.
25+
26+
```javascript
27+
/**
28+
* Do not modify this file - it is a proxy to your `App.re` file
29+
* located in the `src/` folder.
30+
*/
31+
export { app as default } from "./src/App.bs.js";
32+
```
33+
34+
## `./src/App.re`
35+
36+
```reason
37+
open ReactNative;
38+
39+
/*
40+
Here is StyleSheet that is using Style module to define styles for your components
41+
The main different with JavaScript components you may encounter in React Native
42+
is the fact that they **must** be defined before being referenced
43+
(so before actual component definitions)
44+
More at https://reasonml-community.github.io/reason-react-native/en/docs/apis/Style/
45+
*/
46+
let styles =
47+
Style.(
48+
StyleSheet.create({
49+
"container":
50+
style(
51+
~flex=1.,
52+
~justifyContent=`center,
53+
~alignItems=`center,
54+
~backgroundColor="#F5FCFF",
55+
(),
56+
),
57+
"welcome":
58+
style(~fontSize=20., ~textAlign=`center, ~margin=10.->dp, ()),
59+
"instructions":
60+
style(~textAlign=`center, ~color="#333333", ~marginBottom=5.->dp, ()),
61+
})
62+
);
63+
64+
[@react.component]
65+
let app = () =>
66+
<View style=styles##container>
67+
<Text style=styles##welcome>
68+
"Welcome to (Reason) React Native!"->React.string
69+
</Text>
70+
<Text style=styles##instructions>
71+
"To get started, edit src/App.re"->React.string
72+
</Text>
73+
<Text style=styles##instructions>
74+
{switch (Platform.os) {
75+
/*
76+
Instructions depends on the platform this code will run on
77+
More at https://reasonml-community.github.io/reason-react-native/en/docs/apis/Platform/
78+
*/
79+
| os when os == Platform.ios =>
80+
"Press Cmd+R to reload,\n" ++ "Cmd+D or shake for dev menu"
81+
| os when os == Platform.android =>
82+
"Double tap R on your keyboard to reload,\n"
83+
++ "Shake or press menu button for dev menu"
84+
| os when os == Platform.web => "Press Cmd+R to reload."
85+
| _ => ""
86+
}}
87+
->React.string
88+
</Text>
89+
</View>;
90+
```
91+
92+
### Differences with React Native JavaScript
93+
94+
Beside Reason syntax that is a bit different with JavaScript, you may have
95+
noticed this major differences:
96+
97+
- Modules are not imported, but opened instead (without reference to the
98+
filesystem file) and this is due to
99+
[how modules work in ReasonML](https://reasonml.github.io/docs/en/module)
100+
(**filename must be unique**),
101+
- Component definition must be preceded with `[@react.component]`,
102+
- `const` is not a thing in Reason, & `let` is the default as ReasonML have a
103+
specific way to allow mutable variables,
104+
- String in JSX must be quoted and explicitely referenced as `React.string` (you
105+
will find similar specific `React.*` to specify null value (`React.null`),
106+
children from an array `React.array`...)
107+
- References to `styles` keys aren't using dot notation like in JavaScript but
108+
`##` instead thanks to BuckleScript syntax sugar for
109+
[direct JavaScript object access](https://bucklescript.github.io/docs/en/object-2#accessors)
110+
- You won't see any explicit `export` like in JavaScript. By default every
111+
variables defined in a ReasonML module is exposed.
112+
113+
## Start this example
114+
115+
Now let's run this example.
116+
117+
In comparison with standard React Native development, the only thing you need to
118+
be sure that you have successfully compiled `App.re` as `App.bs.js` like we
119+
explained in the [usage](/reason-react-native/en/docs/usage/) section.
120+
121+
As soon as ReasonML compilation is successful, nothing should change for your
122+
development process. You can normally start your React Native app via
123+
`react-native run-ios`, `react-native run-android` or your classic web workflow
124+
if you use `react-native-web`!
7125

8126
---
9127

@@ -15,3 +133,4 @@ title: Example
15133

16134
- [Getting Started](/reason-react-native/en/docs/)
17135
- [Install](/reason-react-native/en/docs/install/)
136+
- [Usage](/reason-react-native/en/docs/usage/)

‎website/docs/index.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ Reason-to-JavaScript compiler.
6666
## Further reading
6767

6868
- [Installation](/reason-react-native/en/docs/install/)
69+
- [Usage](/reason-react-native/en/docs/usage/)
6970
- [Example](/reason-react-native/en/docs/example/)
7071
- [Cheatsheet](/reason-react-native/en/docs/cheatsheet/)
7172
- [Migration from `bs-react-native`](/reason-react-native/en/docs/migration/jsx3/)

‎website/docs/install.md‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,18 @@ Expo, feel free to open
4343
[an issue](https://github.com/reasonml-community/reason-react-native/issues/new?title=Expo+template)
4444
so we can discuss about that_.
4545

46+
_If you are an Expo user, just have a look at the instructions below when your
47+
Expo app is ready_.
48+
4649
## Add _Reason React Native_ to an existing project
4750

4851
If you already have an existing project, it's really fast to get all the thing
4952
you need to start using Reason React Native right away!
5053

51-
Got into your project root & then install the requirements
54+
👉 **You can decide to use Reason React Native for certain components only** as
55+
the compilation process generate normal JavaScript.
56+
57+
Go into your project root & then install the requirements:
5258

5359
```console
5460
yarn add bs-platform --dev
@@ -80,14 +86,20 @@ Then create a file named `bsconfig.json` at the same level at your
8086
}
8187
```
8288

83-
👀 _For details about this file, please refer to
84-
[BuckleScript Configuration documentation](https://bucklescript.github.io/docs/en/build-configuration)._
85-
86-
When it's done, you are ready to use Reason React Native !
89+
The main things you should notice here:
8790

88-
---
91+
- JavaScript generated will be using `import` & `export` (_es6_).
92+
- JavaScript generated files will have `.bs.js` extension (easy to find)
93+
- ReasonML code will be compiled from `src` folder.
94+
- ReasonML will use `reason-react` & `reason-react-native` packages as
95+
dependencies.
8996

97+
👀 _For details about this file, please refer to
98+
[BuckleScript Configuration documentation](https://bucklescript.github.io/docs/en/build-configuration)
99+
if needed._
90100

101+
When it's done, you are ready to
102+
[use Reason React Native](/reason-react-native/en/docs/usage/) !
91103

92104
---
93105

@@ -104,14 +116,14 @@ bindings. This means last digit
104116
- `react-native@0.60.8` should work with `reason-react-native@0.60.0`
105117
- `react-native@0.60.2` should work with `reason-react-native@0.60.4`
106118

107-
👉 At this step, you should check our in-depth
108119
👉 **`reason-react-native` `0.x.*` means it should work with
109120
`react-native@^0.x.*`**.
110121

111122
---
112123

113124
## Further reading
114125

126+
- [Usage](/reason-react-native/en/docs/usage/)
115127
- [Example](/reason-react-native/en/docs/example/)
116128
- [Cheatsheet](/reason-react-native/en/docs/cheatsheet/)
117129

‎website/docs/usage.md‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
id: usage
3+
title: Usage
4+
---
5+
6+
## Using Reason React Native
7+
8+
@todo move here
9+
[what's in the template readme](https://github.com/reasonml-community/reason-react-native/tree/master/react-native-template-reason#readme)
10+
11+
### Using JavaScript components from Reason
12+
13+
@todo check out
14+
[Reason React interop page](https://reasonml.github.io/reason-react/docs/en/components#interop).
15+
16+
You can also browse the source of
17+
[reason-react-native](https://github.com/reasonml-community/reason-react-native/tree/master/reason-react-native/src)
18+
because that's exactly what this project is doing!
19+
20+
### Using Reason React Native components from JavaScript
21+
22+
@todo Meanwhile, check out
23+
[Reason React interop page](https://reasonml.github.io/reason-react/docs/en/components#interop)
24+
25+
---
26+
27+
👉 At this step, you should check our in-depth
28+
[Example](/reason-react-native/en/docs/example/) or go directly check our
29+
[Cheatsheet](/reason-react-native/en/docs/cheatsheet/)
30+
31+
---
32+
33+
## Further reading
34+
35+
- [Example](/reason-react-native/en/docs/example/)
36+
- [Cheatsheet](/reason-react-native/en/docs/cheatsheet/)
37+
38+
## In case you missed it
39+
40+
- [Getting Started](/reason-react-native/en/docs/)
41+
- [Install](/reason-react-native/en/docs/install/)

‎website/src/Consts.re‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ let sections = [
8080
data: [
8181
("Introduction", "docs/"),
8282
("Installation", "docs/install/"),
83+
("Usage", "docs/usage/"),
8384
("Example", "docs/example/"),
8485
("Cheatsheet", "docs/cheatsheet/"),
8586
("Migration from bs-react-native", "docs/migration/jsx3/"),

0 commit comments

Comments
 (0)