@mpxjs/api-proxy 2.9.64 → 2.9.66
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 +3 -3
- package/src/common/js/utils.js +1 -9
- package/src/platform/api/animation/animation.react.js +281 -0
- package/src/platform/api/animation/index.android.js +1 -0
- package/src/platform/api/animation/index.ios.js +5 -0
- package/src/platform/api/create-intersection-observer/index.ali.js +3 -0
- package/src/platform/api/create-intersection-observer/index.ios.js +9 -0
- package/src/platform/api/create-intersection-observer/rnIntersectionObserver.js +239 -0
- package/src/platform/api/route/index.web.js +2 -1
- package/src/platform/api/system/rnSystem.js +4 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/api-proxy",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.66",
|
|
4
4
|
"description": "convert miniprogram API at each end",
|
|
5
5
|
"module": "src/index.js",
|
|
6
6
|
"types": "@types/index.d.ts",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"homepage": "https://github.com/didi/mpx#readme",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@mpxjs/utils": "^2.9.
|
|
40
|
+
"@mpxjs/utils": "^2.9.65",
|
|
41
41
|
"axios": "^1.7.3"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
"optional": true
|
|
81
81
|
}
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "ff9eb06a3be28538870823cebf813ed56f39bbd7"
|
|
84
84
|
}
|
package/src/common/js/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { hasOwn, noop, getEnvObj } from '@mpxjs/utils'
|
|
1
|
+
import { hasOwn, noop, getEnvObj, getFocusedNavigation } from '@mpxjs/utils'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
*
|
|
@@ -87,14 +87,6 @@ function failHandle (result, fail, complete) {
|
|
|
87
87
|
typeof complete === 'function' && complete(result)
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
function getFocusedNavigation () {
|
|
91
|
-
for (const key in global.__mpxPagesMap) {
|
|
92
|
-
const navigation = global.__mpxPagesMap[key]?.[1]
|
|
93
|
-
if (navigation && navigation.isFocused()) {
|
|
94
|
-
return navigation
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
90
|
const ENV_OBJ = getEnvObj()
|
|
99
91
|
|
|
100
92
|
export {
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
class Animation {
|
|
2
|
+
constructor (
|
|
3
|
+
{
|
|
4
|
+
duration = 400,
|
|
5
|
+
delay = 0,
|
|
6
|
+
timingFunction = 'linear',
|
|
7
|
+
transformOrigin = '50% 50% 0'
|
|
8
|
+
} = {}
|
|
9
|
+
) {
|
|
10
|
+
// 默认值
|
|
11
|
+
this._setDefault(duration, delay, timingFunction, transformOrigin)
|
|
12
|
+
this.id = 0
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
_transformUnit (...args) {
|
|
16
|
+
return args.map(each => {
|
|
17
|
+
return global.__formatValue(each)
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
_formatTransformOrigin (transformOrigin) {
|
|
22
|
+
const transformOriginArr = transformOrigin.trim().split(/\s+/, 3).map(item => global.__formatValue(item))
|
|
23
|
+
switch (transformOriginArr.length) {
|
|
24
|
+
case 0:
|
|
25
|
+
transformOriginArr.push('50%', '50%', 0)
|
|
26
|
+
break
|
|
27
|
+
case 1:
|
|
28
|
+
transformOriginArr.push('50%', 0)
|
|
29
|
+
break
|
|
30
|
+
case 2:
|
|
31
|
+
transformOriginArr.push(0)
|
|
32
|
+
break
|
|
33
|
+
}
|
|
34
|
+
return transformOriginArr
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 设置默认值
|
|
38
|
+
_setDefault (duration, delay, timingFunction, transformOrigin) {
|
|
39
|
+
this.DEFAULT = { duration, delay, timingFunction, transformOrigin }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 属性组合
|
|
43
|
+
rules = new Map()
|
|
44
|
+
// transform 对象
|
|
45
|
+
transform = new Map()
|
|
46
|
+
// 组合动画
|
|
47
|
+
steps = []
|
|
48
|
+
|
|
49
|
+
matrix (a, b, c, d, tx, ty) { // Todo
|
|
50
|
+
console.error('React Native 不支持 matrix 动画')
|
|
51
|
+
// this.transform.set('matrix', [a, b, c, d, tx, ty])
|
|
52
|
+
return this
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
matrix3d (a1, b1, c1, d1,
|
|
56
|
+
a2, b2, c2, d2,
|
|
57
|
+
a3, b3, c3, d3,
|
|
58
|
+
a4, b4, c4, d4
|
|
59
|
+
) {
|
|
60
|
+
console.error('React Native 不支持 matrix3d 动画')
|
|
61
|
+
// this.transform.set('matrix3d', [ // Todo
|
|
62
|
+
// a1, b1, c1, d1,
|
|
63
|
+
// a2, b2, c2, d2,
|
|
64
|
+
// a3, b3, c3, d3,
|
|
65
|
+
// a4, b4, c4, d4
|
|
66
|
+
// ])
|
|
67
|
+
return this
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
rotate (angle) { // 旋转变换
|
|
71
|
+
this.transform.set('rotate', `${angle}deg`)
|
|
72
|
+
return this
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
rotate3d (x, y, z, angle) {
|
|
76
|
+
if (typeof y !== 'number') {
|
|
77
|
+
this.transform.set('rotate3d', x)
|
|
78
|
+
} else {
|
|
79
|
+
// this.transform.set('rotate3d', [x, y, z, angle])
|
|
80
|
+
this.rotateX(x)
|
|
81
|
+
this.rotateY(y)
|
|
82
|
+
this.rotateZ(z)
|
|
83
|
+
this.rotate(angle)
|
|
84
|
+
}
|
|
85
|
+
return this
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
rotateX (angle) {
|
|
89
|
+
this.transform.set('rotateX', `${angle}deg`)
|
|
90
|
+
return this
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
rotateY (angle) {
|
|
94
|
+
this.transform.set('rotateY', `${angle}deg`)
|
|
95
|
+
return this
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
rotateZ (angle) {
|
|
99
|
+
this.transform.set('rotateZ', `${angle}deg`)
|
|
100
|
+
return this
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
scale (x, y) {
|
|
104
|
+
const scaleY = (typeof y !== 'undefined' && y !== null) ? y : x
|
|
105
|
+
this.scaleX(x)
|
|
106
|
+
this.scaleY(scaleY)
|
|
107
|
+
// this.transform.set('scale', [x, scaleY])
|
|
108
|
+
return this
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
scaleX (scale) {
|
|
112
|
+
this.transform.set('scaleX', scale)
|
|
113
|
+
return this
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
scaleY (scale) {
|
|
117
|
+
this.transform.set('scaleY', scale)
|
|
118
|
+
return this
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
scaleZ (scale) { // Todo Invariant Violation: Invalid transform scaleZ: {"scaleZ":0}
|
|
122
|
+
console.error('React Native 不支持 transform scaleZ')
|
|
123
|
+
// this.transform.set('scaleZ', scale)
|
|
124
|
+
return this
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
scale3d (x, y, z) { // Todo Invariant Violation: Invalid transform scaleZ: {"scaleZ":0}
|
|
128
|
+
console.error('React Native 不支持 transform scaleZ,故不支持 scale3d')
|
|
129
|
+
// this.scaleX(x)
|
|
130
|
+
// this.scaleY(y)
|
|
131
|
+
// this.scaleZ(z)
|
|
132
|
+
return this
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
skew (x, y) {
|
|
136
|
+
// this.transform.set('skew', [x, y])
|
|
137
|
+
this.skewX(x)
|
|
138
|
+
this.skewY(y)
|
|
139
|
+
return this
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
skewX (angle) {
|
|
143
|
+
this.transform.set('skewX', `${angle}deg`)
|
|
144
|
+
return this
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
skewY (angle) {
|
|
148
|
+
this.transform.set('skewY', `${angle}deg`)
|
|
149
|
+
return this
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
translate (x, y) {
|
|
153
|
+
[x, y] = this._transformUnit(x, y)
|
|
154
|
+
// this.transform.set('translate', [x, y])
|
|
155
|
+
this.translateX(x)
|
|
156
|
+
this.translateY(y)
|
|
157
|
+
return this
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
translateX (translate) {
|
|
161
|
+
[translate] = this._transformUnit(translate)
|
|
162
|
+
this.transform.set('translateX', translate)
|
|
163
|
+
return this
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
translateY (translate) {
|
|
167
|
+
[translate] = this._transformUnit(translate)
|
|
168
|
+
this.transform.set('translateY', translate)
|
|
169
|
+
return this
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
translateZ (translate) { // Todo Invariant Violation: Invalid transform translateZ: {"translateZ":0}
|
|
173
|
+
console.error('React Native 不支持 transform translateZ')
|
|
174
|
+
// [translate] = this._transformUnit(translate)
|
|
175
|
+
// this.transform.set('translateZ', translate)
|
|
176
|
+
return this
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
translate3d (x, y, z) { // Todo Invariant Violation: Invalid transform translateZ: {"translateZ":0}
|
|
180
|
+
console.error('React Native 不支持 transform translateZ,故无法支持 translate3d')
|
|
181
|
+
// [x, y, z] = this._transformUnit(x, y, z)
|
|
182
|
+
// // this.transform.set('translate3d', [x, y, z])
|
|
183
|
+
// this.translateX(x)
|
|
184
|
+
// this.translateY(y)
|
|
185
|
+
// this.translateZ(z)
|
|
186
|
+
return this
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
opacity (value) {
|
|
190
|
+
this.rules.set('opacity', value)
|
|
191
|
+
return this
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
backgroundColor (value) {
|
|
195
|
+
this.rules.set('backgroundColor', value)
|
|
196
|
+
return this
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
width (value) {
|
|
200
|
+
[value] = this._transformUnit(value)
|
|
201
|
+
this.rules.set('width', value)
|
|
202
|
+
return this
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
height (value) {
|
|
206
|
+
[value] = this._transformUnit(value)
|
|
207
|
+
this.rules.set('height', value)
|
|
208
|
+
return this
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
top (value) {
|
|
212
|
+
[value] = this._transformUnit(value)
|
|
213
|
+
this.rules.set('top', value)
|
|
214
|
+
return this
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
right (value) {
|
|
218
|
+
[value] = this._transformUnit(value)
|
|
219
|
+
this.rules.set('right', value)
|
|
220
|
+
return this
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
bottom (value) {
|
|
224
|
+
[value] = this._transformUnit(value)
|
|
225
|
+
this.rules.set('bottom', value)
|
|
226
|
+
return this
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
left (value) {
|
|
230
|
+
[value] = this._transformUnit(value)
|
|
231
|
+
this.rules.set('left', value)
|
|
232
|
+
return this
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// 关键帧载入
|
|
236
|
+
step (arg = {}) {
|
|
237
|
+
const { DEFAULT } = this
|
|
238
|
+
let {
|
|
239
|
+
duration = DEFAULT.duration,
|
|
240
|
+
delay = DEFAULT.delay,
|
|
241
|
+
timingFunction = DEFAULT.timingFunction,
|
|
242
|
+
transformOrigin = DEFAULT.transformOrigin
|
|
243
|
+
} = arg
|
|
244
|
+
if (typeof transformOrigin !== 'string') {
|
|
245
|
+
console.error('Value of transformOrigin only support string type, please check again')
|
|
246
|
+
transformOrigin = DEFAULT.transformOrigin
|
|
247
|
+
}
|
|
248
|
+
this.steps.push({
|
|
249
|
+
animatedOption: {
|
|
250
|
+
duration,
|
|
251
|
+
delay,
|
|
252
|
+
timingFunction,
|
|
253
|
+
transformOrigin: this._formatTransformOrigin(transformOrigin)
|
|
254
|
+
},
|
|
255
|
+
rules: this.rules,
|
|
256
|
+
transform: this.transform
|
|
257
|
+
})
|
|
258
|
+
// 清空 rules 和 transform
|
|
259
|
+
this.rules = new Map()
|
|
260
|
+
this.transform = new Map()
|
|
261
|
+
return this
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// 数据
|
|
265
|
+
createAnimationData () {
|
|
266
|
+
const steps = this.steps
|
|
267
|
+
this.steps = []
|
|
268
|
+
return steps
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// 动画数据产出
|
|
272
|
+
export () {
|
|
273
|
+
this.id++
|
|
274
|
+
return {
|
|
275
|
+
id: this.id,
|
|
276
|
+
actions: this.createAnimationData()
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export default Animation
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './index.ios'
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { isArray, isObject, isString, noop } from '@mpxjs/utils'
|
|
2
|
+
import throttle from 'lodash/throttle'
|
|
3
|
+
import { Dimensions } from 'react-native'
|
|
4
|
+
import { getFocusedNavigation } from '../../../common/js'
|
|
5
|
+
|
|
6
|
+
const WindowRefStr = 'window'
|
|
7
|
+
const IgnoreTarget = 'ignore'
|
|
8
|
+
const DefaultMargin = { top: 0, bottom: 0, left: 0, right: 0 }
|
|
9
|
+
let idCount = 0
|
|
10
|
+
|
|
11
|
+
class RNIntersectionObserver {
|
|
12
|
+
constructor (component, options, intersectionCtx) {
|
|
13
|
+
this.id = idCount++
|
|
14
|
+
this.component = component
|
|
15
|
+
this.options = options
|
|
16
|
+
this.thresholds = options.thresholds.sort((a, b) => a - b) || [0]
|
|
17
|
+
this.initialRatio = options.initialRatio || 0
|
|
18
|
+
this.observeAll = options.observeAll || false
|
|
19
|
+
|
|
20
|
+
// 组件上挂载对应的observers,用于在组件销毁的时候进行批量disconnect
|
|
21
|
+
this.component._intersectionObservers = this.component.__intersectionObservers || []
|
|
22
|
+
this.component._intersectionObservers.push(this)
|
|
23
|
+
|
|
24
|
+
this.observerRefs = null
|
|
25
|
+
this.relativeRef = null
|
|
26
|
+
this.margins = DefaultMargin
|
|
27
|
+
this.callback = noop
|
|
28
|
+
|
|
29
|
+
this.throttleMeasure = this.getThrottleMeasure(options.throttleTime || 100)
|
|
30
|
+
|
|
31
|
+
// 记录上一次相交的比例
|
|
32
|
+
this.previousIntersectionRatio = []
|
|
33
|
+
|
|
34
|
+
// 添加实例添加到上下文中,滚动组件可以获取到上下文内的实例从而触发滚动
|
|
35
|
+
if (intersectionCtx && isObject(intersectionCtx)) {
|
|
36
|
+
this.intersectionCtx = intersectionCtx
|
|
37
|
+
this.intersectionCtx[this.id] = this
|
|
38
|
+
}
|
|
39
|
+
return this
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 支持传递ref 或者 selector
|
|
43
|
+
relativeTo (selector, margins = {}) {
|
|
44
|
+
let relativeRef
|
|
45
|
+
if (isString(selector)) {
|
|
46
|
+
relativeRef = this.component.__selectRef(selector, 'node')
|
|
47
|
+
}
|
|
48
|
+
if (isObject(selector)) {
|
|
49
|
+
relativeRef = selector.nodeRefs?.[0]
|
|
50
|
+
}
|
|
51
|
+
if (relativeRef) {
|
|
52
|
+
this.relativeRef = relativeRef
|
|
53
|
+
this.margins = Object.assign({}, DefaultMargin, margins)
|
|
54
|
+
} else {
|
|
55
|
+
console.warn(`node ${selector}is not found. The relative node for intersection observer will be ignored`)
|
|
56
|
+
}
|
|
57
|
+
return this
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
relativeToViewport (margins = {}) {
|
|
61
|
+
this.relativeRef = WindowRefStr
|
|
62
|
+
this.margins = Object.assign({}, DefaultMargin, margins)
|
|
63
|
+
return this
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
observe (selector, callback) {
|
|
67
|
+
if (this.observerRefs) {
|
|
68
|
+
console.error('"observe" call can be only called once in IntersectionObserver')
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
let targetRef = null
|
|
72
|
+
if (this.observeAll) {
|
|
73
|
+
targetRef = this.component.__selectRef(selector, 'node', true)
|
|
74
|
+
} else {
|
|
75
|
+
targetRef = this.component.__selectRef(selector, 'node')
|
|
76
|
+
}
|
|
77
|
+
if (!targetRef || targetRef.length === 0) {
|
|
78
|
+
console.error('intersection observer target not found')
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
this.observerRefs = isArray(targetRef) ? targetRef : [targetRef]
|
|
82
|
+
this.callback = callback
|
|
83
|
+
this._measureTarget(true)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
_getWindowRect () {
|
|
87
|
+
if (this.windowRect) return this.windowRect
|
|
88
|
+
const navigation = getFocusedNavigation()
|
|
89
|
+
const screen = Dimensions.get('screen')
|
|
90
|
+
const navigationLayout = navigation.layout || {
|
|
91
|
+
x: 0,
|
|
92
|
+
y: 0,
|
|
93
|
+
width: screen.width,
|
|
94
|
+
height: screen.height
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const windowRect = {
|
|
98
|
+
top: navigationLayout.y + this.margins.top,
|
|
99
|
+
left: navigationLayout.x + this.margins.left,
|
|
100
|
+
right: navigationLayout.width - this.margins.right,
|
|
101
|
+
bottom: navigationLayout.y + navigationLayout.height - this.margins.bottom
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
this.windowRect = windowRect
|
|
105
|
+
return this.windowRect
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
_getReferenceRect (targetRef) {
|
|
109
|
+
const targetRefs = isArray(targetRef) ? targetRef : [targetRef]
|
|
110
|
+
const targetPromiseQueue = []
|
|
111
|
+
targetRefs.forEach((targetRefItem) => {
|
|
112
|
+
if (targetRefItem === WindowRefStr) {
|
|
113
|
+
targetPromiseQueue.push(this._getWindowRect())
|
|
114
|
+
return
|
|
115
|
+
}
|
|
116
|
+
// 当节点前面存在后面移除的时候可能会存在拿不到target的情况,此处直接忽略留一个占位不用做计算即可
|
|
117
|
+
// 测试节点移除之后 targetRefItem.getNodeInstance().nodeRef都存在,只是current不存在了
|
|
118
|
+
if (!targetRefItem || !targetRefItem.getNodeInstance().nodeRef.current) {
|
|
119
|
+
targetPromiseQueue.push(Promise.resolve(IgnoreTarget))
|
|
120
|
+
return
|
|
121
|
+
}
|
|
122
|
+
const target = targetRefItem.getNodeInstance().nodeRef.current
|
|
123
|
+
targetPromiseQueue.push(new Promise((resolve) => {
|
|
124
|
+
target.measureInWindow(
|
|
125
|
+
(x, y, width, height) => {
|
|
126
|
+
const boundingClientRect = {
|
|
127
|
+
left: x,
|
|
128
|
+
top: y,
|
|
129
|
+
right: x + width,
|
|
130
|
+
bottom: y + height,
|
|
131
|
+
width: width,
|
|
132
|
+
height: height
|
|
133
|
+
}
|
|
134
|
+
resolve(boundingClientRect)
|
|
135
|
+
}
|
|
136
|
+
)
|
|
137
|
+
}))
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
if (isArray(targetRef)) {
|
|
141
|
+
return Promise.all(targetPromiseQueue)
|
|
142
|
+
} else {
|
|
143
|
+
return targetPromiseQueue[0]
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
_restrictValueInRange (start = 0, end = 0, value = 0) {
|
|
148
|
+
return Math.min(Math.max(start, value), end)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
_isInsectedFn (intersectionRatio, previousIntersectionRatio, thresholds) {
|
|
152
|
+
// console.log('nowintersectionRatio, previousIntersectionRatio', [intersectionRatio, previousIntersectionRatio])
|
|
153
|
+
let nowIndex = -1
|
|
154
|
+
let previousIndex = -1
|
|
155
|
+
thresholds.forEach((item, index) => {
|
|
156
|
+
if (intersectionRatio >= item) {
|
|
157
|
+
nowIndex = index
|
|
158
|
+
}
|
|
159
|
+
if (previousIntersectionRatio >= item) {
|
|
160
|
+
previousIndex = index
|
|
161
|
+
}
|
|
162
|
+
})
|
|
163
|
+
return !(nowIndex === previousIndex)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// 计算相交区域
|
|
167
|
+
_measureIntersection ({ observeRect, relativeRect, observeIndex, isInit }) {
|
|
168
|
+
const visibleRect = {
|
|
169
|
+
left: this._restrictValueInRange(relativeRect.left, relativeRect.right, observeRect.left),
|
|
170
|
+
top: this._restrictValueInRange(relativeRect.top, relativeRect.bottom, observeRect.top),
|
|
171
|
+
right: this._restrictValueInRange(relativeRect.left, relativeRect.right, observeRect.right),
|
|
172
|
+
bottom: this._restrictValueInRange(relativeRect.top, relativeRect.bottom, observeRect.bottom)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const targetArea = (observeRect.bottom - observeRect.top) * (observeRect.right - observeRect.left)
|
|
176
|
+
const visibleArea = (visibleRect.bottom - visibleRect.top) * (visibleRect.right - visibleRect.left)
|
|
177
|
+
const intersectionRatio = targetArea ? visibleArea / targetArea : 0
|
|
178
|
+
|
|
179
|
+
const isInsected = isInit ? intersectionRatio > this.initialRatio : this._isInsectedFn(intersectionRatio, this.previousIntersectionRatio[observeIndex], this.thresholds)
|
|
180
|
+
this.previousIntersectionRatio[observeIndex] = intersectionRatio
|
|
181
|
+
|
|
182
|
+
return {
|
|
183
|
+
intersectionRatio,
|
|
184
|
+
intersectionRect: {
|
|
185
|
+
top: visibleRect.top,
|
|
186
|
+
bottom: relativeRect.bottom,
|
|
187
|
+
left: visibleRect.left,
|
|
188
|
+
right: relativeRect.right
|
|
189
|
+
},
|
|
190
|
+
isInsected
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
getThrottleMeasure (throttleTime) {
|
|
195
|
+
return throttle(() => {
|
|
196
|
+
this._measureTarget()
|
|
197
|
+
}, throttleTime)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// 计算节点的rect信息
|
|
201
|
+
_measureTarget (isInit = false) {
|
|
202
|
+
Promise.all([
|
|
203
|
+
this._getReferenceRect(this.observerRefs),
|
|
204
|
+
this._getReferenceRect(this.relativeRef)
|
|
205
|
+
]).then(([observeRects, relativeRect]) => {
|
|
206
|
+
if (relativeRect === IgnoreTarget) return
|
|
207
|
+
observeRects.forEach((observeRect, index) => {
|
|
208
|
+
if (observeRect === IgnoreTarget) return
|
|
209
|
+
const { intersectionRatio, intersectionRect, isInsected } = this._measureIntersection({
|
|
210
|
+
observeRect,
|
|
211
|
+
observeIndex: index,
|
|
212
|
+
relativeRect,
|
|
213
|
+
isInit
|
|
214
|
+
})
|
|
215
|
+
// 初次调用的
|
|
216
|
+
if (isInsected) {
|
|
217
|
+
this.callback({
|
|
218
|
+
// index: index,
|
|
219
|
+
id: this.observerRefs[index].getNodeInstance().props?.current?.id,
|
|
220
|
+
dataset: this.observerRefs[index].getNodeInstance().props?.current?.dataset || {},
|
|
221
|
+
intersectionRatio: Math.round(intersectionRatio * 100) / 100,
|
|
222
|
+
intersectionRect,
|
|
223
|
+
boundingClientRect: observeRect,
|
|
224
|
+
relativeRect: relativeRect,
|
|
225
|
+
time: Date.now()
|
|
226
|
+
})
|
|
227
|
+
}
|
|
228
|
+
})
|
|
229
|
+
}).catch((e) => {
|
|
230
|
+
console.log('_measureTarget fail', e)
|
|
231
|
+
})
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
disconnect () {
|
|
235
|
+
if (this.intersectionCtx) delete this.intersectionCtx[this.id]
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export default RNIntersectionObserver
|
|
@@ -110,7 +110,8 @@ function reLaunch (options = {}) {
|
|
|
110
110
|
routeCount: ++routeCount,
|
|
111
111
|
replaced: false
|
|
112
112
|
}
|
|
113
|
-
|
|
113
|
+
// 宿主环境中没有办法统计到webview中的页面跳转,所有给用户开放个userDelta,由用户根据webview中的页面跳转的个数自行传递控制relaunch跳转正确
|
|
114
|
+
const delta = router.stack.length - 1 + (options.delta || 0)
|
|
114
115
|
// 在需要操作后退时,先操作后退,在beforeEach中基于当前action通过next()进行replace操作,避免部分浏览器的表现不一致
|
|
115
116
|
if (delta > 0) {
|
|
116
117
|
router.go(-delta)
|
|
@@ -5,10 +5,10 @@ import { successHandle, failHandle, defineUnsupportedProps, getFocusedNavigation
|
|
|
5
5
|
|
|
6
6
|
const getWindowInfo = function () {
|
|
7
7
|
const dimensionsScreen = Dimensions.get('screen')
|
|
8
|
-
const navigation = getFocusedNavigation()
|
|
8
|
+
const navigation = getFocusedNavigation()
|
|
9
9
|
const insets = {
|
|
10
|
-
...
|
|
11
|
-
...
|
|
10
|
+
...initialWindowMetrics?.insets,
|
|
11
|
+
...navigation?.insets
|
|
12
12
|
}
|
|
13
13
|
let safeArea = {}
|
|
14
14
|
let { top = 0, bottom = 0, left = 0, right = 0 } = insets
|
|
@@ -17,7 +17,7 @@ const getWindowInfo = function () {
|
|
|
17
17
|
}
|
|
18
18
|
const screenHeight = dimensionsScreen.height
|
|
19
19
|
const screenWidth = dimensionsScreen.width
|
|
20
|
-
const layout = navigation
|
|
20
|
+
const layout = navigation?.layout || {}
|
|
21
21
|
const layoutHeight = layout.height || 0
|
|
22
22
|
const layoutWidth = layout.width || 0
|
|
23
23
|
const windowHeight = layoutHeight || screenHeight
|