Skip to content

Commit beadf11

Browse files
authored
Chore: change new app recommandation (#176)
When a gnonative user wants to create a new app using gnonative, he can use the make rule `new-app` like that: `APP_NAME=test make new-app`. This rule now uses the gnonative expo module hosted in the NPM's registry. This approach hides a lot of complexity to let the user concentrate to his app development, and makes gnonative updates easier. This PR does other things: - updates gnoboard to Expo v51 to be compatible with Xcode 15.3 or above. - fixes the ios build caused by the uppercase of the first letter of the app name `gnoboard`. - uses a copy of the Expo's gnonative-provider file instead of use-gno file. So make updates of gnonative in gnoboard would be easier. --------- Signed-off-by: D4ryl00 <[email protected]>
1 parent 15d9089 commit beadf11

File tree

97 files changed

+16196
-9647
lines changed

Some content is hidden

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

97 files changed

+16196
-9647
lines changed

Makefile

Lines changed: 10 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ APP_NAME ?= gnoboard
1313
make_dir := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
1414
cache_dir := $(make_dir)/.cache
1515
gnoboard_dir := $(make_dir)/examples/js/react-native/gnoboard
16+
expo_dir := $(make_dir)/expo
1617

1718
# Argument Defaults
1819
APP_OUTPUT_DIR ?= $(make_dir)/examples/js/react-native/$(APP_NAME)
@@ -188,91 +189,35 @@ asdf.install_tools: asdf.add_plugins
188189
########################################
189190
# Script to create a new app
190191

191-
npm_basic_dependencies := @bufbuild/protobuf @connectrpc/connect @connectrpc/connect-web react-native-polyfill-globals react-native-url-polyfill [email protected] react-native-get-random-values text-encoding base-64 react-native-fetch-api
192-
npm_basic_dev_dependencies = @tsconfig/react-native babel-plugin-module-resolver
192+
npm_basic_dependencies := @gnolang/gnonative
193193
OUTPUT_DIR := $(make_dir)/examples/js/react-native
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
199+
$(call check-program, npm)
200+
npm config set @buf:registry https://buf.build/gen/npm/v1/
199201
$(MAKE) new-react-native-app OUTPUT_DIR=$(make_dir)/examples/js/react-native
200-
$(MAKE) add-app-json-entry APP_NAME=$(APP_NAME) APP_OUTPUT_DIR=$(make_dir)/examples/js/react-native
201202
$(MAKE) copy-js-files APP_NAME=$(APP_NAME) APP_OUTPUT_DIR=$(make_dir)/examples/js/react-native
202-
$(MAKE) new-app-build-android APP_NAME=$(APP_NAME) APP_OUTPUT_DIR=$(make_dir)/examples/js/react-native
203-
ifeq ($(OS),Darwin)
204-
$(MAKE) new-app-build-ios APP_NAME=$(APP_NAME) APP_OUTPUT_DIR=$(make_dir)/examples/js/react-native
205-
$(MAKE) copy-ios-project-pbxproj
206-
endif
207203

208204
# creates a new react native app using Expo script. Also creates ios and android folders
209205
new-react-native-app:
206+
$(call check-program, npm)
210207
$(call check-program, npx)
211208
@mkdir -p $(OUTPUT_DIR)
212209
@echo "creating a new gno awesome project at: $(OUTPUT_DIR)"
213210
cd $(OUTPUT_DIR) && npx create-expo-app@latest $(APP_NAME) --template expo-template-blank-typescript
214211
@echo "Creating ios and android folders"
215-
cd $(OUTPUT_DIR)/$(APP_NAME) && npm expo prebuild
212+
cd $(OUTPUT_DIR)/$(APP_NAME) && npx expo prebuild
216213
@echo "Installing npm dependencies"
217-
cd $(OUTPUT_DIR)/$(APP_NAME) && npm install ${npm_basic_dependencies} && npm install -D ${npm_basic_dev_dependencies}
214+
cd $(OUTPUT_DIR)/$(APP_NAME) && npm install ${npm_basic_dependencies}
218215
@echo "Building GnoCore.xcframework for the new app"
219216
$(MAKE) build.ios APP_NAME=$(APP_NAME) APP_OUTPUT_DIR=$(OUTPUT_DIR)/$(APP_NAME)
220217

221218
# copy js files from gnoboard to the new app
222219
copy-js-files:
223-
$(call check-program, jq)
224220
@echo "Copying js files"
225-
@mkdir -p $(OUTPUT_DIR)/$(APP_NAME)/src/grpc
226-
@mkdir -p $(OUTPUT_DIR)/$(APP_NAME)/src/hooks
227-
@cp -r $(gnoboard_dir)/src/grpc $(OUTPUT_DIR)/$(APP_NAME)/src
228-
@cp -r $(gnoboard_dir)/src/hooks $(OUTPUT_DIR)/$(APP_NAME)/src
229-
@cp -r $(gnoboard_dir)/src/native_modules $(OUTPUT_DIR)/$(APP_NAME)/src
230-
@cp -r $(gnoboard_dir)/Makefile $(OUTPUT_DIR)/$(APP_NAME)
231-
@cp -r $(gnoboard_dir)/android/.gitignore $(OUTPUT_DIR)/$(APP_NAME)/android
232-
@cp -r $(gnoboard_dir)/ios/.gitignore $(OUTPUT_DIR)/$(APP_NAME)/ios
233-
@cp $(make_dir)/templates/tsconfig.json $(OUTPUT_DIR)/$(APP_NAME)/tsconfig.json
234-
@cp $(make_dir)/templates/babel.config.js $(OUTPUT_DIR)/$(APP_NAME)/babel.config.js
235-
@cp $(make_dir)/templates/metro.config.js $(OUTPUT_DIR)/$(APP_NAME)/metro.config.js
236-
@cp $(make_dir)/templates/App.tsx $(OUTPUT_DIR)/$(APP_NAME)/App.tsx
237-
238-
# build GnoCore.xcframework for the new app
239-
new-app-build-ios:
240-
@echo "Copying ios files"
241-
@mkdir -p $(OUTPUT_DIR)/$(APP_NAME)/ios/$(APP_NAME)/Sources
242-
@cp -r $(gnoboard_dir)/ios/gnoboard/Sources $(OUTPUT_DIR)/$(APP_NAME)/ios/$(APP_NAME)/
243-
@cp $(gnoboard_dir)/ios/gnoboard/gnoboard-Bridging-Header.h $(OUTPUT_DIR)/$(APP_NAME)/ios/$(APP_NAME)/$(APP_NAME)-Bridging-Header.h
244-
@cp -r $(gnoboard_dir)/ios/Sources $(OUTPUT_DIR)/$(APP_NAME)/ios/
245-
@cd $(OUTPUT_DIR)/$(APP_NAME) && $(MAKE) ios/$(APP_NAME).xcworkspace TEMPLATE_PROJECT=$(APP_NAME)
246-
247-
# build the Android project files for the new app
248-
new-app-build-android:
249-
@echo "Copying Android project files"
250-
@$(eval MAIN_APP_PATH := $(shell find $(OUTPUT_DIR)/$(APP_NAME)/android/app/src/main/java -name 'MainApplication.kt')) # ./android/app/src/main/java/com/anonymous/<APP_NAME>/MainApplication.kt
251-
@$(eval MAIN_APP_FILE := $(shell basename $(MAIN_APP_PATH))) # MainApplication.kt
252-
@$(eval MAIN_APP_DIR := $(shell dirname $(MAIN_APP_PATH))) # ./android/app/src/main/java/com/anonymous/<APP_NAME>
253-
@$(eval PACKAGE_PREFIX := $(shell sed -n 's/package \(.*\)\.$(APP_NAME)/\1/'p $(MAIN_APP_DIR)/$(MAIN_APP_FILE))) # e.g. com.anonymous
254-
@cp -r $(gnoboard_dir)/android/app/src/main/java/land/gno/gobridge $(MAIN_APP_DIR)/.. # copy gobridge directory
255-
@cp -r $(gnoboard_dir)/android/app/src/main/java/land/gno/rootdir $(MAIN_APP_DIR)/.. # copy rootdir directory
256-
@perl -pi -e "s/land\.gno/$(PACKAGE_PREFIX)/" $(MAIN_APP_DIR)/../gobridge/* # in gobridge, replace land.gno by PACKAGE_PREFIX (e.g. com.anonymous)
257-
@perl -pi -e "s/land\.gno/$(PACKAGE_PREFIX)/" $(MAIN_APP_DIR)/../rootdir/* # in rootdir, replace land.gno by PACKAGE_PREFIX (e.g. com.anonymous)
258-
@perl -pi -e '/^package ./ and $$_.="\nimport '"$(PACKAGE_PREFIX)"'.gobridge.GoBridgePackage"' $(MAIN_APP_DIR)/$(MAIN_APP_FILE) # add the right import path for gobridge (e.g. import com.anonymous.gobridge.GoBridgePackage)
259-
@perl -pi -e '/^package ./ and $$_.="\nimport '"$(PACKAGE_PREFIX)"'.rootdir.RootDirPackage"' $(MAIN_APP_DIR)/$(MAIN_APP_FILE) # add the right import path for rootdir (e.g. import com.anonymous.rootdir.RootDirPackage)
260-
@perl -pi -e 's/return PackageList\(this\)\.packages/return PackageList\(this\)\.packages.apply \{\n\t\t\t\tadd(RootDirPackage())\n\t\t\t\tadd(GoBridgePackage())\n\t\t\t\}/' $(MAIN_APP_DIR)/$(MAIN_APP_FILE) # replace the default package list by one adding gobridge and rootdir
261-
@perl -pi -e '/^def projectRoot/ and $$_.="def frameworkDir = \"\$$\{rootDir\.getAbsoluteFile\(\)\.getParentFile\(\)\.getParentFile\(\)\.getParentFile\(\)\.getParentFile\(\)\.getParentFile\(\)\.getAbsolutePath\(\)\}/framework\"\n"' $(OUTPUT_DIR)/$(APP_NAME)/android/app/build.gradle # add the projectRoot variable in build.gradle
262-
@perl -pi -e '/^dependencies/ and $$_.="\timplementation fileTree(dir: \"\$$\{frameworkDir\}/android\", include: \[\"\*\.jar\", \"\*\.aar\"\]\)\n"' $(OUTPUT_DIR)/$(APP_NAME)/android/app/build.gradle # add the framework dependency in build.gradle
263-
@cd $(OUTPUT_DIR)/$(APP_NAME) && $(MAKE) node_modules TEMPLATE_PROJECT=$(APP_NAME)
264-
265-
JSON_FILE := $(OUTPUT_DIR)/$(APP_NAME)/app.json
266-
# add tsconfigPaths entry to app.json
267-
add-app-json-entry:
268-
@echo "Adding tsconfigPaths entry to app.json"
269-
jq '.expo.experiments = {"tsconfigPaths": true}' $(JSON_FILE) > $(JSON_FILE).tmp && mv $(JSON_FILE).tmp $(JSON_FILE)
270-
271-
# copy ios project.pbxproj from gnoboard to the new app and replace 'gnoboard' with the new app name
272-
copy-ios-project-pbxproj:
273-
@echo "Copying ios project.pbxproj"
274-
@cp $(gnoboard_dir)/ios/gnoboard.xcodeproj/project.pbxproj $(OUTPUT_DIR)/$(APP_NAME)/ios/$(APP_NAME).xcodeproj/project.pbxproj
275-
@cd $(OUTPUT_DIR)/$(APP_NAME)/ios/$(APP_NAME).xcodeproj
276-
@sed -i.pbxproj 's/gnoboard/$(APP_NAME)/g' $(OUTPUT_DIR)/$(APP_NAME)/ios/$(APP_NAME).xcodeproj/project.pbxproj
277-
278-
.PHONY: new-app new-react-native-app copy-js-files new-app-build-ios add-app-json-entry copy-ios-project-pbxproj
221+
@cp $(expo_dir)/example/App.tsx $(OUTPUT_DIR)/$(APP_NAME)/App.tsx
222+
223+
.PHONY: new-app configure-npm new-react-native-app copy-js-files

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Gno Native Kit is a framework that allows developers to build and port gno.land (d)apps written in the (d)app's native language.
44

5-
Current Gno (d)apps run on desktop/laptop computers which have Go installed. To run on mobile, the (d)app would need to bundle the Go runtime, which is complicated for most developers.
5+
Current Gno (d)apps run on desktop/laptop computers which have Go installed. To run on mobile, the (d)app would need to bundle the Go runtime, which is complicated for most developers.
66

77
However, Gno Native Kit helps bypass this complexity by using gRPC to make [calls to the Gno core API](https://buf.build/gnolang/gnonative/docs/main:land.gno.gnonative.v1) and access the blockchain's realm functions on a remote Gno.land node.
88
These API calls are a programming language-independent wrapper on top of the core supported APIs like [gnoclient](https://github.com/gnolang/gno/tree/master/gno.land/pkg/gnoclient) and [crypto/keys](https://github.com/gnolang/gno/tree/master/tm2/pkg/crypto/keys).
@@ -76,12 +76,12 @@ cd gnonative
7676

7777
#### Set up the Android NDK
7878

79-
* Launch Android Studio and accept the default startup options. Create a new
80-
default project (so that we get the main screen).
81-
* On the Tools menu, open the SDK Manager.
82-
* In the "SDK Tools" tab, click "Show Package Details". Expand
83-
"NDK (Side by side)" and check "23.1.7779620".
84-
* Click OK to install and close the SDK Manager.
79+
- Launch Android Studio and accept the default startup options. Create a new
80+
default project (so that we get the main screen).
81+
- On the Tools menu, open the SDK Manager.
82+
- In the "SDK Tools" tab, click "Show Package Details". Expand
83+
"NDK (Side by side)" and check "23.1.7779620".
84+
- Click OK to install and close the SDK Manager.
8585

8686
#### Install the tools with asdf (only need to do once)
8787

@@ -101,7 +101,7 @@ make build.android
101101

102102
```console
103103
cd examples/js/react-native/gnoboard
104-
yarn start
104+
npm start
105105
```
106106

107107
#### Connect your Android phone/emulator and bind its port to metro
@@ -125,6 +125,7 @@ If you prefer the CLI option:
125125
```console
126126
android-studio ./android
127127
```
128+
128129
Once done, bind the port to metro:
129130

130131
```console
@@ -145,7 +146,7 @@ See more: https://developer.android.com/studio/run#basic-build-run
145146
make asdf.install_tools
146147
```
147148

148-
If you get an error like "https://github.com/CocoaPods/CLAide.git (at master@97b765e) is not yet checked out" then reinstall cocoapods like this:
149+
If you get an error like "https://github.com/CocoaPods/CLAide.git (at master@97b765e) is not yet checked out" then reinstall cocoapods like this:
149150

150151
```console
151152
asdf uninstall cocoapods
@@ -162,7 +163,7 @@ make build.ios
162163

163164
```console
164165
cd examples/js/react-native/gnoboard
165-
yarn start
166+
npm start
166167
```
167168

168169
#### Open Xcode and connect your iOS device

docs/getting-started/create-new-app.md

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,7 @@ To run the app, run the following command:
2828

2929
```console
3030
cd examples/js/react-native/MyApp
31-
make android.reverse_tcp # for Android, after you have connected an Android device (simulator or real device)
32-
yarn start
33-
```
34-
35-
and then run the following command in another terminal in the repo folder:
36-
37-
```console
38-
cd $(go list -m -f '{{.Dir}}') # go to the root of the repo
39-
cd examples/js/react-native/MyApp
40-
npx react-native [run-android|run-ios]
31+
npx expo [run:android|run-ios]
4132
```
4233

4334
## Using Gno in your App
@@ -46,25 +37,30 @@ To use Gno in your app, you can import the `useGno` hook from
4637
`@gno/hooks/use-gno`:
4738

4839
```ts
49-
import { useGno } from '@gno/hooks/use-gno';
50-
51-
export default function App() {
52-
const gno = useGno();
53-
54-
React.useEffect(() => {
55-
gno.getRemote()
56-
.then(res => console.log(res))
57-
.catch(err => console.log(err));
58-
}, []);
59-
60-
...
61-
```
40+
import { GnoNativeProvider, useGnoNativeContext } from '@gnolang/gnonative';
6241

63-
## Regenerate dependencies
42+
const config = {
43+
remote: 'https://gno.berty.io',
44+
chain_id: 'dev',
45+
};
6446

65-
If you changed some Go code, or updated the React-Native dependencies, you have to build them again:
66-
```console
67-
cd $(go list -m -f '{{.Dir}}') # go to the root of the repo
68-
APP_NAME=MyApp make build.ios # for iOS
69-
APP_NAME=MyApp make build.android # for Android
47+
export default function App() {
48+
return (
49+
<GnoNativeProvider config={config}>
50+
<InnerApp />
51+
</GnoNativeProvider>
52+
);
53+
}
54+
55+
const InnerApp = () => {
56+
const { gnonative } = useGnoNativeContext();
57+
58+
useEffect(() => {
59+
(async () => {
60+
try {
61+
const remote = await gnonative.getRemote();
62+
const chainId = await gnonative.getChainID();
63+
console.log('Remote %s ChainId %s', remote, chainId);
64+
...
65+
}
7066
```

examples/js/react-native/gnoboard/App.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
// order of imports is important
22
import 'react-native-polyfill-globals/auto';
33

4-
import { GnoNativeProvider } from '@gno/provider/gnonative/gnonative-provider';
4+
import { GnoNativeProvider } from '@gno/provider/gnonative-provider';
55
import CustomRouter from '@gno/router/custom-router';
66

77
// Polyfill async.Iterator. For some reason, the Babel presets and plugins are not doing the trick.
88
// Code from here: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-3.html#caveats
99
(Symbol as any).asyncIterator = Symbol.asyncIterator || Symbol.for('Symbol.asyncIterator');
1010

1111
function App() {
12+
const defaultConfig = {
13+
remote: 'gno.land:26657',
14+
chain_id: 'portal-loop',
15+
};
16+
1217
return (
13-
<GnoNativeProvider>
18+
<GnoNativeProvider config={defaultConfig}>
1419
<CustomRouter />
1520
</GnoNativeProvider>
1621
);

examples/js/react-native/gnoboard/app.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"expo": {
3-
"name": "Gnoboard",
4-
"slug": "Gnoboard",
3+
"name": "gnoboard",
54
"version": "1.0.0",
5+
"slug": "gnoboard",
66
"orientation": "portrait",
77
"icon": "./assets/icon.png",
88
"userInterfaceStyle": "light",

examples/js/react-native/gnoboard/ios/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ install! 'cocoapods',
3434

3535
prepare_react_native_project!
3636

37-
target 'Gnoboard' do
37+
target 'gnoboard' do
3838
use_expo_modules!
3939
config = use_native_modules!
4040

examples/js/react-native/gnoboard/ios/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,6 @@ SPEC CHECKSUMS:
15671567
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
15681568
Yoga: 950bbfd7e6f04790fdb51149ed51df41f329fcc8
15691569

1570-
PODFILE CHECKSUM: c23220d69a4743259f4edbb814b43a3d63d83bb6
1570+
PODFILE CHECKSUM: 4bc5bbe35d066cc8497f62a7178ffb47e1f91315
15711571

15721572
COCOAPODS: 1.15.2

0 commit comments

Comments
 (0)