@react-native-ohos/react-native-bindingx 1.0.4-rc.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.
Files changed (38) hide show
  1. package/LICENSE.md +13 -0
  2. package/README.OpenSource +11 -0
  3. package/README.md +14 -0
  4. package/harmony/bindingx/BuildProfile.ets +5 -0
  5. package/harmony/bindingx/build-profile.json5 +9 -0
  6. package/harmony/bindingx/hvigorfile.ts +2 -0
  7. package/harmony/bindingx/index.ets +25 -0
  8. package/harmony/bindingx/oh-package.json5 +12 -0
  9. package/harmony/bindingx/src/main/cpp/CMakeLists.txt +8 -0
  10. package/harmony/bindingx/src/main/cpp/ExpressHandleEval.cpp +176 -0
  11. package/harmony/bindingx/src/main/cpp/ExpressHandleEval.h +51 -0
  12. package/harmony/bindingx/src/main/cpp/ReactBindingXModule.cpp +42 -0
  13. package/harmony/bindingx/src/main/cpp/ReactBindingXModule.h +38 -0
  14. package/harmony/bindingx/src/main/cpp/ReactBindingXPackage.cpp +53 -0
  15. package/harmony/bindingx/src/main/cpp/ReactBindingXPackage.h +37 -0
  16. package/harmony/bindingx/src/main/cpp/ReactBindingxArkTSMessageHandler.cpp +563 -0
  17. package/harmony/bindingx/src/main/cpp/ReactBindingxArkTSMessageHandler.h +78 -0
  18. package/harmony/bindingx/src/main/ets/BindingXCore.ts +477 -0
  19. package/harmony/bindingx/src/main/ets/BindingXParamBean.ts +37 -0
  20. package/harmony/bindingx/src/main/ets/IRNViewUpdater.ts +45 -0
  21. package/harmony/bindingx/src/main/ets/ReactBindingXModule.ts +71 -0
  22. package/harmony/bindingx/src/main/ets/ReactBindingXPackage.ts +46 -0
  23. package/harmony/bindingx/src/main/ets/TimingFunctions.ts +281 -0
  24. package/harmony/bindingx/src/main/ets/TimingFunctionsType.ts +58 -0
  25. package/harmony/bindingx/src/main/ets/TimingFunctionsTypeHandler.ts +128 -0
  26. package/harmony/bindingx/src/main/module.json5 +7 -0
  27. package/harmony/bindingx/src/main/resources/base/element/color.json +8 -0
  28. package/harmony/bindingx/src/main/resources/base/element/string.json +16 -0
  29. package/harmony/bindingx/src/main/resources/base/media/icon.png +0 -0
  30. package/harmony/bindingx/src/main/resources/base/profile/main_pages.json +5 -0
  31. package/harmony/bindingx/src/main/resources/en_US/element/string.json +16 -0
  32. package/harmony/bindingx/src/main/resources/zh_CN/element/string.json +16 -0
  33. package/harmony/bindingx/ts.ts +26 -0
  34. package/harmony/bindingx.har +0 -0
  35. package/lib/index.js +3 -0
  36. package/lib/specs/NativeReactBindingXModule.ts +12 -0
  37. package/lib/src/bindingx.js +131 -0
  38. package/package.json +27 -0
@@ -0,0 +1,131 @@
1
+ /**
2
+ Copyright 2018 Alibaba Group
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+ 'use strict';
18
+
19
+ import {parse} from 'bindingx-parser';
20
+ import {NativeEventEmitter, DeviceEventEmitter, Platform} from 'react-native';
21
+
22
+ import NativeModules from '../specs/NativeReactBindingXModule'
23
+
24
+ const nativeBindingX = NativeModules;
25
+ let bindingx = {
26
+ __instances__: {},
27
+ /**
28
+ * bind
29
+ * @param options
30
+ * @example
31
+ {
32
+ anchor:blockRef,
33
+ eventType:'pan',
34
+ props: [
35
+ {
36
+ element:blockRef,
37
+ property:'transform.translateX',
38
+ expression:"x+1"
39
+ }
40
+ ]
41
+ }
42
+ */
43
+ bind(options, callback = function () {}) {
44
+ if (!options) {
45
+ throw new Error('should pass options for binding');
46
+ }
47
+ if(Platform.OS != "harmony"){
48
+ options.exitExpression = formatExpression(options.exitExpression);
49
+ console.log('options:',options)
50
+ if (options.props) {
51
+ options.props.forEach((prop) => {
52
+ prop.expression = formatExpression(prop.expression);
53
+ });
54
+ }
55
+ }
56
+ let res;
57
+ if (nativeBindingX) {
58
+ res = nativeBindingX.bind(options);
59
+ let token = res && res.token;
60
+ if(Platform.OS == "harmony"){
61
+ token = res;
62
+ }
63
+ this.__instances__[token] = {
64
+ callback
65
+ };
66
+ }
67
+ return res;
68
+ },
69
+ /**
70
+ * @param {object} options
71
+ * @example
72
+ * {eventType:'pan',
73
+ * token:self.gesToken}
74
+ */
75
+ unbind(options) {
76
+ if (!options) {
77
+ throw new Error('should pass options for binding');
78
+ }
79
+ return nativeBindingX.unbind(options);
80
+ },
81
+ unbindAll() {
82
+ return nativeBindingX.unbindAll();
83
+ },
84
+ prepare(options) {
85
+ return nativeBindingX.prepare(options);
86
+ },
87
+ getComputedStyle(el) {
88
+ return nativeBindingX.getComputedStyle(el);
89
+ },
90
+ // { y: 0, state: 'start', x: 0, token: '592' }
91
+ __triggerCallback: (event) => {
92
+ let instances = bindingx.__instances__;
93
+ if (event && event.token &&
94
+ instances[event.token] &&
95
+ typeof instances[event.token].callback == 'function') {
96
+ // trigger global event for callback function
97
+ instances[event.token].callback(event);
98
+ }
99
+ }
100
+ };
101
+
102
+
103
+ if (Platform.OS == 'ios') {
104
+ const bindingXEmitter = new NativeEventEmitter(nativeBindingX);
105
+ bindingXEmitter.addListener('bindingx:statechange', bindingx.__triggerCallback);
106
+ } else {
107
+ DeviceEventEmitter.addListener('bindingx:statechange', bindingx.__triggerCallback);
108
+ }
109
+
110
+
111
+ function formatExpression(expression) {
112
+ if (expression === undefined) return;
113
+ try {
114
+ expression = JSON.parse(expression);
115
+ } catch (err) {
116
+
117
+ }
118
+ let resultExpression = {};
119
+ if (typeof expression === 'string') {
120
+ resultExpression.origin = expression;
121
+ } else if (expression) {
122
+ resultExpression.origin = expression.origin;
123
+ resultExpression.transformed = expression.transformed;
124
+ }
125
+ if (!resultExpression.transformed && !resultExpression.origin) return;
126
+ resultExpression.transformed = resultExpression.transformed || parse(resultExpression.origin);
127
+ return resultExpression;
128
+ }
129
+
130
+
131
+ export default bindingx;
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@react-native-ohos/react-native-bindingx",
3
+ "version": "1.0.4-rc.1",
4
+ "scripts": {
5
+ "prepublish": "",
6
+ "test": "jest"
7
+ },
8
+ "main": "lib/index.js",
9
+ "nativePackage": true,
10
+ "harmony": {
11
+ "alias":"react-native-bindingx"
12
+ },
13
+ "dependencies": {
14
+ "bindingx-parser": "^0.0.2"
15
+ },
16
+ "jest": {
17
+ "preset": "react-native"
18
+ },
19
+ "files": [
20
+ "lib",
21
+ "harmony"
22
+ ],
23
+ "publishConfig": {
24
+ "registry": "https://registry.npmjs.org/",
25
+ "access": "public"
26
+ }
27
+ }