Skip to content

Commit e8634d2

Browse files
committed
Update demo
1 parent 250f8b0 commit e8634d2

File tree

7 files changed

+190
-20
lines changed

7 files changed

+190
-20
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ const App = () => {
166166

167167
This repository includes demo app.
168168

169+
### React Native
170+
169171
Before running this app, please prepare environment for React Native (https://reactnative.dev/docs/environment-setup).
170172

171173
```sh
@@ -174,3 +176,12 @@ cd examples/DemoApp
174176
npm install
175177
npm run ios # or npm run android
176178
```
179+
180+
### Expo
181+
182+
```sh
183+
git clone [email protected]:inokawa/react-native-react-bridge.git
184+
cd examples/DemoAppExpo
185+
yarn
186+
expo start
187+
```

examples/DemoAppExpo/App.tsx

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,70 @@
1-
import React from 'react';
2-
import { StyleSheet, Text, View } from 'react-native';
1+
import React, { useState } from "react";
2+
import {
3+
SafeAreaView,
4+
StyleSheet,
5+
Text,
6+
View,
7+
TextInput,
8+
Pressable,
9+
} from "react-native";
10+
import WebView from "react-native-webview";
11+
import { useBridge } from "react-native-react-bridge";
12+
import webApp from "./WebApp";
313

414
export default function App() {
15+
const [data, setData] = useState("This is React Native");
16+
const { ref, source, onMessage, emit } = useBridge<string>(
17+
webApp,
18+
(message) => {
19+
if (message.type === "hi") {
20+
setData(message.data);
21+
}
22+
}
23+
);
24+
525
return (
6-
<View style={styles.container}>
7-
<Text>Open up App.tsx to start working on your app!</Text>
8-
</View>
26+
<SafeAreaView style={styles.container}>
27+
<View style={styles.top}>
28+
<WebView ref={ref} source={source} onMessage={onMessage} />
29+
</View>
30+
<View style={styles.bottom}>
31+
<TextInput
32+
style={styles.input}
33+
onChangeText={(text) => setData(text)}
34+
value={data}
35+
/>
36+
<Pressable
37+
onPress={() => emit({ type: "hello", data: data })}
38+
style={styles.button}
39+
>
40+
<Text>send to Web</Text>
41+
</Pressable>
42+
</View>
43+
</SafeAreaView>
944
);
1045
}
1146

1247
const styles = StyleSheet.create({
1348
container: {
1449
flex: 1,
15-
backgroundColor: '#fff',
16-
alignItems: 'center',
17-
justifyContent: 'center',
50+
},
51+
top: {
52+
flex: 1,
53+
borderWidth: 4,
54+
borderColor: "gray",
55+
},
56+
bottom: {
57+
padding: 4,
58+
flex: 1,
59+
},
60+
input: {
61+
height: 40,
62+
borderColor: "gray",
63+
borderWidth: 1,
64+
},
65+
button: {
66+
borderRadius: 10,
67+
padding: 8,
68+
backgroundColor: "lightgray",
1869
},
1970
});

examples/DemoAppExpo/WebApp.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React, { useState } from "react";
2+
import {
3+
webViewRender,
4+
emit,
5+
useSubscribe,
6+
} from "react-native-react-bridge/lib/web";
7+
import "./example.css";
8+
9+
const style = {
10+
width: "100vw",
11+
height: "100vh",
12+
margin: "auto",
13+
backgroundColor: "lightblue",
14+
};
15+
16+
const Root = () => {
17+
const [data, setData] = useState("This is Web");
18+
useSubscribe<string>((message) => {
19+
if (message.type === "hello") {
20+
setData(message.data);
21+
}
22+
});
23+
return (
24+
<div style={style}>
25+
<textarea value={data} onChange={(e) => setData(e.target.value)} />
26+
<div>
27+
<button onClick={() => emit({ type: "hi", data: data })}>
28+
send to React Native
29+
</button>
30+
</div>
31+
</div>
32+
);
33+
};
34+
35+
export default webViewRender(<Root />);

examples/DemoAppExpo/example.css

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
body {
2+
font-size: 1rem;
3+
}
4+
5+
textarea {
6+
padding: 10px;
7+
line-height: 1.5;
8+
border-radius: 5px;
9+
border: 1px solid #ccc;
10+
box-shadow: 1px 1px 1px #999;
11+
}
12+
13+
button {
14+
border: 0;
15+
line-height: 2.5;
16+
padding: 0 10px;
17+
text-align: center;
18+
color: #777;
19+
border-radius: 5px;
20+
background-color: white;
21+
border: 1px solid #777;
22+
cursor: pointer;
23+
}
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
// Learn more https://docs.expo.io/guides/customizing-metro
2-
const { getDefaultConfig } = require('expo/metro-config');
2+
const { getDefaultConfig } = require("expo/metro-config");
33

4-
module.exports = getDefaultConfig(__dirname);
4+
const config = getDefaultConfig(__dirname);
5+
6+
module.exports = {
7+
...config,
8+
transformer: {
9+
...config.transformer,
10+
babelTransformerPath: require.resolve(
11+
"react-native-react-bridge/lib/plugin"
12+
),
13+
},
14+
};

examples/DemoAppExpo/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@
99
},
1010
"dependencies": {
1111
"expo": "~41.0.1",
12-
"expo-updates": "~0.5.4",
1312
"expo-splash-screen": "~0.10.2",
13+
"expo-updates": "~0.5.4",
1414
"react": "16.13.1",
1515
"react-dom": "16.13.1",
1616
"react-native": "~0.63.4",
1717
"react-native-gesture-handler": "~1.10.2",
18+
"react-native-react-bridge": "^0.5.1",
1819
"react-native-reanimated": "~2.1.0",
1920
"react-native-screens": "~3.0.0",
2021
"react-native-unimodules": "~0.13.3",
21-
"react-native-web": "~0.13.12"
22+
"react-native-web": "~0.13.12",
23+
"react-native-webview": "^11.4.3"
2224
},
2325
"devDependencies": {
2426
"@babel/core": "^7.9.0",

examples/DemoAppExpo/yarn.lock

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,6 +2479,17 @@ babel-plugin-jest-hoist@^25.5.0:
24792479
"@babel/types" "^7.3.3"
24802480
"@types/babel__traverse" "^7.0.6"
24812481

2482+
2483+
version "4.1.0"
2484+
resolved "https://registry.yarnpkg.com/babel-plugin-module-resolver/-/babel-plugin-module-resolver-4.1.0.tgz#22a4f32f7441727ec1fbf4967b863e1e3e9f33e2"
2485+
integrity sha512-MlX10UDheRr3lb3P0WcaIdtCSRlxdQsB1sBqL7W0raF070bGl1HQQq5K3T2vf2XAYie+ww+5AKC/WrkjRO2knA==
2486+
dependencies:
2487+
find-babel-config "^1.2.0"
2488+
glob "^7.1.6"
2489+
pkg-up "^3.1.0"
2490+
reselect "^4.0.0"
2491+
resolve "^1.13.1"
2492+
24822493
babel-plugin-module-resolver@^3.2.0:
24832494
version "3.2.0"
24842495
resolved "https://registry.yarnpkg.com/babel-plugin-module-resolver/-/babel-plugin-module-resolver-3.2.0.tgz#ddfa5e301e3b9aa12d852a9979f18b37881ff5a7"
@@ -3500,16 +3511,16 @@ escape-html@~1.0.3:
35003511
resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988"
35013512
integrity sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=
35023513

3514+
[email protected], escape-string-regexp@^2.0.0:
3515+
version "2.0.0"
3516+
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz#a30304e99daa32e23b2fd20f51babd07cffca344"
3517+
integrity sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==
3518+
35033519
escape-string-regexp@^1.0.5:
35043520
version "1.0.5"
35053521
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
35063522
integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=
35073523

3508-
escape-string-regexp@^2.0.0:
3509-
version "2.0.0"
3510-
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz#a30304e99daa32e23b2fd20f51babd07cffca344"
3511-
integrity sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==
3512-
35133524
escodegen@^1.11.1:
35143525
version "1.14.3"
35153526
resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-1.14.3.tgz#4e7b81fba61581dc97582ed78cab7f0e8d63f503"
@@ -3938,7 +3949,7 @@ [email protected]:
39383949
statuses "~1.5.0"
39393950
unpipe "~1.0.0"
39403951

3941-
find-babel-config@^1.1.0:
3952+
find-babel-config@^1.1.0, find-babel-config@^1.2.0:
39423953
version "1.2.0"
39433954
resolved "https://registry.yarnpkg.com/find-babel-config/-/find-babel-config-1.2.0.tgz#a9b7b317eb5b9860cda9d54740a8c8337a2283a2"
39443955
integrity sha512-jB2CHJeqy6a820ssiqwrKMeyC6nNdmrcgkKWJWmpoxpE8RKciYJXCcXRq1h2AzCo5I5BJeN2tkGEO3hLTuePRA==
@@ -4399,7 +4410,7 @@ inquirer@^3.0.6:
43994410
strip-ansi "^4.0.0"
44004411
through "^2.3.6"
44014412

4402-
invariant@^2.2.2, invariant@^2.2.4:
4413+
invariant@2.2.4, invariant@^2.2.2, invariant@^2.2.4:
44034414
version "2.2.4"
44044415
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6"
44054416
integrity sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==
@@ -6549,6 +6560,13 @@ pkg-up@^2.0.0:
65496560
dependencies:
65506561
find-up "^2.1.0"
65516562

6563+
pkg-up@^3.1.0:
6564+
version "3.1.0"
6565+
resolved "https://registry.yarnpkg.com/pkg-up/-/pkg-up-3.1.0.tgz#100ec235cc150e4fd42519412596a28512a0def5"
6566+
integrity sha512-nDywThFk1i4BQK4twPQ6TA4RT8bDY96yeuCVBWL3ePARCiEKDRSrNGbFIgUJpLp+XeIR65v8ra7WuJOFUBtkMA==
6567+
dependencies:
6568+
find-up "^3.0.0"
6569+
65526570
plist@^3.0.1:
65536571
version "3.0.2"
65546572
resolved "https://registry.yarnpkg.com/plist/-/plist-3.0.2.tgz#74bbf011124b90421c22d15779cee60060ba95bc"
@@ -6742,6 +6760,13 @@ react-native-gesture-handler@~1.10.2:
67426760
invariant "^2.2.4"
67436761
prop-types "^15.7.2"
67446762

6763+
react-native-react-bridge@^0.5.1:
6764+
version "0.5.1"
6765+
resolved "https://registry.yarnpkg.com/react-native-react-bridge/-/react-native-react-bridge-0.5.1.tgz#2e02201df926a344162ab45a0936642800385f33"
6766+
integrity sha512-uhjku7fP11eFq2+WcakwELghSjJwUpqOhmWx9JgFtBLhX19eA9Ijk18sRa4MsVeqc9ZrxiUP5JTqOZgKWp1Ygw==
6767+
dependencies:
6768+
babel-plugin-module-resolver "4.1.0"
6769+
67456770
react-native-reanimated@~2.1.0:
67466771
version "2.1.0"
67476772
resolved "https://registry.yarnpkg.com/react-native-reanimated/-/react-native-reanimated-2.1.0.tgz#b9ad04aee490e1e030d0a6cdaa43a14895d9a54d"
@@ -6803,6 +6828,14 @@ react-native-web@~0.13.12:
68036828
prop-types "^15.6.0"
68046829
react-timer-mixin "^0.13.4"
68056830

6831+
react-native-webview@^11.4.3:
6832+
version "11.4.3"
6833+
resolved "https://registry.yarnpkg.com/react-native-webview/-/react-native-webview-11.4.3.tgz#7651370b604c8cc27701095e14e05cfefa8f5632"
6834+
integrity sha512-bC6r7vbukC1QYbG2vTmif8/gt6jzlGA7WK7zeVLt8ysZJvBNtoHtT2k7EoMgJIW6/6DTy1rrn6uZS4v2Fa4exQ==
6835+
dependencies:
6836+
escape-string-regexp "2.0.0"
6837+
invariant "2.2.4"
6838+
68066839
react-native@~0.63.4:
68076840
version "0.63.4"
68086841
resolved "https://registry.yarnpkg.com/react-native/-/react-native-0.63.4.tgz#2210fdd404c94a5fa6b423c6de86f8e48810ec36"
@@ -7048,6 +7081,11 @@ reselect@^3.0.1:
70487081
resolved "https://registry.yarnpkg.com/reselect/-/reselect-3.0.1.tgz#efdaa98ea7451324d092b2b2163a6a1d7a9a2147"
70497082
integrity sha1-79qpjqdFEyTQkrKyFjpqHXqaIUc=
70507083

7084+
reselect@^4.0.0:
7085+
version "4.0.0"
7086+
resolved "https://registry.yarnpkg.com/reselect/-/reselect-4.0.0.tgz#f2529830e5d3d0e021408b246a206ef4ea4437f7"
7087+
integrity sha512-qUgANli03jjAyGlnbYVAV5vvnOmJnODyABz51RdBN7M4WaVu8mecZWgyQNkG8Yqe3KRGRt0l4K4B3XVEULC4CA==
7088+
70517089
resolve-cwd@^3.0.0:
70527090
version "3.0.0"
70537091
resolved "https://registry.yarnpkg.com/resolve-cwd/-/resolve-cwd-3.0.0.tgz#0f0075f1bb2544766cf73ba6a6e2adfebcb13f2d"
@@ -7075,7 +7113,7 @@ [email protected]:
70757113
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b"
70767114
integrity sha1-IDEU2CrSxe2ejgQRs5ModeiJ6Xs=
70777115

7078-
resolve@^1.10.0, resolve@^1.14.2, resolve@^1.17.0, resolve@^1.3.2, resolve@^1.4.0, resolve@^1.5.0:
7116+
resolve@^1.10.0, resolve@^1.13.1, resolve@^1.14.2, resolve@^1.17.0, resolve@^1.3.2, resolve@^1.4.0, resolve@^1.5.0:
70797117
version "1.20.0"
70807118
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.20.0.tgz#629a013fb3f70755d6f0b7935cc1c2c5378b1975"
70817119
integrity sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A==

0 commit comments

Comments
 (0)