@gnolang/gnonative 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +5 -0
- package/.prettierrc.js +12 -0
- package/Makefile +62 -0
- package/README.md +118 -0
- package/android/build.gradle +93 -0
- package/android/libs/gnocore-sources.jar +0 -0
- package/android/libs/gnocore.aar +0 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/land/gno/gnonative/GnonativeModule.kt +150 -0
- package/android/src/main/java/land/gno/gnonative/GnonativeView.kt +7 -0
- package/android/src/main/java/land/gno/gnonative/GoBridgeError.kt +6 -0
- package/android/src/main/java/land/gno/gnonative/JavaPromiseBlock.kt +42 -0
- package/build/Gnonative.types.d.ts +7 -0
- package/build/Gnonative.types.d.ts.map +1 -0
- package/build/Gnonative.types.js +2 -0
- package/build/Gnonative.types.js.map +1 -0
- package/build/GnonativeModule.d.ts +3 -0
- package/build/GnonativeModule.d.ts.map +1 -0
- package/build/GnonativeModule.js +5 -0
- package/build/GnonativeModule.js.map +1 -0
- package/build/GnonativeModule.web.d.ts +7 -0
- package/build/GnonativeModule.web.d.ts.map +1 -0
- package/build/GnonativeModule.web.js +12 -0
- package/build/GnonativeModule.web.js.map +1 -0
- package/build/GnonativeView.d.ts +4 -0
- package/build/GnonativeView.d.ts.map +1 -0
- package/build/GnonativeView.js +7 -0
- package/build/GnonativeView.js.map +1 -0
- package/build/GnonativeView.web.d.ts +4 -0
- package/build/GnonativeView.web.d.ts.map +1 -0
- package/build/GnonativeView.web.js +7 -0
- package/build/GnonativeView.web.js.map +1 -0
- package/build/GoBridge.d.ts +12 -0
- package/build/GoBridge.d.ts.map +1 -0
- package/build/GoBridge.js +27 -0
- package/build/GoBridge.js.map +1 -0
- package/build/grpc/client.d.ts +4 -0
- package/build/grpc/client.d.ts.map +1 -0
- package/build/grpc/client.js +12 -0
- package/build/grpc/client.js.map +1 -0
- package/build/grpc/error.d.ts +15 -0
- package/build/grpc/error.d.ts.map +1 -0
- package/build/grpc/error.js +70 -0
- package/build/grpc/error.js.map +1 -0
- package/build/grpc/transport_native.d.ts +4 -0
- package/build/grpc/transport_native.d.ts.map +1 -0
- package/build/grpc/transport_native.js +140 -0
- package/build/grpc/transport_native.js.map +1 -0
- package/build/hooks/types.d.ts +17 -0
- package/build/hooks/types.d.ts.map +1 -0
- package/build/hooks/types.js +2 -0
- package/build/hooks/types.js.map +1 -0
- package/build/hooks/use-gno.d.ts +35 -0
- package/build/hooks/use-gno.d.ts.map +1 -0
- package/build/hooks/use-gno.js +248 -0
- package/build/hooks/use-gno.js.map +1 -0
- package/build/index.d.ts +9 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +13 -0
- package/build/index.js.map +1 -0
- package/expo-module.config.json +9 -0
- package/ios/Frameworks/GnoCore.xcframework/Info.plist +44 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/GnoCore +0 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Headers/GnoCore.h +13 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Headers/GnoGnonative.objc.h +93 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Headers/Universe.objc.h +29 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Headers/ref.h +35 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Modules/module.modulemap +8 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Resources/Info.plist +6 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Versions/A/GnoCore +0 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Versions/A/Headers/GnoCore.h +13 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Versions/A/Headers/GnoGnonative.objc.h +93 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Versions/A/Headers/Universe.objc.h +29 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Versions/A/Headers/ref.h +35 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Versions/A/Modules/module.modulemap +8 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Versions/A/Resources/Info.plist +6 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Versions/Current/GnoCore +0 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Versions/Current/Headers/GnoCore.h +13 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Versions/Current/Headers/GnoGnonative.objc.h +93 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Versions/Current/Headers/Universe.objc.h +29 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Versions/Current/Headers/ref.h +35 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Versions/Current/Modules/module.modulemap +8 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64/GnoCore.framework/Versions/Current/Resources/Info.plist +6 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/GnoCore +0 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Headers/GnoCore.h +13 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Headers/GnoGnonative.objc.h +93 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Headers/Universe.objc.h +29 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Headers/ref.h +35 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Modules/module.modulemap +8 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Resources/Info.plist +6 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Versions/A/GnoCore +0 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Versions/A/Headers/GnoCore.h +13 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Versions/A/Headers/GnoGnonative.objc.h +93 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Versions/A/Headers/Universe.objc.h +29 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Versions/A/Headers/ref.h +35 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Versions/A/Modules/module.modulemap +8 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Versions/A/Resources/Info.plist +6 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Versions/Current/GnoCore +0 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Versions/Current/Headers/GnoCore.h +13 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Versions/Current/Headers/GnoGnonative.objc.h +93 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Versions/Current/Headers/Universe.objc.h +29 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Versions/Current/Headers/ref.h +35 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Versions/Current/Modules/module.modulemap +8 -0
- package/ios/Frameworks/GnoCore.xcframework/ios-arm64_x86_64-simulator/GnoCore.framework/Versions/Current/Resources/Info.plist +6 -0
- package/ios/GnoError.swift +31 -0
- package/ios/Gnonative.podspec +28 -0
- package/ios/GnonativeModule.swift +186 -0
- package/ios/GnonativeView.swift +7 -0
- package/ios/PromiseBlock.swift +45 -0
- package/package.json +50 -0
- package/src/Gnonative.types.ts +7 -0
- package/src/GnonativeModule.ts +5 -0
- package/src/GnonativeModule.web.ts +13 -0
- package/src/GnonativeView.tsx +11 -0
- package/src/GnonativeView.web.tsx +11 -0
- package/src/GoBridge.ts +44 -0
- package/src/grpc/client.ts +14 -0
- package/src/grpc/error.ts +89 -0
- package/src/grpc/transport_native.ts +197 -0
- package/src/hooks/types.ts +19 -0
- package/src/hooks/use-gno.ts +423 -0
- package/src/index.ts +20 -0
- package/tsconfig.json +9 -0
package/.eslintrc.js
ADDED
package/.prettierrc.js
ADDED
package/Makefile
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
PROJECT_DIR := ..
|
|
2
|
+
|
|
3
|
+
ANDROID_FRAMEWORK_SRC_DIR := $(PROJECT_DIR)/framework/android
|
|
4
|
+
ANDROID_FRAMEWORK_OUTPUT_DIR := android/libs
|
|
5
|
+
ANDROID_FRAMEWORK_FILES := gnocore.aar gnocore-sources.jar
|
|
6
|
+
ANDROID_FRAMEWORK_SRC := $(addprefix $(ANDROID_FRAMEWORK_SRC_DIR)/, $(ANDROID_FRAMEWORK_FILES))
|
|
7
|
+
ANDROID_FRAMEWORK_DST := $(addprefix $(ANDROID_FRAMEWORK_OUTPUT_DIR)/, $(ANDROID_FRAMEWORK_FILES))
|
|
8
|
+
|
|
9
|
+
IOS_FRAMEWORK_SRC_DIR := $(PROJECT_DIR)/framework/ios
|
|
10
|
+
IOS_FRAMEWORK_OUTPUT_DIR := ios/Frameworks
|
|
11
|
+
IOS_FRAMEWORK_FILES := GnoCore.xcframework
|
|
12
|
+
IOS_FRAMEWORK_SRC := $(addprefix $(IOS_FRAMEWORK_SRC_DIR)/, $(IOS_FRAMEWORK_FILES))
|
|
13
|
+
IOS_FRAMEWORK_DST := $(addprefix $(IOS_FRAMEWORK_OUTPUT_DIR)/, $(IOS_FRAMEWORK_FILES))
|
|
14
|
+
|
|
15
|
+
build: build.android build.ios
|
|
16
|
+
|
|
17
|
+
clean: clean.android clean.ios
|
|
18
|
+
cd $(PROJECT_DIR); $(MAKE) clean
|
|
19
|
+
.PHONY: clean
|
|
20
|
+
|
|
21
|
+
######### ANDROID #########
|
|
22
|
+
|
|
23
|
+
build.android: $(ANDROID_FRAMEWORK_DST)
|
|
24
|
+
.PHONY: build.android
|
|
25
|
+
|
|
26
|
+
$(ANDROID_FRAMEWORK_SRC):
|
|
27
|
+
cd $(PROJECT_DIR); $(MAKE) framework.android
|
|
28
|
+
|
|
29
|
+
$(ANDROID_FRAMEWORK_DST): $(ANDROID_FRAMEWORK_SRC)
|
|
30
|
+
mkdir -p $(ANDROID_FRAMEWORK_OUTPUT_DIR)
|
|
31
|
+
cp $^ $(ANDROID_FRAMEWORK_OUTPUT_DIR)
|
|
32
|
+
|
|
33
|
+
clean.android:
|
|
34
|
+
rm -fr $(ANDROID_FRAMEWORK_OUTPUT_DIR)
|
|
35
|
+
.PHONY: clean.android
|
|
36
|
+
|
|
37
|
+
######### IOS #########
|
|
38
|
+
|
|
39
|
+
build.ios: $(IOS_FRAMEWORK_DST)
|
|
40
|
+
.PHONY: build.ios
|
|
41
|
+
|
|
42
|
+
$(IOS_FRAMEWORK_SRC):
|
|
43
|
+
cd $(PROJECT_DIR); $(MAKE) framework.ios
|
|
44
|
+
|
|
45
|
+
$(IOS_FRAMEWORK_DST): $(IOS_FRAMEWORK_SRC)
|
|
46
|
+
mkdir -p $(IOS_FRAMEWORK_OUTPUT_DIR)
|
|
47
|
+
cp -r $^ $(IOS_FRAMEWORK_OUTPUT_DIR)
|
|
48
|
+
|
|
49
|
+
clean.ios:
|
|
50
|
+
rm -fr $(IOS_FRAMEWORK_OUTPUT_DIR)
|
|
51
|
+
.PHONY: clean.ios
|
|
52
|
+
|
|
53
|
+
######### NPM #########
|
|
54
|
+
npm.pack: build
|
|
55
|
+
npm install
|
|
56
|
+
npm pack
|
|
57
|
+
.PHONY: npm.pack
|
|
58
|
+
|
|
59
|
+
npm.publish: build
|
|
60
|
+
npm install
|
|
61
|
+
npm publish
|
|
62
|
+
.PHONY: npm.publish
|
package/README.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# gnonative
|
|
2
|
+
|
|
3
|
+
Develop for Gno using your app's native language
|
|
4
|
+
|
|
5
|
+
# API documentation
|
|
6
|
+
|
|
7
|
+
We created a Javascript object helper (useGno) that wraps the RPC API. The
|
|
8
|
+
useGno object is defined in the GnoNative repo at `/expo/src/hooks/use-gno.ts`.
|
|
9
|
+
|
|
10
|
+
The RPC API documentation is avalaible in the Buf registry:
|
|
11
|
+
|
|
12
|
+
- [Documentation](https://buf.build/gnolang/gnonative/docs/main:land.gno.gnonative.v1)
|
|
13
|
+
|
|
14
|
+
# Installation in Expo projects
|
|
15
|
+
|
|
16
|
+
## Prerequisites
|
|
17
|
+
|
|
18
|
+
Please follow the general `Build instructions` in the main
|
|
19
|
+
[README](https://github.com/gnolang/gnonative/blob/main/README.md) and then:
|
|
20
|
+
|
|
21
|
+
```console
|
|
22
|
+
make asdf.install_tools
|
|
23
|
+
npm config set @buf:registry https://buf.build/gen/npm/v1/
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Create new Expo app
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
npx create-expo-app my-app
|
|
30
|
+
cd my-app
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Add the package to your npm dependencies
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
npm install @gnolang/gnonative
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Customize the app
|
|
40
|
+
|
|
41
|
+
We prepared for you an example Hello World code.
|
|
42
|
+
|
|
43
|
+
Open App.js and replace the content with this:
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
import React, { useEffect, useState } from 'react';
|
|
47
|
+
import { StyleSheet, Text, View } from 'react-native';
|
|
48
|
+
|
|
49
|
+
import * as Gnonative from '@gnolang/gnonative';
|
|
50
|
+
|
|
51
|
+
export default function App() {
|
|
52
|
+
const gno = Gnonative.useGno();
|
|
53
|
+
const [greeting, setGreeting] = useState('');
|
|
54
|
+
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
const greeting = async () => {
|
|
57
|
+
try {
|
|
58
|
+
// sync Hello function
|
|
59
|
+
setGreeting(await gno.hello('Gno'));
|
|
60
|
+
|
|
61
|
+
// async Hello function
|
|
62
|
+
for await (const res of await gno.helloStream('Gno')) {
|
|
63
|
+
console.log(res.greeting);
|
|
64
|
+
}
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.log(error);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
greeting();
|
|
70
|
+
}, []);
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<View style={styles.container}>
|
|
74
|
+
<Text>Hey {greeting}</Text>
|
|
75
|
+
</View>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const styles = StyleSheet.create({
|
|
80
|
+
container: {
|
|
81
|
+
flex: 1,
|
|
82
|
+
backgroundColor: '#fff',
|
|
83
|
+
alignItems: 'center',
|
|
84
|
+
justifyContent: 'center',
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Run the app
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
# Re-generate the native project directories from scratch
|
|
93
|
+
npx expo prebuild --clean
|
|
94
|
+
# Run the example app on Android
|
|
95
|
+
npx expo run:android
|
|
96
|
+
# Run the example app on iOS
|
|
97
|
+
npx expo run:ios
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
# Installation in bare React Native projects
|
|
101
|
+
|
|
102
|
+
For bare React Native projects, you must ensure that you have
|
|
103
|
+
[installed and configured the `expo` package](https://docs.expo.dev/bare/installing-expo-modules/)
|
|
104
|
+
before continuing.
|
|
105
|
+
|
|
106
|
+
# Generate new NPM package
|
|
107
|
+
|
|
108
|
+
You can run one of the following command:
|
|
109
|
+
|
|
110
|
+
```shell
|
|
111
|
+
make pack
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
or
|
|
115
|
+
|
|
116
|
+
```shell
|
|
117
|
+
make publish
|
|
118
|
+
```
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
apply plugin: 'com.android.library'
|
|
2
|
+
apply plugin: 'kotlin-android'
|
|
3
|
+
apply plugin: 'maven-publish'
|
|
4
|
+
|
|
5
|
+
group = 'land.gno.gnonative'
|
|
6
|
+
version = '0.1.0'
|
|
7
|
+
|
|
8
|
+
buildscript {
|
|
9
|
+
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
10
|
+
if (expoModulesCorePlugin.exists()) {
|
|
11
|
+
apply from: expoModulesCorePlugin
|
|
12
|
+
applyKotlinExpoModulesCorePlugin()
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Simple helper that allows the root project to override versions declared by this library.
|
|
16
|
+
ext.safeExtGet = { prop, fallback ->
|
|
17
|
+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Ensures backward compatibility
|
|
21
|
+
ext.getKotlinVersion = {
|
|
22
|
+
if (ext.has("kotlinVersion")) {
|
|
23
|
+
ext.kotlinVersion()
|
|
24
|
+
} else {
|
|
25
|
+
ext.safeExtGet("kotlinVersion", "1.8.10")
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
repositories {
|
|
30
|
+
mavenCentral()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
dependencies {
|
|
34
|
+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${getKotlinVersion()}")
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
afterEvaluate {
|
|
39
|
+
publishing {
|
|
40
|
+
publications {
|
|
41
|
+
release(MavenPublication) {
|
|
42
|
+
from components.release
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
repositories {
|
|
46
|
+
maven {
|
|
47
|
+
url = mavenLocal().url
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
android {
|
|
54
|
+
compileSdkVersion safeExtGet("compileSdkVersion", 33)
|
|
55
|
+
|
|
56
|
+
def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
|
|
57
|
+
if (agpVersion.tokenize('.')[0].toInteger() < 8) {
|
|
58
|
+
compileOptions {
|
|
59
|
+
sourceCompatibility JavaVersion.VERSION_11
|
|
60
|
+
targetCompatibility JavaVersion.VERSION_11
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
kotlinOptions {
|
|
64
|
+
jvmTarget = JavaVersion.VERSION_11.majorVersion
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
namespace "land.gno.gnonative"
|
|
69
|
+
defaultConfig {
|
|
70
|
+
minSdkVersion safeExtGet("minSdkVersion", 21)
|
|
71
|
+
targetSdkVersion safeExtGet("targetSdkVersion", 34)
|
|
72
|
+
versionCode 1
|
|
73
|
+
versionName "0.1.0"
|
|
74
|
+
}
|
|
75
|
+
lintOptions {
|
|
76
|
+
abortOnError false
|
|
77
|
+
}
|
|
78
|
+
publishing {
|
|
79
|
+
singleVariant("release") {
|
|
80
|
+
withSourcesJar()
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
repositories {
|
|
86
|
+
mavenCentral()
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
dependencies {
|
|
90
|
+
implementation fileTree(dir: "libs", include: ['*.aar', '*.jar'])
|
|
91
|
+
implementation project(':expo-modules-core')
|
|
92
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
|
|
93
|
+
}
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
package land.gno.gnonative
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.util.Log
|
|
5
|
+
import expo.modules.kotlin.Promise
|
|
6
|
+
import expo.modules.kotlin.exception.CodedException
|
|
7
|
+
import expo.modules.kotlin.modules.Module
|
|
8
|
+
import expo.modules.kotlin.modules.ModuleDefinition
|
|
9
|
+
import gnolang.gno.gnonative.Bridge
|
|
10
|
+
import gnolang.gno.gnonative.BridgeConfig
|
|
11
|
+
import gnolang.gno.gnonative.Gnonative
|
|
12
|
+
import gnolang.gno.gnonative.PromiseBlock
|
|
13
|
+
import java.io.File
|
|
14
|
+
|
|
15
|
+
class GnonativeModule : Module() {
|
|
16
|
+
private var context: Context? = null
|
|
17
|
+
private var rootDir: File? = null
|
|
18
|
+
private var socketPort = 0
|
|
19
|
+
private var bridgeGnoNative: Bridge? = null
|
|
20
|
+
|
|
21
|
+
// Each module class must implement the definition function. The definition consists of components
|
|
22
|
+
// that describes the module's functionality and behavior.
|
|
23
|
+
// See https://docs.expo.dev/modules/module-api for more details about available components.
|
|
24
|
+
override fun definition() = ModuleDefinition {
|
|
25
|
+
// Sets the name of the module that JavaScript code will use to refer to the module. Takes a string as an argument.
|
|
26
|
+
// Can be inferred from module's class name, but it's recommended to set it explicitly for clarity.
|
|
27
|
+
// The module will be accessible from `requireNativeModule('Gnonative')` in JavaScript.
|
|
28
|
+
Name("Gnonative")
|
|
29
|
+
|
|
30
|
+
// Sets constant properties on the module. Can take a dictionary or a closure that returns a dictionary.
|
|
31
|
+
Constants()
|
|
32
|
+
|
|
33
|
+
OnCreate {
|
|
34
|
+
context = appContext.reactContext
|
|
35
|
+
rootDir = context!!.filesDir
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Defines event names that the module can send to JavaScript.
|
|
39
|
+
Events("onChange")
|
|
40
|
+
|
|
41
|
+
AsyncFunction("initBridge") { promise: Promise ->
|
|
42
|
+
try {
|
|
43
|
+
val config: BridgeConfig = Gnonative.newBridgeConfig() ?: throw Exception("")
|
|
44
|
+
config.rootDir = rootDir!!.absolutePath
|
|
45
|
+
bridgeGnoNative = Gnonative.newBridge(config)
|
|
46
|
+
|
|
47
|
+
promise.resolve(true)
|
|
48
|
+
} catch (err: CodedException) {
|
|
49
|
+
promise.reject(err)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
AsyncFunction("closeBridge") { promise: Promise ->
|
|
54
|
+
try {
|
|
55
|
+
bridgeGnoNative?.let {
|
|
56
|
+
bridgeGnoNative!!.close()
|
|
57
|
+
bridgeGnoNative = null
|
|
58
|
+
promise.resolve(true)
|
|
59
|
+
} ?: run {
|
|
60
|
+
throw GoBridgeNotStartedError()
|
|
61
|
+
}
|
|
62
|
+
} catch (err: CodedException) {
|
|
63
|
+
promise.reject(err)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
AsyncFunction("getTcpPort") { promise: Promise ->
|
|
68
|
+
try {
|
|
69
|
+
bridgeGnoNative?.let {
|
|
70
|
+
socketPort = bridgeGnoNative!!.tcpPort.toInt()
|
|
71
|
+
promise.resolve(socketPort)
|
|
72
|
+
} ?: run {
|
|
73
|
+
throw GoBridgeNotStartedError()
|
|
74
|
+
}
|
|
75
|
+
} catch (err: CodedException) {
|
|
76
|
+
promise.reject(err)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
AsyncFunction("invokeGrpcMethod") { method: String, jsonMessage: String, promise: Promise ->
|
|
81
|
+
try {
|
|
82
|
+
bridgeGnoNative?.let {
|
|
83
|
+
val promiseBlock: PromiseBlock = PromiseBlock(promise)
|
|
84
|
+
bridgeGnoNative!!.invokeGrpcMethodWithPromiseBlock(promiseBlock, method, jsonMessage)
|
|
85
|
+
} ?: run {
|
|
86
|
+
throw GoBridgeNotStartedError()
|
|
87
|
+
}
|
|
88
|
+
} catch (err: CodedException) {
|
|
89
|
+
promise.reject(err)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
AsyncFunction("createStreamClient") { method: String, jsonMessage: String, promise: Promise ->
|
|
94
|
+
try {
|
|
95
|
+
bridgeGnoNative?.let {
|
|
96
|
+
val promiseBlock: PromiseBlock = PromiseBlock(promise)
|
|
97
|
+
bridgeGnoNative!!.createStreamClientWithPromiseBlock(promiseBlock, method, jsonMessage)
|
|
98
|
+
} ?: run {
|
|
99
|
+
throw GoBridgeNotStartedError()
|
|
100
|
+
}
|
|
101
|
+
} catch (err: CodedException) {
|
|
102
|
+
promise.reject(err)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
AsyncFunction("streamClientReceive") { id: String, promise: Promise ->
|
|
107
|
+
try {
|
|
108
|
+
bridgeGnoNative?.let {
|
|
109
|
+
val promiseBlock: PromiseBlock = PromiseBlock(promise)
|
|
110
|
+
bridgeGnoNative!!.streamClientReceiveWithPromiseBlock(promiseBlock, id)
|
|
111
|
+
} ?: run {
|
|
112
|
+
throw GoBridgeNotStartedError()
|
|
113
|
+
}
|
|
114
|
+
} catch (err: CodedException) {
|
|
115
|
+
promise.reject(err)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
AsyncFunction("closeStreamClient") { id: String, promise: Promise ->
|
|
120
|
+
try {
|
|
121
|
+
bridgeGnoNative?.let {
|
|
122
|
+
val promiseBlock: PromiseBlock = PromiseBlock(promise)
|
|
123
|
+
bridgeGnoNative!!.closeStreamClientWithPromiseBlock(promiseBlock, id)
|
|
124
|
+
} ?: run {
|
|
125
|
+
throw GoBridgeNotStartedError()
|
|
126
|
+
}
|
|
127
|
+
} catch (err: CodedException) {
|
|
128
|
+
promise.reject(err)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Defines a JavaScript function that always returns a Promise and whose native code
|
|
133
|
+
// is by default dispatched on the different thread than the JavaScript runtime runs on.
|
|
134
|
+
AsyncFunction("setValueAsync") { value: String ->
|
|
135
|
+
// Send an event to JavaScript.
|
|
136
|
+
sendEvent("onChange", mapOf(
|
|
137
|
+
"value" to value
|
|
138
|
+
))
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Enables the module to be used as a native view. Definition components that are accepted as part of
|
|
142
|
+
// the view definition: Prop, Events.
|
|
143
|
+
View(GnonativeView::class) {
|
|
144
|
+
// Defines a setter for the `name` prop.
|
|
145
|
+
Prop("name") { view: GnonativeView, prop: String ->
|
|
146
|
+
println(prop)
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
package land.gno.gnonative
|
|
2
|
+
import expo.modules.kotlin.exception.CodedException
|
|
3
|
+
|
|
4
|
+
class GoBridgeNotStartedError : CodedException("NotStarted", "Service hasn't started yet", null)
|
|
5
|
+
class GoBridgeCoreError(err: Exception?) : CodedException("CoreError", err)
|
|
6
|
+
class GoBridgeCoreEOF : CodedException("EOF", "EOF", null)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
package land.gno.gnonative
|
|
2
|
+
|
|
3
|
+
// Created by Guilhem Fanton on 10/07/2023.
|
|
4
|
+
|
|
5
|
+
import expo.modules.kotlin.Promise
|
|
6
|
+
import expo.modules.kotlin.exception.CodedException
|
|
7
|
+
import gnolang.gno.gnonative.PromiseBlock as IPromiseBlock
|
|
8
|
+
|
|
9
|
+
class PromiseBlock(val promise: Promise): IPromiseBlock {
|
|
10
|
+
// gnolang.gno.gnonative.PromiseBlock aims to keep reference over promise object so go can play with
|
|
11
|
+
// until the promise is resolved
|
|
12
|
+
companion object {
|
|
13
|
+
private var promises = mutableSetOf<PromiseBlock>()
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
init {
|
|
17
|
+
store()
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
override fun callResolve(reply: String?) {
|
|
21
|
+
this.promise.resolve(reply ?: "")
|
|
22
|
+
this.remove() // cleanup the promise
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
override fun callReject(err: Exception?) {
|
|
26
|
+
if (err?.message == "EOF") {
|
|
27
|
+
this.promise.reject(GoBridgeCoreEOF())
|
|
28
|
+
} else {
|
|
29
|
+
this.promise.reject(GoBridgeCoreError(err))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
this.remove() // cleanup the promise
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private fun store() {
|
|
36
|
+
promises.add(this)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private fun remove() {
|
|
40
|
+
promises.remove(this)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Gnonative.types.d.ts","sourceRoot":"","sources":["../src/Gnonative.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Gnonative.types.js","sourceRoot":"","sources":["../src/Gnonative.types.ts"],"names":[],"mappings":"","sourcesContent":["export type ChangeEventPayload = {\n value: string;\n};\n\nexport type GnonativeViewProps = {\n name: string;\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GnonativeModule.d.ts","sourceRoot":"","sources":["../src/GnonativeModule.ts"],"names":[],"mappings":";AAIA,wBAAgD"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { requireNativeModule } from 'expo-modules-core';
|
|
2
|
+
// It loads the native module object from the JSI or falls back to
|
|
3
|
+
// the bridge module (from NativeModulesProxy) if the remote debugger is on.
|
|
4
|
+
export default requireNativeModule('Gnonative');
|
|
5
|
+
//# sourceMappingURL=GnonativeModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GnonativeModule.js","sourceRoot":"","sources":["../src/GnonativeModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,kEAAkE;AAClE,4EAA4E;AAC5E,eAAe,mBAAmB,CAAC,WAAW,CAAC,CAAC","sourcesContent":["import { requireNativeModule } from 'expo-modules-core';\n\n// It loads the native module object from the JSI or falls back to\n// the bridge module (from NativeModulesProxy) if the remote debugger is on.\nexport default requireNativeModule('Gnonative');\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GnonativeModule.web.d.ts","sourceRoot":"","sources":["../src/GnonativeModule.web.ts"],"names":[],"mappings":";;yBAM6B,MAAM,GAAG,QAAQ,IAAI,CAAC;;;AAFnD,wBAQE"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { EventEmitter } from 'expo-modules-core';
|
|
2
|
+
const emitter = new EventEmitter({});
|
|
3
|
+
export default {
|
|
4
|
+
PI: Math.PI,
|
|
5
|
+
async setValueAsync(value) {
|
|
6
|
+
emitter.emit('onChange', { value });
|
|
7
|
+
},
|
|
8
|
+
hello() {
|
|
9
|
+
return 'Hello world! 👋';
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=GnonativeModule.web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GnonativeModule.web.js","sourceRoot":"","sources":["../src/GnonativeModule.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,MAAM,OAAO,GAAG,IAAI,YAAY,CAAC,EAAS,CAAC,CAAC;AAE5C,eAAe;IACb,EAAE,EAAE,IAAI,CAAC,EAAE;IACX,KAAK,CAAC,aAAa,CAAC,KAAa;QAC/B,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IACtC,CAAC;IACD,KAAK;QACH,OAAO,iBAAiB,CAAC;IAC3B,CAAC;CACF,CAAC","sourcesContent":["import { EventEmitter } from 'expo-modules-core';\n\nconst emitter = new EventEmitter({} as any);\n\nexport default {\n PI: Math.PI,\n async setValueAsync(value: string): Promise<void> {\n emitter.emit('onChange', { value });\n },\n hello() {\n return 'Hello world! 👋';\n },\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GnonativeView.d.ts","sourceRoot":"","sources":["../src/GnonativeView.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAKvD,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,KAAK,EAAE,kBAAkB,qBAE9D"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { requireNativeViewManager } from 'expo-modules-core';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
const NativeView = requireNativeViewManager('Gnonative');
|
|
4
|
+
export default function GnonativeView(props) {
|
|
5
|
+
return <NativeView {...props}/>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=GnonativeView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GnonativeView.js","sourceRoot":"","sources":["../src/GnonativeView.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,MAAM,UAAU,GACd,wBAAwB,CAAC,WAAW,CAAC,CAAC;AAExC,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,KAAyB;IAC7D,OAAO,CAAC,UAAU,CAAC,IAAI,KAAK,CAAC,EAAG,CAAC;AACnC,CAAC","sourcesContent":["import { requireNativeViewManager } from 'expo-modules-core';\nimport * as React from 'react';\n\nimport { GnonativeViewProps } from './Gnonative.types';\n\nconst NativeView: React.ComponentType<GnonativeViewProps> =\n requireNativeViewManager('Gnonative');\n\nexport default function GnonativeView(props: GnonativeViewProps) {\n return <NativeView {...props} />;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GnonativeView.web.d.ts","sourceRoot":"","sources":["../src/GnonativeView.web.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,KAAK,EAAE,kBAAkB,qBAM9D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GnonativeView.web.js","sourceRoot":"","sources":["../src/GnonativeView.web.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,KAAyB;IAC7D,OAAO,CACL,CAAC,GAAG,CACF;MAAA,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,CAC1B;IAAA,EAAE,GAAG,CAAC,CACP,CAAC;AACJ,CAAC","sourcesContent":["import * as React from 'react';\n\nimport { GnonativeViewProps } from './Gnonative.types';\n\nexport default function GnonativeView(props: GnonativeViewProps) {\n return (\n <div>\n <span>{props.name}</span>\n </div>\n );\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface GoBridgeInterface {
|
|
2
|
+
initBridge(): Promise<void>;
|
|
3
|
+
closeBridge(): Promise<void>;
|
|
4
|
+
getTcpPort(): Promise<number>;
|
|
5
|
+
invokeGrpcMethod(method: string, jsonMessage: string): Promise<string>;
|
|
6
|
+
createStreamClient(method: string, jsonMessage: string): Promise<string>;
|
|
7
|
+
streamClientReceive(id: string): Promise<string>;
|
|
8
|
+
closeStreamClient(id: string): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
declare const goBridge: GoBridgeInterface;
|
|
11
|
+
export { goBridge as GoBridge };
|
|
12
|
+
//# sourceMappingURL=GoBridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GoBridge.d.ts","sourceRoot":"","sources":["../src/GoBridge.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,iBAAiB;IAChC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9B,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACvE,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACzE,mBAAmB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACjD,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9C;AAgCD,QAAA,MAAM,QAAQ,EAAE,iBAAkC,CAAC;AACnD,OAAO,EAAE,QAAQ,IAAI,QAAQ,EAAE,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import GnonativeModule from './GnonativeModule';
|
|
2
|
+
class GoBridge {
|
|
3
|
+
initBridge() {
|
|
4
|
+
return GnonativeModule.initBridge();
|
|
5
|
+
}
|
|
6
|
+
closeBridge() {
|
|
7
|
+
return GnonativeModule.closeBridge();
|
|
8
|
+
}
|
|
9
|
+
getTcpPort() {
|
|
10
|
+
return GnonativeModule.getTcpPort();
|
|
11
|
+
}
|
|
12
|
+
invokeGrpcMethod(method, jsonMessage) {
|
|
13
|
+
return GnonativeModule.invokeGrpcMethod(method, jsonMessage);
|
|
14
|
+
}
|
|
15
|
+
createStreamClient(method, jsonMessage) {
|
|
16
|
+
return GnonativeModule.createStreamClient(method, jsonMessage);
|
|
17
|
+
}
|
|
18
|
+
streamClientReceive(id) {
|
|
19
|
+
return GnonativeModule.streamClientReceive(id);
|
|
20
|
+
}
|
|
21
|
+
closeStreamClient(id) {
|
|
22
|
+
return GnonativeModule.closeStreamClient(id);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const goBridge = new GoBridge();
|
|
26
|
+
export { goBridge as GoBridge };
|
|
27
|
+
//# sourceMappingURL=GoBridge.js.map
|