Skip to content

Commit 84b60cf

Browse files
committed
Update react-native-template-reason so it looks like default RN hello world
1 parent 3abe32c commit 84b60cf

10 files changed

Lines changed: 151 additions & 51 deletions

File tree

‎generator/README.md‎

Lines changed: 0 additions & 31 deletions
This file was deleted.

‎generator/dependencies.json‎

Lines changed: 0 additions & 5 deletions
This file was deleted.

‎generator/src/App.re‎

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
* Do not modify this file - it is a proxy to your `App.re` file
33
* located in the `src/` folder.
44
*/
5-
export { app as default } from "./lib/js/src/App.js";
5+
export { app as default } from "./src/App.bs.js";
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# React Native HelloWorld
2+
3+
> This is a React Native application developed in Reason.
4+
5+
Please carefully read instructions below in order to enjoy
6+
ReasonML development experience.
7+
8+
## Setup
9+
10+
### IDE
11+
12+
To get the best development experience possible, we recommend you to use [VSCode](https://code.visualstudio.com) with [Reason Language Server](https://marketplace.visualstudio.com/items?itemName=jaredly.reason-vscode) extension & optionally [Flow Language Server](https://marketplace.visualstudio.com/items?itemName=flowtype.flow-for-vscode) extension if you have JavaScript covered by Flow.
13+
14+
If you won't want to use VSCode, at least [get a ReasonML editor plugin](https://reasonml.github.io/docs/en/editor-plugins/).
15+
16+
### `package.json`
17+
18+
To get started, add the following scripts to your `package.json`:
19+
20+
```json
21+
"scripts": {
22+
"re:watch": "bsb -clean-world -make-world -w",
23+
"re:build": "bsb -clean-world -make-world",
24+
"start": "node node_modules/react-native/local-cli/cli.js start",
25+
"start:ios": "react-native run-ios",
26+
"start:android": "react-native run-android",
27+
}
28+
```
29+
30+
Note: you probably have `start` already.
31+
32+
### Development workflow
33+
34+
_Note: `yarn` can be replaced by `npm run` in all commands below._
35+
36+
Depending on your editor & [its ReasonML integration](https://reasonml.github.io/docs/en/editor-plugins/) you might need to use:
37+
38+
```console
39+
yarn re:watch
40+
```
41+
42+
**Reminder: this step might be unecessary if your editor can handle ReasonML compilation by its own.**
43+
[Read more](https://github.com/jaredly/reason-language-server#installation).
44+
45+
As soon as `.re` files are being compiled to `.bs.js`, you can either start the project on _iOS Simulator_ (included in _Xcode_) or an Android Emulator (if you are unfamiliar with _Android Studio_, you might be interested by [Genymotion](https://www.genymotion.com)).
46+
47+
```console
48+
yarn start:ios
49+
```
50+
51+
or
52+
53+
```console
54+
yarn start:android
55+
```
56+
57+
This commands should open up a virtual device & start React Native [metro bundler](https://github.com/facebook/metro). This packager will serves the compiled Reason code to the React Native client.
58+
59+
Now you can start coding by editing files in `src/`!
60+
61+
[Read more about starting the project in your environment of choice](http://facebook.github.io/react-native/docs/getting-started).
62+
63+
**Note: as soon as you have the app installed in a simulator/emulator, you could just run**
64+
65+
```console
66+
yarn start
67+
```
68+
69+
This avoid rebuilding the entire native parts & will just start React Native metro bundler.
70+
71+
## Breakdown of existing files
72+
73+
The `react-native init` command generates a lot of boilerplate with files that might be not needed for your particular use case. Below is a breakdown of all top-level files to help you decide:
74+
75+
- `.babelrc` - required, for transpiling Javascript files to supported by the mobile engine Javascript version
76+
- `.buckconfig` - optional, configuration files for `Buck`. Can be safely removed in most cases unless you are planning on using it
77+
- `.flowconfig` - optional, used to configure `Flow`, which is a type checker for Javascript. Can be removed as you are writing our code in Reason
78+
- `.watchmanconfig` - optional, configuration for `Watchman`, which is a Facebook tool for listening to file system changes. This file is not needed, unless you plan on extending its configuration
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,5 @@ buck-out/
5858
# Bucklescript artifacts
5959
.merlin
6060
.bsb.lock
61-
/lib/bs/
62-
/lib/js/
61+
lib/bs
62+
*.bs.js
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
{
22
"name": "my-reason-react-native-app",
3+
"refmt": 3,
34
"reason": {
45
"react-jsx": 2
56
},
67
"package-specs": {
7-
"module": "commonjs"
8+
"module": "es6",
9+
"in-source": true
810
},
9-
"bsc-flags": ["-bs-super-errors"],
10-
"bs-dependencies": ["bs-react-native", "reason-react"],
11+
"suffix": ".bs.js",
1112
"sources": [
1213
{
1314
"dir": "src",
1415
"subdirs": true
1516
}
1617
],
17-
"suffix": ".js",
18-
"refmt": 3
18+
"bsc-flags": ["-bs-super-errors"],
19+
"bs-dependencies": ["bs-react-native", "reason-react"]
1920
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"bs-platform": "^4.0.0",
3+
"reason-react": "^0.6.0",
4+
"bs-react-native": "^0.10.0"
5+
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"name": "react-native-template-reason",
3-
"version": "1.0.0"
3+
"version": "0.0.8"
44
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* Sample React Native App
3+
* https://github.com/facebook/react-native
4+
*
5+
* Converted from https://github.com/facebook/react-native/blob/d752446b23e0a12171ca0c01d20f5be625f40455/template/App.js
6+
*/
7+
open BsReactNative;
8+
9+
let instructions =
10+
switch (Platform.os()) {
11+
| IOS(_) => "Press Cmd+R to reload,\n" ++ "Cmd+D or shake for dev menu"
12+
| Android =>
13+
"Double tap R on your keyboard to reload,\n"
14+
++ "Shake or press menu button for dev menu"
15+
| exception (Platform.UnknownPlatform(p)) when p == "web" => "Press Cmd+R to reload."
16+
| exception (Platform.UnknownPlatform(_p)) => ""
17+
};
18+
19+
let styles =
20+
Style.(
21+
StyleSheet.create({
22+
"container":
23+
style([
24+
flex(1.),
25+
justifyContent(Center),
26+
alignItems(Center),
27+
backgroundColor(String("#F5FCFF")),
28+
]),
29+
"welcome":
30+
style([
31+
fontSize(Float(20.)),
32+
textAlign(Center),
33+
margin(Pt(10.)),
34+
]),
35+
"instructions":
36+
style([
37+
textAlign(Center),
38+
color(String("#333333")),
39+
marginBottom(Pt(5.)),
40+
]),
41+
})
42+
);
43+
44+
let app = () =>
45+
<View
46+
style={
47+
styles##container;
48+
}>
49+
<Text style={styles##welcome}>
50+
"Welcome to (Bs) React Native!"->ReasonReact.string
51+
</Text>
52+
<Text style={styles##instructions}>
53+
"To get started, edit src/App.re"->ReasonReact.string
54+
</Text>
55+
<Text style={styles##instructions}>
56+
instructions->ReasonReact.string
57+
</Text>
58+
</View>;

0 commit comments

Comments
 (0)