expo-module-template-local 0.1.0
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/android/build.gradle +91 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/{%= project.package %}/{%- project.moduleName %}.kt +47 -0
- package/android/src/main/java/{%= project.package %}/{%- project.viewName %}.kt +7 -0
- package/expo-module.config.json +9 -0
- package/index.ts +26 -0
- package/ios/{%- project.moduleName %}.swift +44 -0
- package/ios/{%- project.name %}.podspec +21 -0
- package/ios/{%- project.viewName %}.swift +7 -0
- package/package.json +26 -0
- package/src/{%- project.moduleName %}.ts +5 -0
- package/src/{%- project.moduleName %}.web.ts +13 -0
- package/src/{%- project.name %}.types.ts +7 -0
- package/src/{%- project.viewName %}.tsx +11 -0
- package/src/{%- project.viewName %}.web.tsx +11 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
apply plugin: 'com.android.library'
|
|
2
|
+
apply plugin: 'kotlin-android'
|
|
3
|
+
apply plugin: 'maven-publish'
|
|
4
|
+
|
|
5
|
+
group = '<%- project.package %>'
|
|
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
|
+
// Creating sources with comments
|
|
39
|
+
task androidSourcesJar(type: Jar) {
|
|
40
|
+
classifier = 'sources'
|
|
41
|
+
from android.sourceSets.main.java.srcDirs
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
afterEvaluate {
|
|
45
|
+
publishing {
|
|
46
|
+
publications {
|
|
47
|
+
release(MavenPublication) {
|
|
48
|
+
from components.release
|
|
49
|
+
// Add additional sourcesJar to artifacts
|
|
50
|
+
artifact(androidSourcesJar)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
repositories {
|
|
54
|
+
maven {
|
|
55
|
+
url = mavenLocal().url
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
android {
|
|
62
|
+
compileSdkVersion safeExtGet("compileSdkVersion", 33)
|
|
63
|
+
|
|
64
|
+
compileOptions {
|
|
65
|
+
sourceCompatibility JavaVersion.VERSION_11
|
|
66
|
+
targetCompatibility JavaVersion.VERSION_11
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
kotlinOptions {
|
|
70
|
+
jvmTarget = JavaVersion.VERSION_11.majorVersion
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
defaultConfig {
|
|
74
|
+
minSdkVersion safeExtGet("minSdkVersion", 21)
|
|
75
|
+
targetSdkVersion safeExtGet("targetSdkVersion", 33)
|
|
76
|
+
versionCode 1
|
|
77
|
+
versionName "0.1.0"
|
|
78
|
+
}
|
|
79
|
+
lintOptions {
|
|
80
|
+
abortOnError false
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
repositories {
|
|
85
|
+
mavenCentral()
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
dependencies {
|
|
89
|
+
implementation project(':expo-modules-core')
|
|
90
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
|
|
91
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
package <%- project.package %>
|
|
2
|
+
|
|
3
|
+
import expo.modules.kotlin.modules.Module
|
|
4
|
+
import expo.modules.kotlin.modules.ModuleDefinition
|
|
5
|
+
|
|
6
|
+
class <%- project.moduleName %> : Module() {
|
|
7
|
+
// Each module class must implement the definition function. The definition consists of components
|
|
8
|
+
// that describes the module's functionality and behavior.
|
|
9
|
+
// See https://docs.expo.dev/modules/module-api for more details about available components.
|
|
10
|
+
override fun definition() = ModuleDefinition {
|
|
11
|
+
// Sets the name of the module that JavaScript code will use to refer to the module. Takes a string as an argument.
|
|
12
|
+
// Can be inferred from module's class name, but it's recommended to set it explicitly for clarity.
|
|
13
|
+
// The module will be accessible from `requireNativeModule('<%- project.name %>')` in JavaScript.
|
|
14
|
+
Name("<%- project.name %>")
|
|
15
|
+
|
|
16
|
+
// Sets constant properties on the module. Can take a dictionary or a closure that returns a dictionary.
|
|
17
|
+
Constants(
|
|
18
|
+
"PI" to Math.PI
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
// Defines event names that the module can send to JavaScript.
|
|
22
|
+
Events("onChange")
|
|
23
|
+
|
|
24
|
+
// Defines a JavaScript synchronous function that runs the native code on the JavaScript thread.
|
|
25
|
+
Function("hello") {
|
|
26
|
+
"Hello world! 👋"
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Defines a JavaScript function that always returns a Promise and whose native code
|
|
30
|
+
// is by default dispatched on the different thread than the JavaScript runtime runs on.
|
|
31
|
+
AsyncFunction("setValueAsync") { value: String ->
|
|
32
|
+
// Send an event to JavaScript.
|
|
33
|
+
sendEvent("onChange", mapOf(
|
|
34
|
+
"value" to value
|
|
35
|
+
))
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Enables the module to be used as a native view. Definition components that are accepted as part of
|
|
39
|
+
// the view definition: Prop, Events.
|
|
40
|
+
View(<%- project.viewName %>::class) {
|
|
41
|
+
// Defines a setter for the `name` prop.
|
|
42
|
+
Prop("name") { view: <%- project.viewName %>, prop: String ->
|
|
43
|
+
println(prop)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
package/index.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { NativeModulesProxy, EventEmitter, Subscription } from 'expo-modules-core';
|
|
2
|
+
|
|
3
|
+
// Import the native module. On web, it will be resolved to <%- project.name %>.web.ts
|
|
4
|
+
// and on native platforms to <%- project.name %>.ts
|
|
5
|
+
import <%- project.moduleName %> from './src/<%- project.moduleName %>';
|
|
6
|
+
import <%- project.viewName %> from './src/<%- project.viewName %>';
|
|
7
|
+
import { ChangeEventPayload, <%- project.viewName %>Props } from './src/<%- project.name %>.types';
|
|
8
|
+
|
|
9
|
+
// Get the native constant value.
|
|
10
|
+
export const PI = <%- project.moduleName %>.PI;
|
|
11
|
+
|
|
12
|
+
export function hello(): string {
|
|
13
|
+
return <%- project.moduleName %>.hello();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function setValueAsync(value: string) {
|
|
17
|
+
return await <%- project.moduleName %>.setValueAsync(value);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const emitter = new EventEmitter(<%- project.moduleName %> ?? NativeModulesProxy.<%- project.name %>);
|
|
21
|
+
|
|
22
|
+
export function addChangeListener(listener: (event: ChangeEventPayload) => void): Subscription {
|
|
23
|
+
return emitter.addListener<ChangeEventPayload>('onChange', listener);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { <%- project.viewName %>, <%- project.viewName %>Props, ChangeEventPayload };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import ExpoModulesCore
|
|
2
|
+
|
|
3
|
+
public class <%- project.moduleName %>: Module {
|
|
4
|
+
// Each module class must implement the definition function. The definition consists of components
|
|
5
|
+
// that describes the module's functionality and behavior.
|
|
6
|
+
// See https://docs.expo.dev/modules/module-api for more details about available components.
|
|
7
|
+
public func definition() -> ModuleDefinition {
|
|
8
|
+
// Sets the name of the module that JavaScript code will use to refer to the module. Takes a string as an argument.
|
|
9
|
+
// Can be inferred from module's class name, but it's recommended to set it explicitly for clarity.
|
|
10
|
+
// The module will be accessible from `requireNativeModule('<%- project.name %>')` in JavaScript.
|
|
11
|
+
Name("<%- project.name %>")
|
|
12
|
+
|
|
13
|
+
// Sets constant properties on the module. Can take a dictionary or a closure that returns a dictionary.
|
|
14
|
+
Constants([
|
|
15
|
+
"PI": Double.pi
|
|
16
|
+
])
|
|
17
|
+
|
|
18
|
+
// Defines event names that the module can send to JavaScript.
|
|
19
|
+
Events("onChange")
|
|
20
|
+
|
|
21
|
+
// Defines a JavaScript synchronous function that runs the native code on the JavaScript thread.
|
|
22
|
+
Function("hello") {
|
|
23
|
+
return "Hello world! 👋"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Defines a JavaScript function that always returns a Promise and whose native code
|
|
27
|
+
// is by default dispatched on the different thread than the JavaScript runtime runs on.
|
|
28
|
+
AsyncFunction("setValueAsync") { (value: String) in
|
|
29
|
+
// Send an event to JavaScript.
|
|
30
|
+
self.sendEvent("onChange", [
|
|
31
|
+
"value": value
|
|
32
|
+
])
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Enables the module to be used as a native view. Definition components that are accepted as part of the
|
|
36
|
+
// view definition: Prop, Events.
|
|
37
|
+
View(<%- project.viewName %>.self) {
|
|
38
|
+
// Defines a setter for the `name` prop.
|
|
39
|
+
Prop("name") { (view: <%- project.viewName %>, prop: String) in
|
|
40
|
+
print(prop)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Pod::Spec.new do |s|
|
|
2
|
+
s.name = '<%- project.name %>'
|
|
3
|
+
s.version = '1.0.0'
|
|
4
|
+
s.summary = 'A sample project summary'
|
|
5
|
+
s.description = 'A sample project description'
|
|
6
|
+
s.author = ''
|
|
7
|
+
s.homepage = 'https://docs.expo.dev/modules/'
|
|
8
|
+
s.platform = :ios, '13.0'
|
|
9
|
+
s.source = { git: '' }
|
|
10
|
+
s.static_framework = true
|
|
11
|
+
|
|
12
|
+
s.dependency 'ExpoModulesCore'
|
|
13
|
+
|
|
14
|
+
# Swift/Objective-C compatibility
|
|
15
|
+
s.pod_target_xcconfig = {
|
|
16
|
+
'DEFINES_MODULE' => 'YES',
|
|
17
|
+
'SWIFT_COMPILATION_MODE' => 'wholemodule'
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
s.source_files = "**/*.{h,m,mm,swift,hpp,cpp}"
|
|
21
|
+
end
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "expo-module-template-local",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "ExpoModuleTemplate standalone module",
|
|
5
|
+
"scripts": {},
|
|
6
|
+
"keywords": [
|
|
7
|
+
"react-native",
|
|
8
|
+
"expo",
|
|
9
|
+
"expo-module-template-local"
|
|
10
|
+
],
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/expo/expo.git",
|
|
14
|
+
"directory": "packages/expo-module-template-local"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/expo/expo/issues"
|
|
18
|
+
},
|
|
19
|
+
"author": "650 Industries, Inc.",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"homepage": "https://docs.expo.dev/modules",
|
|
22
|
+
"dependencies": {},
|
|
23
|
+
"devDependencies": {},
|
|
24
|
+
"peerDependencies": {},
|
|
25
|
+
"gitHead": "5222dff5bbfeb88d610dac5215809285700fb819"
|
|
26
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EventEmitter } from 'expo-modules-core';
|
|
2
|
+
|
|
3
|
+
const emitter = new EventEmitter({} as any);
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
PI: Math.PI,
|
|
7
|
+
async setValueAsync(value: string): Promise<void> {
|
|
8
|
+
emitter.emit('onChange', { value });
|
|
9
|
+
},
|
|
10
|
+
hello() {
|
|
11
|
+
return 'Hello world! 👋';
|
|
12
|
+
},
|
|
13
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { requireNativeViewManager } from 'expo-modules-core';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
|
|
4
|
+
import { <%- project.viewName %>Props } from './<%- project.name %>.types';
|
|
5
|
+
|
|
6
|
+
const NativeView: React.ComponentType<<%- project.viewName %>Props> =
|
|
7
|
+
requireNativeViewManager('<%- project.name %>');
|
|
8
|
+
|
|
9
|
+
export default function <%- project.viewName %>(props: <%- project.viewName %>Props) {
|
|
10
|
+
return <NativeView {...props} />;
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
import { <%- project.viewName %>Props } from './<%- project.name %>.types';
|
|
4
|
+
|
|
5
|
+
export default function <%- project.viewName %>(props: <%- project.viewName %>Props) {
|
|
6
|
+
return (
|
|
7
|
+
<div>
|
|
8
|
+
<span>{props.name}</span>
|
|
9
|
+
</div>
|
|
10
|
+
);
|
|
11
|
+
}
|