@expo-harmony/expo-modules-core 55.0.25-harmony.1

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.
@@ -0,0 +1 @@
1
+ harmony/library/src/main/cpp/common/**/*
package/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # @expo-harmony/expo-modules-core
2
+
3
+ [**GitHub 仓库**](https://github.com/renbaoshuo/expo-harmony/tree/master/packages/expo-modules-core)
4
+
5
+ 为 HarmonyOS 上的 React Native 应用提供 Expo Modules Core 所需的原生运行时、HAR 和 C++ 开发入口,与官方同版本的 expo-modules-core 配套使用。
6
+
7
+ ## Author
8
+
9
+ **expo-harmony** © [Baoshuo](https://github.com/renbaoshuo), Released under the [MIT](./LICENSE) License.<br>
10
+ Authored and maintained by Baoshuo with help from [contributors](https://github.com/renbaoshuo/expo-harmony/contributors).
11
+
12
+ > [Personal Website](https://baoshuo.ren) · [Blog](https://blog.baoshuo.ren) · GitHub [@renbaoshuo](https://github.com/renbaoshuo) · Twitter [@baoshuo](https://twitter.com/baoshuo)
Binary file
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/index.js ADDED
@@ -0,0 +1,3 @@
1
+ 'use strict';
2
+
3
+ module.exports = Object.freeze({});
@@ -0,0 +1,7 @@
1
+ const expoModulesCore = global.__turboModuleProxy?.('ExpoModulesCore')
2
+ ?? global.nativeModuleProxy?.ExpoModulesCore;
3
+
4
+ if (typeof expoModulesCore?.installModules !== 'function') {
5
+ throw new Error('ExpoModulesCore is not linked into the RNOH runtime.');
6
+ }
7
+ expoModulesCore.installModules();
package/package.json ADDED
@@ -0,0 +1,78 @@
1
+ {
2
+ "name": "@expo-harmony/expo-modules-core",
3
+ "version": "55.0.25-harmony.1",
4
+ "description": "HarmonyOS port of expo-modules-core",
5
+ "keywords": [
6
+ "react-native",
7
+ "expo",
8
+ "expo-harmony",
9
+ "harmonyos"
10
+ ],
11
+ "author": "Baoshuo <i@baoshuo.ren>",
12
+ "license": "MIT",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/renbaoshuo/expo-harmony.git",
16
+ "directory": "packages/expo-modules-core"
17
+ },
18
+ "homepage": "https://github.com/renbaoshuo/expo-harmony/tree/master/packages/expo-modules-core#readme",
19
+ "bugs": "https://github.com/renbaoshuo/expo-harmony/issues",
20
+ "main": "src/index.ts",
21
+ "types": "index.d.ts",
22
+ "scripts": {
23
+ "harmony:clean": "expo-harmony-module prepare --clean-only",
24
+ "harmony:build": "expo-harmony-module prepare",
25
+ "prepack": "yarn harmony:build"
26
+ },
27
+ "peerDependencies": {
28
+ "@react-native-oh/react-native-harmony": "0.84.1",
29
+ "@react-native-ohos/react-native-worklets": "1.0.0",
30
+ "expo-modules-core": "55.0.25",
31
+ "react-native-worklets": "^0.7.4 || ^0.8.0"
32
+ },
33
+ "peerDependenciesMeta": {
34
+ "@react-native-ohos/react-native-worklets": {
35
+ "optional": true
36
+ },
37
+ "react-native-worklets": {
38
+ "optional": true
39
+ }
40
+ },
41
+ "devDependencies": {
42
+ "@expo-harmony/expo-module-scripts": "55.0.0-harmony.0",
43
+ "@react-native-oh/react-native-harmony": "0.84.1",
44
+ "@react-native-ohos/react-native-worklets": "1.0.0",
45
+ "expo-modules-core": "55.0.25",
46
+ "react": "19.2.3",
47
+ "react-native": "0.84.1",
48
+ "react-native-worklets": "0.7.4"
49
+ },
50
+ "engines": {
51
+ "node": ">=20"
52
+ },
53
+ "publishConfig": {
54
+ "access": "public"
55
+ },
56
+ "harmony": {
57
+ "alias": "expo-modules-core",
58
+ "redirectInternalImports": true,
59
+ "autolinking": {
60
+ "mainHarPath": "harmony",
61
+ "ohPackageName": "@expo-harmony/expo-modules-core",
62
+ "etsPackageClassName": "ExpoModulesCorePackage",
63
+ "cppPackageClassName": "ExpoModulesCorePackage",
64
+ "cmakeLibraryTargetName": "expo_harmony__expo_modules_core"
65
+ },
66
+ "modules": {
67
+ "@react-native-ohos/react-native-worklets": {
68
+ "version": "1.0.0",
69
+ "mainHarPath": "harmony",
70
+ "ohPackageName": "@react-native-ohos/react-native-worklets",
71
+ "etsPackageClassName": "ReanimatedWorkletPackage",
72
+ "etsPackageImport": "named",
73
+ "cppPackageClassName": "ReanimatedWorkletPackage",
74
+ "cmakeLibraryTargetName": "rnoh_worklets"
75
+ }
76
+ }
77
+ }
78
+ }
@@ -0,0 +1,6 @@
1
+ import type { ComponentType } from 'react';
2
+
3
+ export declare function requireNativeViewManager<P>(
4
+ moduleName: string,
5
+ viewName?: string
6
+ ): ComponentType<P>;
@@ -0,0 +1,141 @@
1
+ 'use strict';
2
+
3
+ const React = require('react');
4
+ const ReactNative = require('react-native');
5
+ const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry');
6
+
7
+ const EXPO_VIEW_COMPONENT_NAME = 'ViewManagerAdapter_ExpoModulesCore';
8
+ const nativeComponentsCache = new Map();
9
+ const propsRevisions = new WeakMap();
10
+ let nextPropsRevision = 1;
11
+
12
+ function getExpoGlobal() {
13
+ return globalThis.expo;
14
+ }
15
+
16
+ function expoLogicalComponentName(moduleName, viewName) {
17
+ return viewName
18
+ ? `ViewManagerAdapter_${moduleName}_${viewName}`
19
+ : `ViewManagerAdapter_${moduleName}`;
20
+ }
21
+
22
+ function expoViewPropsRevision(props) {
23
+ const existing = propsRevisions.get(props);
24
+ if (existing !== undefined) return existing;
25
+
26
+ if (!Number.isSafeInteger(nextPropsRevision)) {
27
+ throw new Error('Expo View props revision identity space was exhausted.');
28
+ }
29
+
30
+ const revision = nextPropsRevision;
31
+ nextPropsRevision += 1;
32
+ propsRevisions.set(props, revision);
33
+
34
+ return revision;
35
+ }
36
+
37
+ function ensureNativeModulesAreInstalled() {
38
+ if (getExpoGlobal()) return;
39
+
40
+ const core = ReactNative.TurboModuleRegistry.get('ExpoModulesCore');
41
+ if (!core || typeof core.installModules !== 'function') {
42
+ throw new Error('Unable to install Expo modules: ExpoModulesCore.installModules() is unavailable.');
43
+ }
44
+
45
+ try {
46
+ core.installModules();
47
+ } catch (error) {
48
+ throw new Error(`Unable to install Expo modules: ${error}`);
49
+ }
50
+
51
+ if (!getExpoGlobal()) {
52
+ throw new Error('Unable to install Expo modules: the native installer did not create globalThis.expo.');
53
+ }
54
+ }
55
+
56
+ function requireExpoViewComponent(moduleName, viewName) {
57
+ const name = expoLogicalComponentName(moduleName, viewName);
58
+ const appId = getExpoGlobal()?.__expo_app_identifier__ ?? '';
59
+ const key = appId ? `${name}_${appId}` : name;
60
+ const cached = nativeComponentsCache.get(key);
61
+ if (cached) return cached;
62
+
63
+ const component = NativeComponentRegistry.get(key, () => {
64
+ const config = getExpoGlobal()?.getViewConfig?.(moduleName, viewName);
65
+ if (!config) {
66
+ throw new Error(`Unable to get the view config for ${viewName ?? 'default view'} from module ${moduleName}.`);
67
+ }
68
+
69
+ return {
70
+ ...config,
71
+ uiViewClassName: EXPO_VIEW_COMPONENT_NAME,
72
+ validAttributes: {
73
+ ...config?.validAttributes,
74
+ expoModuleName: true,
75
+ expoViewRevision: true,
76
+ expoViewName: true,
77
+ },
78
+ };
79
+ });
80
+
81
+ nativeComponentsCache.set(key, component);
82
+
83
+ return component;
84
+ }
85
+
86
+ function requireNativeViewManager(moduleName, viewName) {
87
+ ensureNativeModulesAreInstalled();
88
+
89
+ const ReactNativeComponent = requireExpoViewComponent(moduleName, viewName);
90
+
91
+ class NativeComponent extends React.PureComponent {
92
+ static displayName = viewName ?? moduleName;
93
+
94
+ nativeRef = React.createRef();
95
+ nativeTag = null;
96
+ committedPropsRevision = 0;
97
+ nativeComponentName = expoLogicalComponentName(moduleName, viewName);
98
+
99
+ get nativePropsRevision() {
100
+ return this.committedPropsRevision;
101
+ }
102
+
103
+ componentDidMount() {
104
+ this.committedPropsRevision = propsRevisions.get(this.props) ?? this.committedPropsRevision;
105
+ this.nativeTag = ReactNative.findNodeHandle(this.nativeRef.current);
106
+ }
107
+
108
+ componentDidUpdate() {
109
+ this.committedPropsRevision = propsRevisions.get(this.props) ?? this.committedPropsRevision;
110
+ }
111
+
112
+ componentWillUnmount() {
113
+ this.nativeTag = null;
114
+ }
115
+
116
+ render() {
117
+ return React.createElement(ReactNativeComponent, {
118
+ ...this.props,
119
+ expoModuleName: moduleName,
120
+ expoViewRevision: expoViewPropsRevision(this.props),
121
+ expoViewName: viewName ?? '',
122
+ ref: this.nativeRef,
123
+ });
124
+ }
125
+ }
126
+
127
+ try {
128
+ const nativeModule = getExpoGlobal()?.modules?.[moduleName];
129
+ const prototypeName = viewName ? `${moduleName}_${viewName}` : moduleName;
130
+ const nativeViewPrototype = nativeModule?.ViewPrototypes?.[prototypeName];
131
+ if (nativeViewPrototype) {
132
+ Object.assign(NativeComponent.prototype, nativeViewPrototype);
133
+ }
134
+ } catch {
135
+ // Match Expo's behavior for tests and runtimes with incomplete module mocks.
136
+ }
137
+
138
+ return NativeComponent;
139
+ }
140
+
141
+ exports.requireNativeViewManager = requireNativeViewManager;
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from 'expo-modules-core';