@ray-js/components 1.7.56-beta.1 → 1.7.56-beta.3

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,21 @@
1
+ /**
2
+ * Animated - 纯净底层动画组件
3
+ *
4
+ * 只提供三个核心方法:
5
+ * - setProperty(property, value): 设置动画属性
6
+ * - setStyle(style): 设置样式
7
+ * - setText(text): 设置文本内容
8
+ *
9
+ * 可以配合任何动画库使用(GSAP、Anime.js、Framer Motion 等)
10
+ */
11
+ import React from 'react';
12
+ import type { AnimatedViewRef, AnimatedTextRef, AnimatedProps } from './types';
13
+ /**
14
+ * 默认导出
15
+ */
16
+ declare const Animated: {
17
+ View: React.ForwardRefExoticComponent<Omit<AnimatedProps, "mode"> & React.RefAttributes<AnimatedViewRef>>;
18
+ Text: React.ForwardRefExoticComponent<Omit<AnimatedProps, "mode"> & React.RefAttributes<AnimatedTextRef>>;
19
+ };
20
+ export default Animated;
21
+ export type { AnimatedViewRef, AnimatedTextRef, AnimatedProps } from './types';
@@ -136,10 +136,11 @@ const AnimatedBase = /*#__PURE__*/forwardRef((props, ref) => {
136
136
  } = _ref2,
137
137
  option = _objectWithoutProperties(_ref2, _excluded);
138
138
  if (finish && typeof finish === 'function') {
139
- callbackRef.current = event => {
140
- finish(event);
141
- callbackRef.current = null;
142
- };
139
+ callbackRef.current = finish;
140
+ } else {
141
+ // 如果没有传 finish 参数,清空之前的回调
142
+ // 避免 duration: 0 的重置动画再次触发之前的 finish
143
+ callbackRef.current = null;
143
144
  }
144
145
  (_inst$__apply = inst.__apply) === null || _inst$__apply === void 0 || _inst$__apply.call(inst, callback, option);
145
146
  },
@@ -233,11 +234,12 @@ const AnimatedBase = /*#__PURE__*/forwardRef((props, ref) => {
233
234
  const customStyleValue = useMemo(() => {
234
235
  if (!style) return undefined;
235
236
  return typeof style === 'object' ? styleToString(style) : style;
236
- }, [style]);
237
+ }, []);
237
238
  const handleAnimationEnd = useCallback(event => {
238
- if (callbackRef.current) {
239
- callbackRef.current(event);
239
+ if (callbackRef.current && typeof callbackRef.current === 'function') {
240
+ const temp = callbackRef.current;
240
241
  callbackRef.current = null;
242
+ temp(event);
241
243
  }
242
244
  if (onAnimationEnd) {
243
245
  onAnimationEnd();
@@ -1,3 +1,9 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import "core-js/modules/es.string.trim.js";
3
+ import "core-js/modules/esnext.iterator.constructor.js";
4
+ import "core-js/modules/esnext.iterator.filter.js";
5
+ import "core-js/modules/esnext.iterator.map.js";
6
+ import "core-js/modules/web.dom-collections.iterator.js";
1
7
  // @ts-nocheck
2
8
  /**
3
9
  * TyAnimated - 高性能动画组件(小程序原生层)
@@ -25,12 +31,7 @@ Component({
25
31
  // 兼容 FastView 接口
26
32
  customStyle: {
27
33
  type: String,
28
- value: '',
29
- observer: function (v) {
30
- this.setData({
31
- __style: v
32
- });
33
- }
34
+ value: ''
34
35
  },
35
36
  customClass: {
36
37
  type: String,
@@ -61,7 +62,13 @@ Component({
61
62
  },
62
63
  lifetimes: {
63
64
  attached() {
64
- // 组件初始化
65
+ // 组件初始化:将 customStyle 的初始值复制到 __style
66
+ const initialStyle = this.properties.customStyle || '';
67
+ if (initialStyle) {
68
+ this.setData({
69
+ __style: initialStyle
70
+ });
71
+ }
65
72
  },
66
73
  detached() {
67
74
  // 清理工作
@@ -106,15 +113,64 @@ Component({
106
113
  }
107
114
  return null;
108
115
  },
116
+ /**
117
+ * 解析样式字符串为对象
118
+ */
119
+ _parseStyle(styleString) {
120
+ if (!styleString) return {};
121
+ const result = {};
122
+ const styles = styleString.split(';').filter(Boolean);
123
+ for (const style of styles) {
124
+ const colonIndex = style.indexOf(':');
125
+ if (colonIndex > 0) {
126
+ const key = style.substring(0, colonIndex).trim();
127
+ const value = style.substring(colonIndex + 1).trim();
128
+ if (key && value) {
129
+ result[key] = value;
130
+ }
131
+ }
132
+ }
133
+ return result;
134
+ },
135
+ /**
136
+ * 样式对象转字符串
137
+ */
138
+ _styleToString(styleObj) {
139
+ return Object.entries(styleObj).map(_ref => {
140
+ let [key, value] = _ref;
141
+ return "".concat(key, ":").concat(value);
142
+ }).join(';');
143
+ },
109
144
  setCustomStyle(value) {
110
145
  // 防止传入 undefined 或 null 导致小程序报错
111
146
  if (value === undefined || value === null) {
112
147
  console.warn('[TyAnimatedComponent] setCustomStyle: value is undefined or null, ignored');
113
148
  return;
114
149
  }
150
+
151
+ // 1. 合并样式
152
+ const currentStyle = this._parseStyle(this.data.__style || '');
153
+ const newStyle = this._parseStyle(value);
154
+ const mergedStyle = _objectSpread(_objectSpread({}, currentStyle), newStyle);
155
+ const mergedStyleString = this._styleToString(mergedStyle);
156
+ if (mergedStyleString === this.data.__style && this.data.__animData !== null) {
157
+ console.log('[TyAnimated] 值相同且有动画数据,强制刷新');
158
+
159
+ // 先清空样式和动画数据
160
+ this.setData({
161
+ __style: '',
162
+ __animData: null
163
+ }, () => {
164
+ // 再设置目标样式
165
+ this.setData({
166
+ __style: mergedStyleString
167
+ });
168
+ });
169
+ return;
170
+ }
115
171
  this.setData({
116
- __style: value,
117
- customStyle: value
172
+ __style: mergedStyleString,
173
+ __animData: null
118
174
  });
119
175
  },
120
176
  /**
@@ -2,8 +2,8 @@
2
2
  <view
3
3
  wx:if="{{__mode==='view'}}"
4
4
  id="root"
5
- class="container {{__className}} {{customClass}}"
6
- style="{{__style}};{{customStyle}}"
5
+ class="container {{__className}}"
6
+ style="{{__style}}"
7
7
  animation="{{__animData}}"
8
8
  bindtap="__onClick"
9
9
  bindtouchstart="__onTouchStart"
@@ -14,8 +14,8 @@
14
14
  <text
15
15
  wx:else
16
16
  id="rootText"
17
- class="container {{__className}} {{customClass}}"
18
- style="{{__style}};{{customStyle}}"
17
+ class="container {{__className}}"
18
+ style="{{__style}}"
19
19
  animation="{{__animData}}"
20
20
  bindtap="__onClick"
21
21
  bindtouchstart="__onTouchStart"
@@ -1,4 +1,4 @@
1
1
  import React from 'react';
2
2
  import { ScrollViewProps } from '@ray-js/adapter';
3
- declare const ScrollView: React.ForwardRefExoticComponent<ScrollViewProps & React.RefAttributes<any>>;
3
+ declare const ScrollView: React.FC<ScrollViewProps>;
4
4
  export default ScrollView;
@@ -6,7 +6,7 @@ import React from 'react';
6
6
  import { useEventListener } from 'ahooks';
7
7
  import { ScrollView as ScrollViewDef } from '@ray-js/adapter';
8
8
  import handleProps from '../utils/handleProps';
9
- const ScrollView = /*#__PURE__*/React.forwardRef((props, ref) => {
9
+ const ScrollView = props => {
10
10
  const {
11
11
  onScroll,
12
12
  onScrollToUpper,
@@ -14,9 +14,6 @@ const ScrollView = /*#__PURE__*/React.forwardRef((props, ref) => {
14
14
  } = props,
15
15
  restProps = _objectWithoutProperties(props, _excluded);
16
16
  const currentNode = React.useRef(null);
17
-
18
- // 使用传入的 ref 或内部的 ref
19
- const scrollRef = ref || currentNode;
20
17
  useEventListener('scroll', e => {
21
18
  onScroll === null || onScroll === void 0 || onScroll(_objectSpread(_objectSpread(_objectSpread({}, e), {}, {
22
19
  type: 'scroll'
@@ -24,7 +21,7 @@ const ScrollView = /*#__PURE__*/React.forwardRef((props, ref) => {
24
21
  origin: e
25
22
  }));
26
23
  }, {
27
- target: scrollRef
24
+ target: currentNode
28
25
  });
29
26
  useEventListener('scrolltoupper', e => {
30
27
  onScrollToUpper === null || onScrollToUpper === void 0 || onScrollToUpper(_objectSpread(_objectSpread(_objectSpread({}, e), {}, {
@@ -33,7 +30,7 @@ const ScrollView = /*#__PURE__*/React.forwardRef((props, ref) => {
33
30
  origin: e
34
31
  }));
35
32
  }, {
36
- target: scrollRef
33
+ target: currentNode
37
34
  });
38
35
  useEventListener('scrolltolower', e => {
39
36
  onScrollToLower === null || onScrollToLower === void 0 || onScrollToLower(_objectSpread(_objectSpread(_objectSpread({}, e), {}, {
@@ -42,15 +39,15 @@ const ScrollView = /*#__PURE__*/React.forwardRef((props, ref) => {
42
39
  origin: e
43
40
  }));
44
41
  }, {
45
- target: scrollRef
42
+ target: currentNode
46
43
  });
47
44
  return (
48
45
  /*#__PURE__*/
49
46
  // @ts-ignore
50
47
  React.createElement("v-scroll-view", _extends({}, handleProps(restProps), {
51
- ref: scrollRef
48
+ ref: currentNode
52
49
  }), props.children)
53
50
  );
54
- });
51
+ };
55
52
  ScrollView.defaultProps = ScrollViewDef.defaultProps;
56
53
  export default ScrollView;
@@ -1,4 +1,4 @@
1
1
  import * as React from 'react';
2
2
  import type { ScrollViewProps } from '@ray-js/adapter';
3
- declare const ScrollView: React.ForwardRefExoticComponent<ScrollViewProps & React.RefAttributes<any>>;
3
+ declare const ScrollView: React.FC<ScrollViewProps>;
4
4
  export default ScrollView;
@@ -4,16 +4,13 @@ const _excluded = ["style"];
4
4
  import * as React from 'react';
5
5
  import { inlineStyle } from '@ray-js/framework-shared';
6
6
  import { ScrollView as RemaxScrollView } from '@ray-js/adapter';
7
- const ScrollView = /*#__PURE__*/React.forwardRef((props, ref) => {
7
+ const ScrollView = props => {
8
8
  const {
9
9
  style
10
10
  } = props,
11
11
  restProps = _objectWithoutProperties(props, _excluded);
12
- // @ts-ignore - RemaxScrollView 支持 ref,但类型定义可能不完整
13
12
  return /*#__PURE__*/React.createElement(RemaxScrollView, _extends({
14
- ref: ref,
15
13
  style: inlineStyle(style)
16
14
  }, restProps));
17
- });
18
- ScrollView.displayName = 'ScrollView';
15
+ };
19
16
  export default ScrollView;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/components",
3
- "version": "1.7.56-beta.1",
3
+ "version": "1.7.56-beta.3",
4
4
  "description": "Ray basic components",
5
5
  "keywords": [
6
6
  "ray"
@@ -29,8 +29,8 @@
29
29
  "dependencies": {
30
30
  "@ray-core/macro": "^0.4.9",
31
31
  "@ray-core/wechat": "^0.4.9",
32
- "@ray-js/adapter": "1.7.56-beta.1",
33
- "@ray-js/framework-shared": "1.7.56-beta.1",
32
+ "@ray-js/adapter": "1.7.56-beta.3",
33
+ "@ray-js/framework-shared": "1.7.56-beta.3",
34
34
  "ahooks": "^3.8.5",
35
35
  "clsx": "^1.2.1",
36
36
  "core-js": "^3.43.0",
@@ -40,11 +40,11 @@
40
40
  "style-to-object": "^0.3.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@ray-js/cli": "1.7.56-beta.1"
43
+ "@ray-js/cli": "1.7.56-beta.3"
44
44
  },
45
45
  "publishConfig": {
46
46
  "access": "public",
47
47
  "registry": "https://registry.npmjs.org"
48
48
  },
49
- "gitHead": "e1d99bcbd08502ade11590cf19ea8c3d01f41cbb"
49
+ "gitHead": "fdf56468c021ff48a0f36d027dcb9408533ef3ba"
50
50
  }