Skip to content

Commit 38e461b

Browse files
authored
Chore: improve hello example apps (example/js) (#177)
This PR moves the `hello` example app using Expo from `example/js/react-native/hello` to `example/js/expo/hello`, and modifies the `new-app` Makefile rule to create new apps in the new `example/js/expo` directory. We also recreate `example/js/react-native/hello` from scratch following the react-native guide, to create a new `hello` app without Expo. Then we integrated gnonative files without the gnonative NPM package. The steps to accomplish that are written in the `example/js/react-native/hello/README.md` file so anyone can integrate gnonative in its bare React-Native app. --------- Signed-off-by: D4ryl00 <[email protected]>
1 parent 7534c7d commit 38e461b

File tree

124 files changed

+26786
-7945
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+26786
-7945
lines changed

.tool-versions

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
nodejs 21.7.3
1+
nodejs 22.8.0
22
ruby 3.2.2
33
cocoapods 1.15.2
44
java openjdk-17.0.2

Makefile

+6-8
Original file line numberDiff line numberDiff line change
@@ -190,19 +190,19 @@ asdf.install_tools: asdf.add_plugins
190190
# Script to create a new app
191191

192192
npm_basic_dependencies := @gnolang/gnonative
193-
OUTPUT_DIR := $(make_dir)/examples/js/react-native
193+
OUTPUT_DIR := $(make_dir)/examples/js/expo
194194

195195
new-app:
196196
ifndef APP_NAME
197197
$(error APP_NAME is undefined. Please set APP_NAME to the name of your app)
198198
endif
199199
$(call check-program, npm)
200200
npm config set @buf:registry https://buf.build/gen/npm/v1/
201-
$(MAKE) new-react-native-app OUTPUT_DIR=$(make_dir)/examples/js/react-native
202-
$(MAKE) copy-js-files APP_NAME=$(APP_NAME) APP_OUTPUT_DIR=$(make_dir)/examples/js/react-native
201+
$(MAKE) new-expo-app OUTPUT_DIR=$(make_dir)/examples/js/expo
202+
$(MAKE) copy-js-files OUTPUT_DIR=$(make_dir)/examples/js/expo APP_NAME=$(APP_NAME)
203203

204-
# creates a new react native app using Expo script. Also creates ios and android folders
205-
new-react-native-app:
204+
# creates a new Expo app using Expo script. Also creates ios and android folders
205+
new-expo-app:
206206
$(call check-program, npm)
207207
$(call check-program, npx)
208208
@mkdir -p $(OUTPUT_DIR)
@@ -212,12 +212,10 @@ new-react-native-app:
212212
cd $(OUTPUT_DIR)/$(APP_NAME) && npx expo prebuild
213213
@echo "Installing npm dependencies"
214214
cd $(OUTPUT_DIR)/$(APP_NAME) && npm install ${npm_basic_dependencies}
215-
@echo "Building GnoCore.xcframework for the new app"
216-
$(MAKE) build.ios APP_NAME=$(APP_NAME) APP_OUTPUT_DIR=$(OUTPUT_DIR)/$(APP_NAME)
217215

218216
# copy js files from gnoboard to the new app
219217
copy-js-files:
220218
@echo "Copying js files"
221219
@cp $(expo_dir)/example/App.tsx $(OUTPUT_DIR)/$(APP_NAME)/App.tsx
222220

223-
.PHONY: new-app configure-npm new-react-native-app copy-js-files
221+
.PHONY: new-app configure-npm new-expo-app copy-js-files

examples/js/expo/hello/.gitignore

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

examples/js/expo/hello/App.tsx

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { GnoNativeProvider, useGnoNativeContext } from '@gnolang/gnonative';
2+
import React, { useEffect, useState } from 'react';
3+
import { StyleSheet, Text, View } from 'react-native';
4+
5+
const config = {
6+
remote: 'https://gno.berty.io',
7+
chain_id: 'dev',
8+
};
9+
10+
export default function App() {
11+
return (
12+
<GnoNativeProvider config={config}>
13+
<InnerApp />
14+
</GnoNativeProvider>
15+
);
16+
}
17+
18+
const InnerApp = () => {
19+
const { gnonative } = useGnoNativeContext();
20+
const [greeting, setGreeting] = useState('');
21+
22+
useEffect(() => {
23+
(async () => {
24+
try {
25+
const accounts = await gnonative.listKeyInfo();
26+
console.log(accounts);
27+
28+
const remote = await gnonative.getRemote();
29+
const chainId = await gnonative.getChainID();
30+
console.log('Remote %s ChainId %s', remote, chainId);
31+
32+
const phrase = await gnonative.generateRecoveryPhrase();
33+
const address = await gnonative.addressFromMnemonic(phrase);
34+
const addressStr = await gnonative.addressToBech32(address);
35+
36+
console.log('Phrase:', phrase);
37+
console.log('Address:', addressStr);
38+
39+
setGreeting(await gnonative.hello('Gno'));
40+
41+
for await (const res of await gnonative.helloStream('Gno')) {
42+
console.log(res.greeting);
43+
}
44+
} catch (error) {
45+
console.log(error);
46+
}
47+
})();
48+
}, []);
49+
50+
return (
51+
<View style={styles.container}>
52+
<Text>Gnonative App</Text>
53+
<Text>{greeting}</Text>
54+
</View>
55+
);
56+
};
57+
58+
const styles = StyleSheet.create({
59+
container: {
60+
flex: 1,
61+
backgroundColor: '#fff',
62+
alignItems: 'center',
63+
justifyContent: 'center',
64+
},
65+
});

examples/js/expo/hello/app.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"expo": {
3+
"name": "hello",
4+
"slug": "hello",
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+
"ios": {
15+
"supportsTablet": true,
16+
"bundleIdentifier": "land.gno.hello"
17+
},
18+
"android": {
19+
"adaptiveIcon": {
20+
"foregroundImage": "./assets/adaptive-icon.png",
21+
"backgroundColor": "#ffffff"
22+
},
23+
"package": "land.gno.hello"
24+
},
25+
"web": {
26+
"favicon": "./assets/favicon.png"
27+
}
28+
}
29+
}
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = function(api) {
2+
api.cache(true);
3+
return {
4+
presets: ['babel-preset-expo'],
5+
};
6+
};

0 commit comments

Comments
 (0)