expo-module-template 10.5.0 → 10.6.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/src/main/java/{%= project.package %}/{%- project.name %}Module.kt +27 -1
- package/ios/{%- project.name %}Module.swift +27 -1
- package/ios/{%- project.name %}View.swift +4 -2
- package/package.json +2 -2
- package/src/{%- project.name %}.ts +21 -4
- package/src/{%- project.name %}View.tsx +3 -7
|
@@ -4,18 +4,44 @@ import expo.modules.kotlin.modules.Module
|
|
|
4
4
|
import expo.modules.kotlin.modules.ModuleDefinition
|
|
5
5
|
|
|
6
6
|
class <%- project.name %>Module : 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.
|
|
7
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.
|
|
8
14
|
Name("<%- project.name %>")
|
|
9
15
|
|
|
10
|
-
|
|
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 function that always returns a Promise and whose native code
|
|
25
|
+
// is by default dispatched on the different thread than the JavaScript runtime runs on.
|
|
26
|
+
AsyncFunction("setValueAsync") { value: String ->
|
|
11
27
|
println("Hello 👋")
|
|
28
|
+
|
|
29
|
+
// Send an event to JavaScript.
|
|
30
|
+
sendEvent("onChange", mapOf(
|
|
31
|
+
"value" to value
|
|
32
|
+
))
|
|
12
33
|
}
|
|
13
34
|
|
|
35
|
+
// Enables the module to be used as a view manager. The view manager definition is built from
|
|
36
|
+
// the definition components used in the closure passed to viewManager.
|
|
37
|
+
// Definition components that are accepted as part of the view manager definition: `View`, `Prop`.
|
|
14
38
|
ViewManager {
|
|
39
|
+
// Defines the factory creating a native view when the module is used as a view.
|
|
15
40
|
View { context ->
|
|
16
41
|
<%- project.name %>View(context)
|
|
17
42
|
}
|
|
18
43
|
|
|
44
|
+
// Defines a setter for the `name` prop.
|
|
19
45
|
Prop("name") { view: <%- project.name %>View, prop: String ->
|
|
20
46
|
println(prop)
|
|
21
47
|
}
|
|
@@ -1,18 +1,44 @@
|
|
|
1
1
|
import ExpoModulesCore
|
|
2
2
|
|
|
3
3
|
public class <%- project.name %>Module: 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.
|
|
4
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.
|
|
5
11
|
Name("<%- project.name %>")
|
|
6
12
|
|
|
7
|
-
|
|
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 function that always returns a Promise and whose native code
|
|
22
|
+
// is by default dispatched on the different thread than the JavaScript runtime runs on.
|
|
23
|
+
AsyncFunction("setValueAsync") { (value: String) in
|
|
8
24
|
print("Hello 👋")
|
|
25
|
+
|
|
26
|
+
// Send an event to JavaScript.
|
|
27
|
+
sendEvent("onChange", [
|
|
28
|
+
"value": value
|
|
29
|
+
])
|
|
9
30
|
}
|
|
10
31
|
|
|
32
|
+
// Enables the module to be used as a view manager. The view manager definition is built from
|
|
33
|
+
// the definition components used in the closure passed to viewManager.
|
|
34
|
+
// Definition components that are accepted as part of the view manager definition: `View`, `Prop`.
|
|
11
35
|
ViewManager {
|
|
36
|
+
// Defines the factory creating a native view when the module is used as a view.
|
|
12
37
|
View {
|
|
13
38
|
<%- project.name %>View()
|
|
14
39
|
}
|
|
15
40
|
|
|
41
|
+
// Defines a setter for the `name` prop.
|
|
16
42
|
Prop("name") { (view: <%- project.name %>View, prop: String) in
|
|
17
43
|
print(prop)
|
|
18
44
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import ExpoModulesCore
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// This view will be used as a native component. Make sure to inherit from `ExpoView`
|
|
4
|
+
// to apply the proper styling (e.g. border radius and shadows).
|
|
5
|
+
class <%- project.name %>View: ExpoView {
|
|
4
6
|
|
|
5
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-module-template",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.6.0",
|
|
4
4
|
"description": "ExpoModuleTemplate standalone module",
|
|
5
5
|
"main": "build/ModuleTemplate.js",
|
|
6
6
|
"types": "build/ModuleTemplate.d.ts",
|
|
@@ -24,5 +24,5 @@
|
|
|
24
24
|
"dependencies": {},
|
|
25
25
|
"devDependencies": {},
|
|
26
26
|
"peerDependencies": {},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "8948d665a96976b0817c0d8ce7e3c4009777e95a"
|
|
28
28
|
}
|
|
@@ -1,11 +1,28 @@
|
|
|
1
|
-
import { NativeModulesProxy } from 'expo-modules-core';
|
|
1
|
+
import { requireNativeModule, NativeModulesProxy, EventEmitter, Subscription } from 'expo-modules-core';
|
|
2
2
|
|
|
3
3
|
import <%- project.name %>View, { <%- project.name %>ViewProps } from './<%- project.name %>View'
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// It loads the native module object from the JSI or falls back to
|
|
6
|
+
// the bridge module (from NativeModulesProxy) if the remote debugger is on.
|
|
7
|
+
const <%- project.name %> = requireNativeModule('<%- project.name %>');
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
// Get the native constant value.
|
|
10
|
+
export const PI = <%- project.name %>.PI;
|
|
11
|
+
|
|
12
|
+
export async function setValueAsync(value: string) {
|
|
13
|
+
return await <%- project.name %>.setValueAsync(value);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// For now the events are not going through the JSI, so we have to use its bridge equivalent.
|
|
17
|
+
// This will be fixed in the stable release and built into the module object.
|
|
18
|
+
const emitter = new EventEmitter(NativeModulesProxy.<%- project.name %>);
|
|
19
|
+
|
|
20
|
+
export type ChangeEventPayload = {
|
|
21
|
+
value: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export function addChangeListener(listener: (event: ChangeEventPayload) => void): Subscription {
|
|
25
|
+
return emitter.addListener<ChangeEventPayload>('onChange', listener);
|
|
9
26
|
}
|
|
10
27
|
|
|
11
28
|
export {
|
|
@@ -2,16 +2,12 @@ import { requireNativeViewManager } from 'expo-modules-core';
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
|
|
4
4
|
export type <%- project.name %>ViewProps = {
|
|
5
|
-
name:
|
|
5
|
+
name: string;
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
type <%- project.name %>ViewState = {}
|
|
9
|
-
|
|
10
8
|
const NativeView: React.ComponentType<<%- project.name %>ViewProps> =
|
|
11
9
|
requireNativeViewManager('<%- project.name %>');
|
|
12
10
|
|
|
13
|
-
export default
|
|
14
|
-
|
|
15
|
-
return <NativeView name={this.props.name} />;
|
|
16
|
-
}
|
|
11
|
+
export default function <%- project.name %>View(props: <%- project.name %>ViewProps) {
|
|
12
|
+
return <NativeView name={props.name} />;
|
|
17
13
|
}
|