Skip to content

Commit 4f31f18

Browse files
authored
Merge pull request #21 from inokawa/support-images
Support images
2 parents 1a222cb + c72dc0d commit 4f31f18

File tree

13 files changed

+147
-12
lines changed

13 files changed

+147
-12
lines changed

README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ The communication between React app and React Native app will be also simplified
1616

1717
<img src="./examples/ios.gif" height="500px" /> <img src="./examples/android.gif" height="500px" />
1818

19+
## Features
20+
21+
- Create React app bundle for WebView automatically in build process of React Native
22+
- `.js`, `.ts`, `.jsx`, `.tsx` will be packed into one source.
23+
- Handle communication between React Native and WebView with React hook style
24+
- Support bundling some assets in web side with ES6 import syntax
25+
- `.json` is imported as an object, like require in Node.js.
26+
- `.css` is injected to the HTML head of WebView, like [css-loader](https://github.com/webpack-contrib/css-loader).
27+
- `.bmp`, `.gif`, `.png`, `.jpg`, `.jpeg`, `.webp` and `.svg` are loaded as base64 encoded url, like [url-loader](https://github.com/webpack-contrib/url-loader).
28+
29+
If you have some feature requests or improvements, please create a [issue](https://github.com/inokawa/react-native-react-bridge/issues) or [PR](https://github.com/inokawa/react-native-react-bridge/pulls).
30+
1931
## Install
2032

2133
```sh
@@ -56,8 +68,10 @@ import {
5668
emit,
5769
useSubscribe,
5870
} from "react-native-react-bridge/lib/web";
59-
// Import css is supported
71+
// Importing css is supported
6072
import "./example.css";
73+
// Images are loaded as base64 encoded string
74+
import image from "./foo.png";
6175

6276
const Root = () => {
6377
const [data, setData] = useState("");
@@ -69,6 +83,7 @@ const Root = () => {
6983
});
7084
return (
7185
<div>
86+
<img src={image} />
7287
<div>{data}</div>
7388
<button
7489
onClick={() => {
@@ -123,11 +138,6 @@ const App = () => {
123138

124139
4. Start your React Native app!
125140

126-
## Limitations
127-
128-
- In web side, `.js`, `.ts`, `.jsx`, `.tsx`, `.css` and `.json` are currently supported extensions.
129-
- If you have some feature requests or improvements, please create a [issue](https://github.com/inokawa/react-native-react-bridge/issues).
130-
131141
## Demo
132142

133143
This repository includes demo app.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from "react";
2+
import { webViewRender } from "react-native-react-bridge/lib/web";
3+
import bmp from "./twitter.bmp";
4+
import gif from "./twitter.gif";
5+
import png from "./twitter.png";
6+
import jpg from "./twitter.jpg";
7+
import jpeg from "./twitter.jpeg";
8+
import webp from "./twitter.webp";
9+
import svg from "./twitter.svg";
10+
11+
const App = () => {
12+
return (
13+
<div>
14+
<img src={bmp} />
15+
<img src={gif} />
16+
<img src={png} />
17+
<img src={jpg} />
18+
<img src={jpeg} />
19+
<img src={webp} />
20+
<img src={svg} />
21+
</div>
22+
);
23+
};
24+
25+
export default webViewRender(App);

fixtures/twitter.bmp

625 KB
Binary file not shown.

fixtures/twitter.gif

3.35 KB
Loading

fixtures/twitter.jpeg

11.8 KB
Loading

fixtures/twitter.jpg

11.8 KB
Loading

fixtures/twitter.png

9.26 KB
Loading

fixtures/twitter.svg

Lines changed: 20 additions & 0 deletions
Loading

fixtures/twitter.webp

7.51 KB
Loading

src/plugin/__snapshots__/metro.spec.js.snap

Lines changed: 24 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)