Skip to content

Commit 990e5a8

Browse files
committed
"Fix" example (it's still not working in expo, but at least reason part is building)
Closes #340
1 parent 84b60cf commit 990e5a8

8 files changed

Lines changed: 124 additions & 101 deletions

File tree

‎example/.gitignore‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
node_modules/**/*
22
.expo/*
33
npm-debug.*
4-
lib
4+
lib/bs
55
.bsb.lock
66
.merlin
7+
*.bs.js

‎example/App.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { reactClass as default } from './lib/js/src/RNTesterApp.js';
1+
export { reactComponentForJs as default } from "./src/RNTesterApp.bs.js";

‎example/bsconfig.json‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
"react-jsx": 2
55
},
66
"refmt": 3,
7-
"bs-dependencies": [
8-
"reason-react",
9-
"../../bs-react-native"
10-
],
7+
"package-specs": {
8+
"module": "es6",
9+
"in-source": true
10+
},
11+
"suffix": ".bs.js",
1112
"sources": [
1213
{
1314
"dir": "src",
1415
"subdirs": true
1516
}
16-
]
17+
],
18+
"bs-dependencies": ["reason-react", "../../bs-react-native"]
1719
}

‎example/package.json‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
{
2-
"name": "empty-project-template",
3-
"main": "node_modules/expo/AppEntry.js",
42
"private": true,
3+
"name": "bs-react-native-example",
4+
"main": "node_modules/expo/AppEntry.js",
55
"scripts": {
6+
"re:watch": "bsb -clean-world -make-world -w",
7+
"re:build": "bsb -clean-world -make-world",
68
"start": "expo start",
79
"android": "expo start --android",
810
"ios": "expo start --ios",
9-
"eject": "expo eject",
10-
"watch": "../node_modules/.bin/bsb -make-world -w",
11-
"clean-build": "../node_modules/.bin/bsb -clean-world -make-world"
11+
"eject": "expo eject"
1212
},
1313
"dependencies": {
14+
"bs-platform": "^4.0.18",
1415
"expo": "^30.0.1",
1516
"react": "16.3.1",
16-
"react-native": "https://github.com/expo/react-native/archive/sdk-30.0.0.tar.gz"
17+
"react-native": "https://github.com/expo/react-native/archive/sdk-30.0.0.tar.gz",
18+
"reason-react": "^0.6.0"
1719
}
1820
}

‎example/src/RNTesterApp.re‎

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,13 @@ let header = (~onBack=?, ~title, ()) =>
4444
<View style=styles##headerCenter>
4545
<Text style=styles##title> {ReasonReact.string(title)} </Text>
4646
</View>
47-
{
48-
switch (onBack) {
49-
| None => ReasonReact.null
50-
| Some(onBack) =>
51-
<View style=styles##headerLeft>
52-
<Button title="Back" onPress=onBack />
53-
</View>
54-
}
55-
}
47+
{switch (onBack) {
48+
| None => ReasonReact.null
49+
| Some(onBack) =>
50+
<View style=styles##headerLeft>
51+
<Button title="Back" onPress=onBack />
52+
</View>
53+
}}
5654
</View>;
5755

5856
type action =
@@ -89,40 +87,35 @@ let make = _children => {
8987
render: ({state, send}) => {
9088
let components = ExampleList.components;
9189
<SafeAreaView style=styles##appContainer>
92-
{
93-
switch (state.currentExample) {
94-
| None =>
95-
<View style=styles##exampleContainer>
96-
{header(~title="ReasonRNTester", ())}
97-
<RNTesterExampleList
98-
components
99-
onPress=(
100-
item =>
101-
switch (state.currentExample) {
102-
| None => send(ChangeCurrentExample(Some(item)))
103-
| Some(_) => send(ChangeCurrentExample(None))
104-
}
105-
)
106-
/>
107-
</View>
108-
| Some(example) when example.exampleType === FullScreen =>
109-
example.examples[0].render()
110-
| Some(example) =>
111-
<View style=styles##exampleContainer>
112-
{
113-
header(
114-
~title=example.title,
115-
~onBack=_event => send(ChangeCurrentExample(None)),
116-
(),
117-
)
118-
}
119-
<RNTesterExampleContainer example />
120-
</View>
121-
}
122-
}
90+
{switch (state.currentExample) {
91+
| None =>
92+
<View style=styles##exampleContainer>
93+
{header(~title="ReasonRNTester", ())}
94+
<RNTesterExampleList
95+
components
96+
onPress={item =>
97+
switch (state.currentExample) {
98+
| None => send(ChangeCurrentExample(Some(item)))
99+
| Some(_) => send(ChangeCurrentExample(None))
100+
}
101+
}
102+
/>
103+
</View>
104+
| Some(example) when example.exampleType === FullScreen =>
105+
example.examples[0].render()
106+
| Some(example) =>
107+
<View style=styles##exampleContainer>
108+
{header(
109+
~title=example.title,
110+
~onBack=_event => send(ChangeCurrentExample(None)),
111+
(),
112+
)}
113+
<RNTesterExampleContainer example />
114+
</View>
115+
}}
123116
</SafeAreaView>;
124117
},
125118
};
126119

127-
let reactClass =
120+
let reactComponentForJs =
128121
ReasonReact.wrapReasonForJs(~component, _jsProps => make([||]));

‎example/src/pages/GeolocationExample.re‎

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,14 @@ module GeolocationGetCurrentPositionExample = {
4242
<Text> {ReasonReact.string("Get current position")} </Text>
4343
</TouchableOpacity>
4444
<Text>
45-
{
46-
ReasonReact.string(
47-
"latitude:" ++ string_of_float(state.coords.latitude),
48-
)
49-
}
45+
{ReasonReact.string(
46+
"latitude:" ++ string_of_float(state.coords.latitude),
47+
)}
5048
</Text>
5149
<Text>
52-
{
53-
ReasonReact.string(
54-
"longitude:" ++ string_of_float(state.coords.longitude),
55-
)
56-
}
50+
{ReasonReact.string(
51+
"longitude:" ++ string_of_float(state.coords.longitude),
52+
)}
5753
</Text>
5854
</View>
5955
</View>
@@ -83,39 +79,33 @@ module GeolocationWatchPositionExample = {
8379
switch (action) {
8480
| UpdateCoords(coords) => Update({coords: coords})
8581
},
86-
subscriptions: ({send}) => [
87-
Sub(
88-
() =>
89-
Geolocation.watchPosition(
90-
position =>
91-
send(
92-
UpdateCoords({
93-
latitude: position##coords##latitude,
94-
longitude: position##coords##longitude,
95-
}),
96-
),
97-
error => Js.log(error),
98-
),
99-
Geolocation.clearWatch,
100-
),
101-
],
82+
didMount: self => {
83+
let watchId =
84+
Geolocation.watchPosition(
85+
position =>
86+
self.send(
87+
UpdateCoords({
88+
latitude: position##coords##latitude,
89+
longitude: position##coords##longitude,
90+
}),
91+
),
92+
error => Js.log(error),
93+
);
94+
self.onUnmount(() => Geolocation.clearWatch(watchId));
95+
},
10296
render: ({state}) =>
10397
Style.(
10498
<View>
10599
<View style={style([padding(Pt(10.))])}>
106100
<Text>
107-
{
108-
ReasonReact.string(
109-
"latitude:" ++ string_of_float(state.coords.latitude),
110-
)
111-
}
101+
{ReasonReact.string(
102+
"latitude:" ++ string_of_float(state.coords.latitude),
103+
)}
112104
</Text>
113105
<Text>
114-
{
115-
ReasonReact.string(
116-
"longitude:" ++ string_of_float(state.coords.longitude),
117-
)
118-
}
106+
{ReasonReact.string(
107+
"longitude:" ++ string_of_float(state.coords.longitude),
108+
)}
119109
</Text>
120110
</View>
121111
</View>

‎example/src/pages/NetInfoExample.re‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,11 @@ module NetInfoIsConnectedExample = {
1313
switch (action) {
1414
| UpdateIsConnected(isConnected) => Update({isConnected: isConnected})
1515
},
16-
subscriptions: self => [
17-
Sub(
18-
() => {
19-
let handleConnectionChange = isConnected =>
20-
self.send(UpdateIsConnected(isConnected));
21-
NetInfo.IsConnected.addEventListener(handleConnectionChange);
22-
handleConnectionChange;
23-
},
24-
listener => NetInfo.IsConnected.removeEventListener(listener),
25-
),
26-
],
16+
didMount: (self) => {
17+
let handleConnectionChange = isConnected => self.send(UpdateIsConnected(isConnected));
18+
NetInfo.IsConnected.addEventListener(handleConnectionChange);
19+
self.onUnmount(() => NetInfo.IsConnected.removeEventListener(handleConnectionChange));
20+
},
2721
render: ({state}) =>
2822
Style.(
2923
<View>

‎example/yarn.lock‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,6 +1353,11 @@ braces@^2.3.1:
13531353
split-string "^3.0.2"
13541354
to-regex "^3.0.1"
13551355

1356+
bs-platform@^4.0.18:
1357+
version "4.0.18"
1358+
resolved "https://registry.yarnpkg.com/bs-platform/-/bs-platform-4.0.18.tgz#d17b8693ba1f714d9b27e0ddb365f2069ba4b8a0"
1359+
integrity sha512-BwzW0iYHvREqUZIgQxJmdJrxexppLvJxYQ4LLexbhCp7uZU5DIZ5ub4ZHpkCkc8fn8bsXWc+Rrejb3csi+BoAQ==
1360+
13561361
bser@^2.0.0:
13571362
version "2.0.0"
13581363
resolved "https://registry.yarnpkg.com/bser/-/bser-2.0.0.tgz#9ac78d3ed5d915804fd87acb158bc797147a1719"
@@ -3641,6 +3646,16 @@ react-devtools-core@3.1.0:
36413646
shell-quote "^1.6.1"
36423647
ws "^2.0.3"
36433648

3649+
"react-dom@>=15.0.0 || >=16.0.0":
3650+
version "16.8.4"
3651+
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.8.4.tgz#1061a8e01a2b3b0c8160037441c3bf00a0e3bc48"
3652+
integrity sha512-Ob2wK7XG2tUDt7ps7LtLzGYYB6DXMCLj0G5fO6WeEICtT4/HdpOi7W/xLzZnR6RCG1tYza60nMdqtxzA8FaPJQ==
3653+
dependencies:
3654+
loose-envify "^1.1.0"
3655+
object-assign "^4.1.1"
3656+
prop-types "^15.6.2"
3657+
scheduler "^0.13.4"
3658+
36443659
react-native-branch@2.2.5:
36453660
version "2.2.5"
36463661
resolved "https://registry.yarnpkg.com/react-native-branch/-/react-native-branch-2.2.5.tgz#4074dd63b4973e6397d9ce50e97b57c77a518e9d"
@@ -3780,6 +3795,16 @@ react@16.3.1:
37803795
object-assign "^4.1.1"
37813796
prop-types "^15.6.0"
37823797

3798+
"react@>=15.0.0 || >=16.0.0":
3799+
version "16.8.4"
3800+
resolved "https://registry.yarnpkg.com/react/-/react-16.8.4.tgz#fdf7bd9ae53f03a9c4cd1a371432c206be1c4768"
3801+
integrity sha512-0GQ6gFXfUH7aZcjGVymlPOASTuSjlQL4ZtVC5YKH+3JL6bBLCVO21DknzmaPlI90LN253ojj02nsapy+j7wIjg==
3802+
dependencies:
3803+
loose-envify "^1.1.0"
3804+
object-assign "^4.1.1"
3805+
prop-types "^15.6.2"
3806+
scheduler "^0.13.4"
3807+
37833808
read-pkg-up@^2.0.0:
37843809
version "2.0.0"
37853810
resolved "https://registry.yarnpkg.com/read-pkg-up/-/read-pkg-up-2.0.0.tgz#6b72a8048984e0c41e79510fd5e9fa99b3b549be"
@@ -3807,6 +3832,14 @@ readable-stream@^2.0.1, readable-stream@^2.0.6, readable-stream@^2.1.5, readable
38073832
string_decoder "~1.1.1"
38083833
util-deprecate "~1.0.1"
38093834

3835+
reason-react@^0.6.0:
3836+
version "0.6.0"
3837+
resolved "https://registry.yarnpkg.com/reason-react/-/reason-react-0.6.0.tgz#e9a7d6a10958161c3a12ef7fec1b6662edaae94a"
3838+
integrity sha512-FKzBDXE96KPyUbeRo2ToqUe9rl4IKgwegtjCXvyx0bzJXCKLqwiiN3OiOTH/siJS+/IZRZhBAHnd/R3VkRMsMQ==
3839+
dependencies:
3840+
react ">=15.0.0 || >=16.0.0"
3841+
react-dom ">=15.0.0 || >=16.0.0"
3842+
38103843
regenerate@^1.2.1:
38113844
version "1.4.0"
38123845
resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.4.0.tgz#4a856ec4b56e4077c557589cae85e7a4c8869a11"
@@ -3978,6 +4011,14 @@ sax@~1.1.1:
39784011
version "1.1.6"
39794012
resolved "http://registry.npmjs.org/sax/-/sax-1.1.6.tgz#5d616be8a5e607d54e114afae55b7eaf2fcc3240"
39804013

4014+
scheduler@^0.13.4:
4015+
version "0.13.4"
4016+
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.13.4.tgz#8fef05e7a3580c76c0364d2df5e550e4c9140298"
4017+
integrity sha512-cvSOlRPxOHs5dAhP9yiS/6IDmVAVxmk33f0CtTJRkmUWcb1Us+t7b1wqdzoC0REw2muC9V5f1L/w5R5uKGaepA==
4018+
dependencies:
4019+
loose-envify "^1.1.0"
4020+
object-assign "^4.1.1"
4021+
39814022
"semver@2 || 3 || 4 || 5", semver@5.x, semver@^5.0.1, semver@^5.0.3, semver@^5.1.0, semver@^5.3.0, semver@^5.4.1:
39824023
version "5.5.1"
39834024
resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.1.tgz#7dfdd8814bdb7cabc7be0fb1d734cfb66c940477"

0 commit comments

Comments
 (0)