expo-module-template 10.6.0 → 10.7.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/$package.json CHANGED
@@ -13,7 +13,12 @@
13
13
  "prepublishOnly": "expo-module prepublishOnly",
14
14
  "expo-module": "expo-module"
15
15
  },
16
- "keywords": ["react-native", "expo", "<%- project.slug %>", "<%- project.name %>"],
16
+ "keywords": [
17
+ "react-native",
18
+ "expo",
19
+ "<%- project.slug %>",
20
+ "<%- project.name %>"
21
+ ],
17
22
  "repository": "<%- repo %>",
18
23
  "bugs": {
19
24
  "url": "<%- repo %>/issues"
@@ -24,9 +29,11 @@
24
29
  "dependencies": {},
25
30
  "devDependencies": {
26
31
  "expo-module-scripts": "^2.0.0",
27
- "expo-modules-core": "^0.9.0"
32
+ "expo-modules-core": "^0.11.3"
28
33
  },
29
34
  "peerDependencies": {
30
- "expo": "*"
35
+ "expo": "*",
36
+ "react": "*",
37
+ "react-native": "*"
31
38
  }
32
39
  }
@@ -21,11 +21,14 @@ class <%- project.name %>Module : Module() {
21
21
  // Defines event names that the module can send to JavaScript.
22
22
  Events("onChange")
23
23
 
24
+ // Defines a JavaScript synchronous function that runs the native code on the JavaScript thread.
25
+ Function("hello") {
26
+ "Hello world! 👋"
27
+ }
28
+
24
29
  // Defines a JavaScript function that always returns a Promise and whose native code
25
30
  // is by default dispatched on the different thread than the JavaScript runtime runs on.
26
31
  AsyncFunction("setValueAsync") { value: String ->
27
- println("Hello 👋")
28
-
29
32
  // Send an event to JavaScript.
30
33
  sendEvent("onChange", mapOf(
31
34
  "value" to value
@@ -0,0 +1,20 @@
1
+ import { StyleSheet, Text, View } from 'react-native';
2
+
3
+ import * as <%- project.name %> from '<%- project.slug %>';
4
+
5
+ export default function App() {
6
+ return (
7
+ <View style={styles.container}>
8
+ <Text>{<%- project.name %>.hello()}</Text>
9
+ </View>
10
+ );
11
+ }
12
+
13
+ const styles = StyleSheet.create({
14
+ container: {
15
+ flex: 1,
16
+ backgroundColor: '#fff',
17
+ alignItems: 'center',
18
+ justifyContent: 'center',
19
+ },
20
+ });
@@ -0,0 +1,19 @@
1
+ const path = require('path');
2
+ module.exports = function (api) {
3
+ api.cache(true);
4
+ return {
5
+ presets: ['babel-preset-expo'],
6
+ plugins: [
7
+ [
8
+ 'module-resolver',
9
+ {
10
+ extensions: ['.tsx', '.ts', '.js', '.json'],
11
+ alias: {
12
+ // For development, we want to alias the library to the source
13
+ '<%- project.slug %>': path.join(__dirname, '..', 'src', '<%- project.name %>.ts'),
14
+ },
15
+ },
16
+ ],
17
+ ],
18
+ };
19
+ };
@@ -0,0 +1,14 @@
1
+ // Learn more https://docs.expo.io/guides/customizing-metro
2
+ const { getDefaultConfig } = require('expo/metro-config');
3
+ const path = require('path');
4
+
5
+ const config = getDefaultConfig(__dirname);
6
+
7
+ config.resolver.nodeModulesPaths = [
8
+ path.resolve(__dirname, './node_modules'),
9
+ path.resolve(__dirname, '../node_modules'),
10
+ ];
11
+
12
+ config.watchFolders = [path.resolve(__dirname, '..')];
13
+
14
+ module.exports = config;
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "expo/tsconfig.base",
3
+ "compilerOptions": {
4
+ "strict": true,
5
+ "paths": {
6
+ "<%- project.slug %>": ["../src/<%- project.name %>"],
7
+ "<%- project.slug %>/*": ["../src/*"]
8
+ }
9
+ }
10
+ }
@@ -0,0 +1,20 @@
1
+ const createConfigAsync = require('@expo/webpack-config');
2
+ const path = require('path');
3
+
4
+ module.exports = async (env, argv) => {
5
+ const config = await createConfigAsync(
6
+ {
7
+ ...env,
8
+ babel: {
9
+ dangerouslyAddModulePathsToTranspile: ['<%- project.slug %>'],
10
+ },
11
+ },
12
+ argv
13
+ );
14
+ config.resolve.modules = [
15
+ path.resolve(__dirname, './node_modules'),
16
+ path.resolve(__dirname, '../node_modules'),
17
+ ];
18
+
19
+ return config;
20
+ };
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "platforms": ["ios", "android", "web"],
3
3
  "ios": {
4
- "modulesClassNames": ["<%- project.name %>Module"]
4
+ "modules": ["<%- project.name %>Module"]
5
5
  },
6
6
  "android": {
7
- "modulesClassNames": ["<%- project.package %>.<%- project.name %>Module"]
7
+ "modules": ["<%- project.package %>.<%- project.name %>Module"]
8
8
  }
9
9
  }
@@ -18,13 +18,16 @@ public class <%- project.name %>Module: Module {
18
18
  // Defines event names that the module can send to JavaScript.
19
19
  Events("onChange")
20
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
+
21
26
  // Defines a JavaScript function that always returns a Promise and whose native code
22
27
  // is by default dispatched on the different thread than the JavaScript runtime runs on.
23
28
  AsyncFunction("setValueAsync") { (value: String) in
24
- print("Hello 👋")
25
-
26
29
  // Send an event to JavaScript.
27
- sendEvent("onChange", [
30
+ self.sendEvent("onChange", [
28
31
  "value": value
29
32
  ])
30
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-module-template",
3
- "version": "10.6.0",
3
+ "version": "10.7.2",
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": "8948d665a96976b0817c0d8ce7e3c4009777e95a"
27
+ "gitHead": "32c35bd146dc1c22fc3c11d3e7ae018701ad3c4c"
28
28
  }
@@ -1,31 +1,29 @@
1
- import { requireNativeModule, NativeModulesProxy, EventEmitter, Subscription } from 'expo-modules-core';
1
+ import { NativeModulesProxy, EventEmitter, Subscription } from 'expo-modules-core';
2
2
 
3
- import <%- project.name %>View, { <%- project.name %>ViewProps } from './<%- project.name %>View'
4
-
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 %>');
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.name %> from './<%- project.name %>Module';
6
+ import <%- project.name %>View from './<%- project.name %>View';
7
+ import { ChangeEventPayload, <%- project.name %>ViewProps } from './<%- project.name %>.types';
8
8
 
9
9
  // Get the native constant value.
10
10
  export const PI = <%- project.name %>.PI;
11
11
 
12
+ export function hello(): string {
13
+ return <%- project.name %>.hello();
14
+ }
15
+
12
16
  export async function setValueAsync(value: string) {
13
17
  return await <%- project.name %>.setValueAsync(value);
14
18
  }
15
19
 
16
20
  // For now the events are not going through the JSI, so we have to use its bridge equivalent.
17
21
  // 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
- };
22
+ // Note: On web, NativeModulesProxy.<%- project.name %> is undefined, so we fall back to the directly imported implementation
23
+ const emitter = new EventEmitter(NativeModulesProxy.<%- project.name %> ?? <%- project.name %>);
23
24
 
24
25
  export function addChangeListener(listener: (event: ChangeEventPayload) => void): Subscription {
25
26
  return emitter.addListener<ChangeEventPayload>('onChange', listener);
26
27
  }
27
28
 
28
- export {
29
- <%- project.name %>View,
30
- <%- project.name %>ViewProps
31
- };
29
+ export { <%- project.name %>View, <%- project.name %>ViewProps, ChangeEventPayload };
@@ -0,0 +1,7 @@
1
+ export type ChangeEventPayload = {
2
+ value: string;
3
+ };
4
+
5
+ export type <%- project.name %>ViewProps = {
6
+ name: string;
7
+ };
@@ -0,0 +1,5 @@
1
+ import { requireNativeModule } from 'expo-modules-core';
2
+
3
+ // It loads the native module object from the JSI or falls back to
4
+ // the bridge module (from NativeModulesProxy) if the remote debugger is on.
5
+ export default requireNativeModule('<%- project.name %>');
@@ -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
+ };
@@ -1,9 +1,7 @@
1
1
  import { requireNativeViewManager } from 'expo-modules-core';
2
2
  import * as React from 'react';
3
3
 
4
- export type <%- project.name %>ViewProps = {
5
- name: string;
6
- };
4
+ import { <%- project.name %>ViewProps } from './<%- project.name %>.types';
7
5
 
8
6
  const NativeView: React.ComponentType<<%- project.name %>ViewProps> =
9
7
  requireNativeViewManager('<%- project.name %>');
@@ -0,0 +1,13 @@
1
+ import * as React from 'react';
2
+
3
+ import { <%- project.name %>ViewProps } from './<%- project.name %>.types';
4
+
5
+ function <%- project.name %>WebView(props: <%- project.name %>ViewProps) {
6
+ return (
7
+ <div>
8
+ <span>{props.name}</span>
9
+ </div>
10
+ );
11
+ }
12
+
13
+ export default <%- project.name %>WebView;
package/tsconfig.json CHANGED
@@ -5,5 +5,5 @@
5
5
  "outDir": "./build"
6
6
  },
7
7
  "include": ["./src"],
8
- "exclude": ["**/__mocks__/*", "**/__tests__/*"]
8
+ "exclude": ["**/__mocks__/*", "**/__tests__/*", "**/__stories__/*"]
9
9
  }
package/babel.config.js DELETED
@@ -1,6 +0,0 @@
1
- module.exports = function (api) {
2
- api.cache(true);
3
- return {
4
- presets: ['babel-preset-expo'],
5
- };
6
- };