@arco-design/mobile-react 2.35.0 → 2.35.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.
@@ -26,7 +26,7 @@ export interface PopupSwiperProps extends PopupProps {
26
26
  * @default direction 属性指定的方向性
27
27
  * @default_en The value of direction property
28
28
  */
29
- allowSwipeDirections: DirectionType[];
29
+ allowSwipeDirections?: DirectionType[];
30
30
  /**
31
31
  * 固定弹窗退出方向,默认跟随手势滑动方向
32
32
  * @en Fixed the exit direction of the pop-up window, and the default sliding direction follows the gesture
@@ -1,6 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import React, { useRef, forwardRef, useCallback, useMemo, useContext, useEffect, useImperativeHandle } from 'react';
3
3
  import { cls, nextTick, defaultLocale } from '@arco-design/mobile-utils';
4
+ import { Promise } from 'es6-promise';
4
5
  import Loading from '../loading';
5
6
  import { GlobalContext } from '../context-provider';
6
7
  import { PullRefreshStatus } from './model';
@@ -104,8 +105,8 @@ export var PullRefresh = /*#__PURE__*/forwardRef(function (props, ref) {
104
105
  }, ms ? {
105
106
  transition: "all " + ms / 1000 + "s"
106
107
  } : {}));
107
- setTimeout(function () {
108
- callback == null ? void 0 : callback();
108
+ callback && setTimeout(function () {
109
+ callback();
109
110
  }, ms);
110
111
  };
111
112
 
@@ -132,11 +133,6 @@ export var PullRefresh = /*#__PURE__*/forwardRef(function (props, ref) {
132
133
  if (disabled || touchRef.current || loadingRef.current || !domRef.current) return;
133
134
  if (!ifShouldHandle()) return;
134
135
  setTouching(true);
135
-
136
- if (domRef.current.scrollTop === 0) {
137
- domRef.current.scrollTop = 1;
138
- }
139
-
140
136
  var _e$touches$ = e.touches[0],
141
137
  pageX = _e$touches$.pageX,
142
138
  pageY = _e$touches$.pageY;
@@ -1,4 +1,5 @@
1
1
  import type { CSSProperties, ReactNode } from 'react';
2
+ import { Promise } from 'es6-promise';
2
3
  export interface PullRefreshRef {
3
4
  /**
4
5
  * 最外层元素 DOM
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import React, { useRef, forwardRef, useImperativeHandle, useEffect, useMemo, useState, useCallback } from 'react';
3
- import { cls, execRAF, getActualContainer, getScrollContainerRect } from '@arco-design/mobile-utils';
3
+ import { cls, execRAF, getActualContainer, getScrollContainerRect, safeGetComputedStyle, convertCssPropertyToNumber } from '@arco-design/mobile-utils';
4
4
  import { ContextLayout } from '../context-provider';
5
5
  import { useRefState } from '../_helpers';
6
6
  import Portal from '../portal';
@@ -76,9 +76,14 @@ var Sticky = /*#__PURE__*/forwardRef(function (props, ref) {
76
76
  var _getScrollContainerRe = getScrollContainerRect(scrollContainerRef.current),
77
77
  containerRect = _getScrollContainerRe.containerRect;
78
78
 
79
- var containerTop = containerRect.top,
80
- containerBottom = containerRect.bottom,
79
+ var rectTop = containerRect.top,
80
+ rectBottom = containerRect.bottom,
81
81
  containerHeight = containerRect.height;
82
+ var scrollStyle = safeGetComputedStyle(scrollContainerRef.current);
83
+ var borderTop = needTop ? convertCssPropertyToNumber(scrollStyle, 'borderTopWidth') : 0;
84
+ var borderBottom = needBottom ? convertCssPropertyToNumber(scrollStyle, 'borderBottomWidth') : 0;
85
+ var containerTop = rectTop + borderTop;
86
+ var containerBottom = rectBottom - borderBottom;
82
87
  var disFromTop = Math.round(placeholderClientRect.top - containerTop);
83
88
  var disFromBottom = Math.round(placeholderClientRect.top + calculatedHeight - containerBottom);
84
89
  var topFollowDifference = followBottom - followOffset - calculatedHeight - topOffset - containerTop;
@@ -87,8 +92,32 @@ var Sticky = /*#__PURE__*/forwardRef(function (props, ref) {
87
92
  var isTopSticky = needTop ? disFromTop <= topOffset && followBottom > containerTop + followOffset : false;
88
93
  var isBottomSticky = needBottom ? disFromBottom >= -bottomOffset && followTop < containerBottom - followOffset : false;
89
94
  var newStickyState = isTopSticky || isBottomSticky;
90
- var cssTop = (stickyStyle === 'absolute' ? 0 : containerTop) + topOffset;
91
- var cssBottom = (stickyStyle === 'absolute' ? 0 : window.innerHeight - containerBottom) + bottomOffset;
95
+ var stickyTop = containerTop;
96
+ var stickyBottom = window.innerHeight - containerBottom;
97
+ var stickyLeft = placeholderClientRect.left;
98
+
99
+ if (stickyStyle === 'absolute') {
100
+ var offsetParent = contentRef.current.offsetParent;
101
+
102
+ if (offsetParent) {
103
+ var _getScrollContainerRe2 = getScrollContainerRect(offsetParent),
104
+ parentRect = _getScrollContainerRe2.containerRect;
105
+
106
+ var parentStyle = safeGetComputedStyle(offsetParent);
107
+ var parentBorderTop = needTop ? convertCssPropertyToNumber(parentStyle, 'borderTopWidth') : 0;
108
+ var parentBorderBottom = needBottom ? convertCssPropertyToNumber(parentStyle, 'borderBottomWidth') : 0;
109
+ var parentBorderLeft = convertCssPropertyToNumber(parentStyle, 'borderLeftWidth');
110
+ stickyTop = containerTop - parentRect.top - parentBorderTop;
111
+ stickyBottom = parentRect.bottom - containerBottom - parentBorderBottom;
112
+ stickyLeft = placeholderClientRect.left - parentRect.left - parentBorderLeft;
113
+ } else {
114
+ stickyTop = 0;
115
+ stickyBottom = 0;
116
+ }
117
+ }
118
+
119
+ var cssTop = stickyTop + topOffset;
120
+ var cssBottom = stickyBottom + bottomOffset;
92
121
  var stickyCssStyle = {};
93
122
 
94
123
  if (newStickyState) {
@@ -102,7 +131,7 @@ var Sticky = /*#__PURE__*/forwardRef(function (props, ref) {
102
131
  } : {}, isBottomSticky ? {
103
132
  bottom: bottomFollowDifference > 0 ? cssBottom : cssBottom + bottomFollowDifference
104
133
  } : {}, {
105
- left: placeholderClientRect.left,
134
+ left: stickyLeft,
106
135
  width: placeholderClientRect.width
107
136
  }, userSetStickyCssStyle || {});
108
137
  }
@@ -26,7 +26,7 @@ export interface PopupSwiperProps extends PopupProps {
26
26
  * @default direction 属性指定的方向性
27
27
  * @default_en The value of direction property
28
28
  */
29
- allowSwipeDirections: DirectionType[];
29
+ allowSwipeDirections?: DirectionType[];
30
30
  /**
31
31
  * 固定弹窗退出方向,默认跟随手势滑动方向
32
32
  * @en Fixed the exit direction of the pop-up window, and the default sliding direction follows the gesture
@@ -1,5 +1,6 @@
1
1
  import React, { useRef, forwardRef, useCallback, useMemo, useContext, useEffect, useImperativeHandle, } from 'react';
2
2
  import { cls, nextTick, defaultLocale } from '@arco-design/mobile-utils';
3
+ import { Promise } from 'es6-promise';
3
4
  import Loading from '../loading';
4
5
  import { GlobalContext } from '../context-provider';
5
6
  import { PullRefreshStatus } from './model';
@@ -49,9 +50,10 @@ export const PullRefresh = forwardRef((props, ref) => {
49
50
  transform: translateY ? `translateY(${translateY}px) translateZ(0)` : '',
50
51
  ...(ms ? { transition: `all ${ms / 1000}s` } : {}),
51
52
  });
52
- setTimeout(() => {
53
- callback?.();
54
- }, ms);
53
+ callback &&
54
+ setTimeout(() => {
55
+ callback();
56
+ }, ms);
55
57
  };
56
58
  const reset = (callback = () => { }) => {
57
59
  scroll(0, 300, () => {
@@ -70,9 +72,6 @@ export const PullRefresh = forwardRef((props, ref) => {
70
72
  if (!ifShouldHandle())
71
73
  return;
72
74
  setTouching(true);
73
- if (domRef.current.scrollTop === 0) {
74
- domRef.current.scrollTop = 1;
75
- }
76
75
  const { pageX, pageY } = e.touches[0];
77
76
  if (pageX && pageY) {
78
77
  touchRef.current = { start: domRef.current?.scrollTop, x: pageX, y: pageY };
@@ -1,4 +1,5 @@
1
1
  import type { CSSProperties, ReactNode } from 'react';
2
+ import { Promise } from 'es6-promise';
2
3
  export interface PullRefreshRef {
3
4
  /**
4
5
  * 最外层元素 DOM
@@ -1,5 +1,5 @@
1
1
  import React, { useRef, forwardRef, useImperativeHandle, useEffect, useMemo, useState, useCallback, } from 'react';
2
- import { cls, execRAF, getActualContainer, getScrollContainerRect, } from '@arco-design/mobile-utils';
2
+ import { cls, execRAF, getActualContainer, getScrollContainerRect, safeGetComputedStyle, convertCssPropertyToNumber, } from '@arco-design/mobile-utils';
3
3
  import { ContextLayout } from '../context-provider';
4
4
  import { useRefState } from '../_helpers';
5
5
  import Portal from '../portal';
@@ -33,7 +33,16 @@ const Sticky = forwardRef((props, ref) => {
33
33
  const calculatedHeight = contentClientRect.height;
34
34
  contentCalculateHeightRef.current = contentClientRect.height;
35
35
  const { containerRect } = getScrollContainerRect(scrollContainerRef.current);
36
- const { top: containerTop, bottom: containerBottom, height: containerHeight, } = containerRect;
36
+ const { top: rectTop, bottom: rectBottom, height: containerHeight } = containerRect;
37
+ const scrollStyle = safeGetComputedStyle(scrollContainerRef.current);
38
+ const borderTop = needTop
39
+ ? convertCssPropertyToNumber(scrollStyle, 'borderTopWidth')
40
+ : 0;
41
+ const borderBottom = needBottom
42
+ ? convertCssPropertyToNumber(scrollStyle, 'borderBottomWidth')
43
+ : 0;
44
+ const containerTop = rectTop + borderTop;
45
+ const containerBottom = rectBottom - borderBottom;
37
46
  const disFromTop = Math.round(placeholderClientRect.top - containerTop);
38
47
  const disFromBottom = Math.round(placeholderClientRect.top + calculatedHeight - containerBottom);
39
48
  const topFollowDifference = followBottom - followOffset - calculatedHeight - topOffset - containerTop;
@@ -46,9 +55,32 @@ const Sticky = forwardRef((props, ref) => {
46
55
  ? disFromBottom >= -bottomOffset && followTop < containerBottom - followOffset
47
56
  : false;
48
57
  const newStickyState = isTopSticky || isBottomSticky;
49
- const cssTop = (stickyStyle === 'absolute' ? 0 : containerTop) + topOffset;
50
- const cssBottom = (stickyStyle === 'absolute' ? 0 : window.innerHeight - containerBottom) +
51
- bottomOffset;
58
+ let stickyTop = containerTop;
59
+ let stickyBottom = window.innerHeight - containerBottom;
60
+ let stickyLeft = placeholderClientRect.left;
61
+ if (stickyStyle === 'absolute') {
62
+ const offsetParent = contentRef.current.offsetParent;
63
+ if (offsetParent) {
64
+ const { containerRect: parentRect } = getScrollContainerRect(offsetParent);
65
+ const parentStyle = safeGetComputedStyle(offsetParent);
66
+ const parentBorderTop = needTop
67
+ ? convertCssPropertyToNumber(parentStyle, 'borderTopWidth')
68
+ : 0;
69
+ const parentBorderBottom = needBottom
70
+ ? convertCssPropertyToNumber(parentStyle, 'borderBottomWidth')
71
+ : 0;
72
+ const parentBorderLeft = convertCssPropertyToNumber(parentStyle, 'borderLeftWidth');
73
+ stickyTop = containerTop - parentRect.top - parentBorderTop;
74
+ stickyBottom = parentRect.bottom - containerBottom - parentBorderBottom;
75
+ stickyLeft = placeholderClientRect.left - parentRect.left - parentBorderLeft;
76
+ }
77
+ else {
78
+ stickyTop = 0;
79
+ stickyBottom = 0;
80
+ }
81
+ }
82
+ const cssTop = stickyTop + topOffset;
83
+ const cssBottom = stickyBottom + bottomOffset;
52
84
  let stickyCssStyle = {};
53
85
  if (newStickyState) {
54
86
  stickyCssStyle = {
@@ -68,7 +100,7 @@ const Sticky = forwardRef((props, ref) => {
68
100
  : cssBottom + bottomFollowDifference,
69
101
  }
70
102
  : {}),
71
- left: placeholderClientRect.left,
103
+ left: stickyLeft,
72
104
  width: placeholderClientRect.width,
73
105
  ...(userSetStickyCssStyle || {}),
74
106
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arco-design/mobile-react",
3
- "version": "2.35.0",
3
+ "version": "2.35.2",
4
4
  "description": "",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",
@@ -15,7 +15,7 @@
15
15
  "author": "taoyiyue@bytedance.com",
16
16
  "license": "ISC",
17
17
  "dependencies": {
18
- "@arco-design/mobile-utils": "2.20.2",
18
+ "@arco-design/mobile-utils": "2.20.4",
19
19
  "@arco-design/transformable": "^1.0.0",
20
20
  "@babel/runtime": "^7",
21
21
  "lodash.throttle": "^4.1.1",
@@ -47,5 +47,5 @@
47
47
  "publishConfig": {
48
48
  "access": "public"
49
49
  },
50
- "gitHead": "efb0db8d0e3ecdd787266dce595b2990e80bbefa"
50
+ "gitHead": "a60bba95c16b19816c23b4e59b4db57d16137589"
51
51
  }
@@ -26,7 +26,7 @@ export interface PopupSwiperProps extends PopupProps {
26
26
  * @default direction 属性指定的方向性
27
27
  * @default_en The value of direction property
28
28
  */
29
- allowSwipeDirections: DirectionType[];
29
+ allowSwipeDirections?: DirectionType[];
30
30
  /**
31
31
  * 固定弹窗退出方向,默认跟随手势滑动方向
32
32
  * @en Fixed the exit direction of the pop-up window, and the default sliding direction follows the gesture
@@ -1,16 +1,16 @@
1
1
  (function (global, factory) {
2
2
  if (typeof define === "function" && define.amd) {
3
- define(["exports", "@babel/runtime/helpers/extends", "react", "@arco-design/mobile-utils", "../loading", "../context-provider", "./model", "./hooks", "../_helpers"], factory);
3
+ define(["exports", "@babel/runtime/helpers/extends", "react", "@arco-design/mobile-utils", "es6-promise", "../loading", "../context-provider", "./model", "./hooks", "../_helpers"], factory);
4
4
  } else if (typeof exports !== "undefined") {
5
- factory(exports, require("@babel/runtime/helpers/extends"), require("react"), require("@arco-design/mobile-utils"), require("../loading"), require("../context-provider"), require("./model"), require("./hooks"), require("../_helpers"));
5
+ factory(exports, require("@babel/runtime/helpers/extends"), require("react"), require("@arco-design/mobile-utils"), require("es6-promise"), require("../loading"), require("../context-provider"), require("./model"), require("./hooks"), require("../_helpers"));
6
6
  } else {
7
7
  var mod = {
8
8
  exports: {}
9
9
  };
10
- factory(mod.exports, global._extends, global.react, global.mobileUtils, global.loading, global.contextProvider, global.model, global.hooks, global._helpers);
10
+ factory(mod.exports, global._extends, global.react, global.mobileUtils, global.es6Promise, global.loading, global.contextProvider, global.model, global.hooks, global._helpers);
11
11
  global.androidPullRefresh = mod.exports;
12
12
  }
13
- })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _extends2, _react, _mobileUtils, _loading, _contextProvider, _model, _hooks, _helpers) {
13
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _extends2, _react, _mobileUtils, _es6Promise, _loading, _contextProvider, _model, _hooks, _helpers) {
14
14
  "use strict";
15
15
 
16
16
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
@@ -122,8 +122,8 @@
122
122
  }, ms ? {
123
123
  transition: "all " + ms / 1000 + "s"
124
124
  } : {}));
125
- setTimeout(function () {
126
- callback == null ? void 0 : callback();
125
+ callback && setTimeout(function () {
126
+ callback();
127
127
  }, ms);
128
128
  };
129
129
 
@@ -150,11 +150,6 @@
150
150
  if (disabled || touchRef.current || loadingRef.current || !domRef.current) return;
151
151
  if (!ifShouldHandle()) return;
152
152
  setTouching(true);
153
-
154
- if (domRef.current.scrollTop === 0) {
155
- domRef.current.scrollTop = 1;
156
- }
157
-
158
153
  var _e$touches$ = e.touches[0],
159
154
  pageX = _e$touches$.pageX,
160
155
  pageY = _e$touches$.pageY;
@@ -173,7 +168,7 @@
173
168
  }, [disabled, ifShouldHandle]);
174
169
 
175
170
  var refresh = function refresh() {
176
- return new Promise(function (resolve) {
171
+ return new _es6Promise.Promise(function (resolve) {
177
172
  setStatus(_model.PullRefreshStatus.Loading);
178
173
  (0, _mobileUtils.nextTick)(function () {
179
174
  scroll(tipsHeight, 300);
@@ -1,4 +1,5 @@
1
1
  import type { CSSProperties, ReactNode } from 'react';
2
+ import { Promise } from 'es6-promise';
2
3
  export interface PullRefreshRef {
3
4
  /**
4
5
  * 最外层元素 DOM
@@ -96,9 +96,14 @@
96
96
  var _getScrollContainerRe = (0, _mobileUtils.getScrollContainerRect)(scrollContainerRef.current),
97
97
  containerRect = _getScrollContainerRe.containerRect;
98
98
 
99
- var containerTop = containerRect.top,
100
- containerBottom = containerRect.bottom,
99
+ var rectTop = containerRect.top,
100
+ rectBottom = containerRect.bottom,
101
101
  containerHeight = containerRect.height;
102
+ var scrollStyle = (0, _mobileUtils.safeGetComputedStyle)(scrollContainerRef.current);
103
+ var borderTop = needTop ? (0, _mobileUtils.convertCssPropertyToNumber)(scrollStyle, 'borderTopWidth') : 0;
104
+ var borderBottom = needBottom ? (0, _mobileUtils.convertCssPropertyToNumber)(scrollStyle, 'borderBottomWidth') : 0;
105
+ var containerTop = rectTop + borderTop;
106
+ var containerBottom = rectBottom - borderBottom;
102
107
  var disFromTop = Math.round(placeholderClientRect.top - containerTop);
103
108
  var disFromBottom = Math.round(placeholderClientRect.top + calculatedHeight - containerBottom);
104
109
  var topFollowDifference = followBottom - followOffset - calculatedHeight - topOffset - containerTop;
@@ -107,8 +112,32 @@
107
112
  var isTopSticky = needTop ? disFromTop <= topOffset && followBottom > containerTop + followOffset : false;
108
113
  var isBottomSticky = needBottom ? disFromBottom >= -bottomOffset && followTop < containerBottom - followOffset : false;
109
114
  var newStickyState = isTopSticky || isBottomSticky;
110
- var cssTop = (stickyStyle === 'absolute' ? 0 : containerTop) + topOffset;
111
- var cssBottom = (stickyStyle === 'absolute' ? 0 : window.innerHeight - containerBottom) + bottomOffset;
115
+ var stickyTop = containerTop;
116
+ var stickyBottom = window.innerHeight - containerBottom;
117
+ var stickyLeft = placeholderClientRect.left;
118
+
119
+ if (stickyStyle === 'absolute') {
120
+ var offsetParent = contentRef.current.offsetParent;
121
+
122
+ if (offsetParent) {
123
+ var _getScrollContainerRe2 = (0, _mobileUtils.getScrollContainerRect)(offsetParent),
124
+ parentRect = _getScrollContainerRe2.containerRect;
125
+
126
+ var parentStyle = (0, _mobileUtils.safeGetComputedStyle)(offsetParent);
127
+ var parentBorderTop = needTop ? (0, _mobileUtils.convertCssPropertyToNumber)(parentStyle, 'borderTopWidth') : 0;
128
+ var parentBorderBottom = needBottom ? (0, _mobileUtils.convertCssPropertyToNumber)(parentStyle, 'borderBottomWidth') : 0;
129
+ var parentBorderLeft = (0, _mobileUtils.convertCssPropertyToNumber)(parentStyle, 'borderLeftWidth');
130
+ stickyTop = containerTop - parentRect.top - parentBorderTop;
131
+ stickyBottom = parentRect.bottom - containerBottom - parentBorderBottom;
132
+ stickyLeft = placeholderClientRect.left - parentRect.left - parentBorderLeft;
133
+ } else {
134
+ stickyTop = 0;
135
+ stickyBottom = 0;
136
+ }
137
+ }
138
+
139
+ var cssTop = stickyTop + topOffset;
140
+ var cssBottom = stickyBottom + bottomOffset;
112
141
  var stickyCssStyle = {};
113
142
 
114
143
  if (newStickyState) {
@@ -122,7 +151,7 @@
122
151
  } : {}, isBottomSticky ? {
123
152
  bottom: bottomFollowDifference > 0 ? cssBottom : cssBottom + bottomFollowDifference
124
153
  } : {}, {
125
- left: placeholderClientRect.left,
154
+ left: stickyLeft,
126
155
  width: placeholderClientRect.width
127
156
  }, userSetStickyCssStyle || {});
128
157
  }