expo-module-template 10.3.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/$package.json CHANGED
@@ -5,8 +5,13 @@
5
5
  "main": "build/<%- project.name %>.js",
6
6
  "types": "build/<%- project.name %>.d.ts",
7
7
  "scripts": {
8
- "build": "tsc",
9
- "lint": "eslint ."
8
+ "build": "expo-module build",
9
+ "clean": "expo-module clean",
10
+ "lint": "expo-module lint",
11
+ "test": "expo-module test",
12
+ "prepare": "expo-module prepare",
13
+ "prepublishOnly": "expo-module prepublishOnly",
14
+ "expo-module": "expo-module"
10
15
  },
11
16
  "keywords": ["react-native", "expo", "<%- project.slug %>", "<%- project.name %>"],
12
17
  "repository": "<%- repo %>",
@@ -18,7 +23,8 @@
18
23
  "homepage": "<%- repo %>#readme",
19
24
  "dependencies": {},
20
25
  "devDependencies": {
21
- "expo-module-scripts": "^2.0.0"
26
+ "expo-module-scripts": "^2.0.0",
27
+ "expo-modules-core": "^0.9.0"
22
28
  },
23
29
  "peerDependencies": {
24
30
  "expo": "*"
@@ -1,66 +1,79 @@
1
1
  apply plugin: 'com.android.library'
2
2
  apply plugin: 'kotlin-android'
3
3
  apply plugin: 'kotlin-android-extensions'
4
- apply plugin: 'maven'
4
+ apply plugin: 'maven-publish'
5
5
 
6
6
  group = '<%- project.package %>'
7
7
  version = '<%- project.version %>'
8
8
 
9
9
  buildscript {
10
+ def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
11
+ if (expoModulesCorePlugin.exists()) {
12
+ apply from: expoModulesCorePlugin
13
+ applyKotlinExpoModulesCorePlugin()
14
+ }
15
+
10
16
  // Simple helper that allows the root project to override versions declared by this library.
11
17
  ext.safeExtGet = { prop, fallback ->
12
18
  rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
13
19
  }
14
20
 
21
+ // Ensures backward compatibility
22
+ ext.getKotlinVersion = {
23
+ if (ext.has("kotlinVersion")) {
24
+ ext.kotlinVersion()
25
+ } else {
26
+ ext.safeExtGet("kotlinVersion", "1.6.10")
27
+ }
28
+ }
29
+
15
30
  repositories {
16
31
  mavenCentral()
17
32
  }
18
33
 
19
34
  dependencies {
20
- classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${safeExtGet('kotlinVersion', '1.4.21')}")
35
+ classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${getKotlinVersion()}")
21
36
  }
22
37
  }
23
38
 
24
- // Upload android library to maven with javadoc and android sources
25
- configurations {
26
- deployerJars
27
- }
28
-
29
39
  // Creating sources with comments
30
40
  task androidSourcesJar(type: Jar) {
31
41
  classifier = 'sources'
32
42
  from android.sourceSets.main.java.srcDirs
33
43
  }
34
44
 
35
- // Put the androidSources and javadoc to the artifacts
36
- artifacts {
37
- archives androidSourcesJar
38
- }
39
-
40
- uploadArchives {
41
- repositories {
42
- mavenDeployer {
43
- configuration = configurations.deployerJars
44
- repository(url: mavenLocal().url)
45
+ afterEvaluate {
46
+ publishing {
47
+ publications {
48
+ release(MavenPublication) {
49
+ from components.release
50
+ // Add additional sourcesJar to artifacts
51
+ artifact(androidSourcesJar)
52
+ }
53
+ }
54
+ repositories {
55
+ maven {
56
+ url = mavenLocal().url
57
+ }
45
58
  }
46
59
  }
47
60
  }
48
61
 
49
62
  android {
50
- compileSdkVersion safeExtGet("compileSdkVersion", 30)
63
+ compileSdkVersion safeExtGet("compileSdkVersion", 31)
51
64
 
52
65
  compileOptions {
53
- sourceCompatibility JavaVersion.VERSION_1_8
54
- targetCompatibility JavaVersion.VERSION_1_8
66
+ sourceCompatibility JavaVersion.VERSION_11
67
+ targetCompatibility JavaVersion.VERSION_11
55
68
  }
56
-
69
+
57
70
  kotlinOptions {
58
- jvmTarget = JavaVersion.VERSION_1_8
71
+ jvmTarget = JavaVersion.VERSION_11.majorVersion
59
72
  }
60
73
 
61
74
  defaultConfig {
62
75
  minSdkVersion safeExtGet("minSdkVersion", 21)
63
- targetSdkVersion safeExtGet("targetSdkVersion", 30)
76
+ targetSdkVersion safeExtGet("targetSdkVersion", 31)
64
77
  versionCode 1
65
78
  versionName "<%- project.version %>"
66
79
  }
@@ -75,5 +88,5 @@ repositories {
75
88
 
76
89
  dependencies {
77
90
  implementation project(':expo-modules-core')
78
- implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${safeExtGet('kotlinVersion', '1.4.21')}"
91
+ implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
79
92
  }
@@ -4,19 +4,45 @@ 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 {
8
- name("<%- project.name %>")
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 %>")
9
15
 
10
- function("helloAsync") { options: Map<String, String> ->
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
 
14
- viewManager {
15
- view { context ->
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`.
38
+ ViewManager {
39
+ // Defines the factory creating a native view when the module is used as a view.
40
+ View { context ->
16
41
  <%- project.name %>View(context)
17
42
  }
18
43
 
19
- prop("name") { view: <%- project.name %>View, prop: String ->
44
+ // Defines a setter for the `name` prop.
45
+ Prop("name") { view: <%- project.name %>View, prop: String ->
20
46
  println(prop)
21
47
  }
22
48
  }
@@ -1,19 +1,45 @@
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 {
5
- name("<%- project.name %>")
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 %>")
6
12
 
7
- function("helloAsync") { (options: [String: String]) in
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
 
11
- viewManager {
12
- view {
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`.
35
+ ViewManager {
36
+ // Defines the factory creating a native view when the module is used as a view.
37
+ View {
13
38
  <%- project.name %>View()
14
39
  }
15
40
 
16
- prop("name") { (view: <%- project.name %>View, prop: String) in
41
+ // Defines a setter for the `name` prop.
42
+ Prop("name") { (view: <%- project.name %>View, prop: String) in
17
43
  print(prop)
18
44
  }
19
45
  }
@@ -1,5 +1,7 @@
1
- import UIKit
1
+ import ExpoModulesCore
2
2
 
3
- class <%- project.name %>View: UIView {
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.0",
3
+ "version": "10.6.0",
4
4
  "description": "ExpoModuleTemplate standalone module",
5
5
  "main": "build/ModuleTemplate.js",
6
6
  "types": "build/ModuleTemplate.d.ts",
@@ -22,11 +22,7 @@
22
22
  "license": "MIT",
23
23
  "homepage": "https://docs.expo.dev/versions/latest/sdk/module-template",
24
24
  "dependencies": {},
25
- "devDependencies": {
26
- "expo-module-scripts": "^2.0.0"
27
- },
28
- "peerDependencies": {
29
- "expo": "*"
30
- },
31
- "gitHead": "12f4884904f6a8788964b79a46fa0acbf80917a8"
25
+ "devDependencies": {},
26
+ "peerDependencies": {},
27
+ "gitHead": "8948d665a96976b0817c0d8ce7e3c4009777e95a"
32
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
- const { <%- project.name %> } = NativeModulesProxy;
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
- export async function helloAsync(options: Record<string, string>) {
8
- return await <%- project.name %>.helloAsync(options);
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: number;
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 class <%- project.name %>View extends React.Component<<%- project.name %>ViewProps, <%- project.name %>ViewState> {
14
- render() {
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
  }