Skip to content

Commit 0a96fb6

Browse files
authored
added html example (expo#409)
1 parent b08a6f0 commit 0a96fb6

File tree

5 files changed

+95
-0
lines changed

5 files changed

+95
-0
lines changed

with-html/App.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Image } from "react-native";
2+
3+
export default function App() {
4+
return (
5+
<main className="flex-1 items-center justify-center">
6+
<article className="md:flex bg-slate-100 rounded-xl p-8 md:p-0 dark:bg-slate-800">
7+
<Image
8+
className="w-24 h-24 md:w-48 md:h-auto md:rounded-none rounded-full mx-auto"
9+
source={{
10+
uri: "https://en.gravatar.com/userimage/120276729/078ee8361156d0e1c37b90e7851fed4b.png",
11+
}}
12+
width="384"
13+
height="512"
14+
/>
15+
<main className="pt-6 md:p-8 text-center md:text-left space-y-4">
16+
<p className="text-lg font-medium">
17+
With <code>@expo/html-elements</code>, you can write HTML syntax
18+
that renders to real native components. Combined with Tailwind CSS,
19+
you have an experience that makes web developers feel at home.”
20+
</p>
21+
<article className="font-medium">
22+
<p className="text-sky-500 dark:text-sky-400 my-0">Evan Bacon</p>
23+
<p className="text-slate-700 dark:text-slate-500 my-2">
24+
Engineer, Expo
25+
</p>
26+
</article>
27+
</main>
28+
</article>
29+
</main>
30+
);
31+
}

with-html/README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# HTML Elements Example
2+
3+
<p>
4+
<!-- iOS -->
5+
<img alt="Supports Expo iOS" longdesc="Supports Expo iOS" src="https://img.shields.io/badge/iOS-4630EB.svg?style=flat-square&logo=APPLE&labelColor=999999&logoColor=fff" />
6+
<!-- Android -->
7+
<img alt="Supports Expo Android" longdesc="Supports Expo Android" src="https://img.shields.io/badge/Android-4630EB.svg?style=flat-square&logo=ANDROID&labelColor=A4C639&logoColor=fff" />
8+
<!-- Web -->
9+
<img alt="Supports Expo Web" longdesc="Supports Expo Web" src="https://img.shields.io/badge/web-4630EB.svg?style=flat-square&logo=GOOGLE-CHROME&labelColor=4285F4&logoColor=fff" />
10+
</p>
11+
12+
## 🚀 How to use
13+
14+
<!-- Setup instructions -->
15+
16+
- Install with `yarn` or `npm install`.
17+
- Run `yarn start` or `npm run start` to try it out.
18+
19+
## 📝 Notes
20+
21+
<!-- Link to related Expo or library docs -->
22+
23+
This example combines the [`@expo/html-elements` Babel plugin](https://github.com/expo/expo/blob/d314efccb28d005d5df83df74883eb0365020ae2/packages/html-elements/babel.js#L3-L41) and [`nativewind`](https://www.nativewind.dev/) which enables CSS-like styling.
24+
25+
You can write pure HTML elements which are converted to native views at build time.

with-html/babel.config.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = function (api) {
2+
api.cache(true);
3+
return {
4+
presets: ["babel-preset-expo"],
5+
plugins: [
6+
// Must come before the nativewind plugin
7+
"@expo/html-elements/babel",
8+
[
9+
"nativewind/babel",
10+
{
11+
allowModuleTransform: ["@expo/html-elements"],
12+
},
13+
],
14+
],
15+
};
16+
};

with-html/package.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"dependencies": {
3+
"@expo/html-elements": "^0.3.0",
4+
"expo": "^46.0.0",
5+
"nativewind": "^2.0.10",
6+
"react": "18.0.0",
7+
"react-dom": "18.0.0",
8+
"react-native": "0.69.4",
9+
"react-native-web": "~0.18.7"
10+
},
11+
"devDependencies": {
12+
"@babel/core": "^7.18.6",
13+
"tailwindcss": "^3.1.8"
14+
}
15+
}

with-html/tailwind.config.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/** @type {import('tailwindcss').Config} */
2+
module.exports = {
3+
content: ['./App.{js,jsx,ts,tsx}', './screens/**/*.{js,jsx,ts,tsx}'],
4+
theme: {
5+
extend: {},
6+
},
7+
plugins: [],
8+
};

0 commit comments

Comments
 (0)