Skip to content

Commit adc8bac

Browse files
committed
chore: initial commit
0 parents  commit adc8bac

File tree

12 files changed

+206
-0
lines changed

12 files changed

+206
-0
lines changed

.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Learn more https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files
2+
3+
# dependencies
4+
node_modules/
5+
6+
# Expo
7+
.expo/
8+
dist/
9+
web-build/
10+
11+
# Native
12+
*.orig.*
13+
*.jks
14+
*.p8
15+
*.p12
16+
*.key
17+
*.mobileprovision
18+
19+
# Metro
20+
.metro-health-check*
21+
22+
# debug
23+
npm-debug.*
24+
yarn-debug.*
25+
yarn-error.*
26+
27+
# macOS
28+
.DS_Store
29+
*.pem
30+
31+
# local env files
32+
.env*.local
33+
34+
# typescript
35+
*.tsbuildinfo

App.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import './globals.js'
2+
import { StatusBar } from 'expo-status-bar'
3+
import { StyleSheet, Text, View } from 'react-native'
4+
import { useState, useEffect } from 'react'
5+
import { createLibp2p } from 'libp2p'
6+
7+
export default function App () {
8+
const [libp2p, setLibp2p] = useState(null)
9+
useEffect(() => {
10+
async function getLibp2p() {
11+
const node = await createLibp2p()
12+
console.info('loaded libp2p', node.peerId)
13+
setLibp2p(node)
14+
}
15+
getLibp2p()
16+
}, [])
17+
18+
return (
19+
<View style={styles.container}>
20+
<Text>Open up App.js to start working on your app!</Text>
21+
<Text>Our PeerId is {libp2p?.peerId.toString()}</Text>
22+
<StatusBar style="auto" />
23+
</View>
24+
)
25+
}
26+
27+
const styles = StyleSheet.create({
28+
container: {
29+
flex: 1,
30+
backgroundColor: '#fff',
31+
alignItems: 'center',
32+
justifyContent: 'center',
33+
}
34+
})

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Running js-libp2p under React Native
2+
3+
Very basic support so far, just js-libp2p itself, no extra modules yet.
4+
5+
1. Turn on exports map support
6+
7+
```js
8+
// metro.config.js
9+
module.exports = {
10+
resolver: {
11+
unstable_enablePackageExports: true,
12+
}
13+
}
14+
```
15+
16+
2. Shimming globals
17+
18+
Some standard JS APIs aren't available in React Native:
19+
20+
1. `crypto.getRandomValues` - `react-native-get-random-values`
21+
2. `TextEncoder`/`TextDecoder` - `text-encoding`
22+
3. `EventTarget`/`Event` - `event-target-shim`
23+
24+
```js
25+
// globals.js - this should be imported at the top of your App.js file
26+
import 'react-native-get-random-values'
27+
import { TextEncoder, TextDecoder } from 'text-encoding'
28+
import { EventTarget, Event } from 'event-target-shim'
29+
30+
global.TextEncoder = TextEncoder
31+
global.TextDecoder = TextDecoder
32+
global.EventTarget = EventTarget
33+
global.Event = Event
34+
```
35+
36+
## Running
37+
38+
### iOS
39+
40+
1. Install XCode
41+
2. Install iOS (XCode > Settings > Platforms > Install the latest iOS version)
42+
43+
### Android
44+
45+
1. ???
46+
47+
### Start
48+
49+
Start [Expo](https://expo.dev/):
50+
51+
```console
52+
$ npm i
53+
$ npm start
54+
```
55+
56+
Follow the instructions - press `i` to start iOS or `a` for Android.

app.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"expo": {
3+
"name": "my-app",
4+
"slug": "my-app",
5+
"version": "1.0.0",
6+
"orientation": "portrait",
7+
"icon": "./assets/icon.png",
8+
"userInterfaceStyle": "light",
9+
"splash": {
10+
"image": "./assets/splash.png",
11+
"resizeMode": "contain",
12+
"backgroundColor": "#ffffff"
13+
},
14+
"assetBundlePatterns": [
15+
"**/*"
16+
],
17+
"ios": {
18+
"supportsTablet": true
19+
},
20+
"android": {
21+
"adaptiveIcon": {
22+
"foregroundImage": "./assets/adaptive-icon.png",
23+
"backgroundColor": "#ffffff"
24+
}
25+
},
26+
"web": {
27+
"favicon": "./assets/favicon.png"
28+
}
29+
}
30+
}

assets/adaptive-icon.png

17.1 KB
Loading

assets/favicon.png

1.43 KB
Loading

assets/icon.png

21.9 KB
Loading

assets/splash.png

46.2 KB
Loading

babel.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = function (api) {
2+
api.cache(true)
3+
4+
return {
5+
presets: ['babel-preset-expo']
6+
}
7+
}

globals.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Shim global JS objects, hopefully this won't be necessary forever
2+
// https://github.com/facebook/hermes/discussions/1072
3+
4+
import 'react-native-get-random-values'
5+
import { TextEncoder, TextDecoder } from 'text-encoding'
6+
import { EventTarget, Event } from 'event-target-shim'
7+
8+
global.TextEncoder = TextEncoder
9+
global.TextDecoder = TextDecoder
10+
global.EventTarget = EventTarget
11+
global.Event = Event

0 commit comments

Comments
 (0)