@conecli/cone-render 0.10.1-beta.8 → 0.10.1-beta.9
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/dist/common/const.ts +1 -1
- package/dist/common/index.h5.ts +1 -1
- package/dist/common/jssdk.ts +1 -1
- package/dist/common/token/token.jd.ts +1 -1
- package/dist/components/base/CustomScrollView/index.tsx +1 -1
- package/dist/components/base/InOrOutViewObserver/index.tsx +1 -1
- package/dist/components/base/InViewRender/index.tsx +1 -1
- package/dist/components/base/InViewRender/index.weapp.tsx +1 -1
- package/dist/components/base/LazyLayoutLoad/index.tsx +1 -1
- package/dist/components/base/LazyLayoutLoad/index.weapp.tsx +1 -1
- package/dist/components/base/LazyLoadImage/index.h5.module.scss +4 -8
- package/dist/components/base/LazyLoadImage/index.h5.tsx +1 -1
- package/dist/components/base/LazyLoadImage/index.tsx +1 -1
- package/dist/components/base/NetworkDataError/index.tsx +1 -1
- package/dist/components/debug/DebugLayout/index.module.scss +2 -2
- package/dist/components/decorate/PlaceHolder/index.tsx +1 -1
- package/dist/components/floorItem.jd.tsx +1 -1
- package/dist/components/floorItem.tsx +1 -1
- package/dist/components/floorItem.weapp.tsx +1 -1
- package/dist/interface/component.ts +1 -1
- package/dist/interface/jumpEventReport.ts +1 -1
- package/dist/jumpEventReport/logEventConfig.ts +1 -1
- package/dist/jumpEventReport/web.tjm.ts +1 -1
- package/dist/open/api/device.ts +1 -1
- package/dist/sass/app.h5.scss +0 -18
- package/dist/service/http/colorSign.ts +1 -1
- package/dist/service/requestServer.ts +1 -1
- package/dist/utils/connectNativeJsBridge.ts +1 -1
- package/dist/utils/index.h5.ts +1 -1
- package/dist/utils/taroRenderUtil.ts +1 -1
- package/dist/utils/utils.ts +1 -1
- package/package.json +53 -64
- package/dist/components/base/CustomScrollView/index-back.tsx +0 -1
- package/dist/utils/log.ts +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import Taro from '@tarojs/taro'
|
|
2
1
|
isH5AndJdShopView,
|
|
3
2
|
isH5AndJdShopViewH5Scroll,
|
|
4
3
|
isAppClassifyPage,
|
|
5
4
|
TaroEventType,
|
|
6
5
|
WEBVIEW_STATE,
|
|
7
6
|
M_H5_ROOT_ELE_NODE,
|
|
8
7
|
latestFromNativeMsgStorage,
|
|
9
8
|
getNativePageScrollRes,
|
|
10
9
|
props: ComponentInterFace.InOrOutViewObserverProps,
|
|
11
10
|
const {
|
|
12
11
|
children,
|
|
13
12
|
style,
|
|
14
13
|
inViewCallback,
|
|
15
14
|
outViewCallback,
|
|
16
15
|
threshold = 0,
|
|
17
16
|
} = props
|
|
18
17
|
const [componentShowState, setComponentShowState] = useState(false)
|
|
19
18
|
const componentObserverRef = useRef<HTMLElement | null>(null)
|
|
20
19
|
const componentShowStateRef = useRef(false)
|
|
21
20
|
const needShowHighVersion =
|
|
22
21
|
isAppClassifyPage ||
|
|
23
22
|
(isH5AndJdShopViewH5Scroll &&
|
|
24
23
|
!(
|
|
25
24
|
global.info.queryInfo?.downgraded &&
|
|
26
25
|
global.info.queryInfo.downgraded === 'true'
|
|
27
26
|
))
|
|
28
27
|
const rootDom =
|
|
29
28
|
isH5AndJdShopView && needShowHighVersion
|
|
30
29
|
? null
|
|
31
30
|
: document.querySelector(`${M_H5_ROOT_ELE_NODE}`)
|
|
32
31
|
if (isH5AndJdShopView && !needShowHighVersion) {
|
|
33
32
|
useEffect(() => {
|
|
34
33
|
const latestRes =
|
|
35
34
|
latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] || {}
|
|
36
35
|
dealPageScrollInfo(latestRes)
|
|
37
36
|
Taro.eventCenter.on(TaroEventType.PAGE_SCROLL, res => {
|
|
38
37
|
dealPageScrollInfo(res)
|
|
39
38
|
})
|
|
40
39
|
Taro.eventCenter.on(
|
|
41
40
|
TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE,
|
|
42
41
|
state => {
|
|
43
42
|
state === WEBVIEW_STATE.NOT_VISIBLE && handleInOrOutView(false)
|
|
44
43
|
},
|
|
45
44
|
)
|
|
46
45
|
return function cleanup() {
|
|
47
46
|
Taro.eventCenter.off(TaroEventType.PAGE_SCROLL, res => {
|
|
48
47
|
dealPageScrollInfo(res)
|
|
49
48
|
})
|
|
50
49
|
Taro.eventCenter.off(
|
|
51
50
|
TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE,
|
|
52
51
|
state => {
|
|
53
52
|
state === WEBVIEW_STATE.NOT_VISIBLE && handleInOrOutView(false)
|
|
54
53
|
},
|
|
55
54
|
)
|
|
56
55
|
}
|
|
57
56
|
}, [])
|
|
58
57
|
useEffect(() => {
|
|
59
58
|
if (componentShowState) {
|
|
60
59
|
typeof inViewCallback === 'function' && inViewCallback()
|
|
61
60
|
console.log('app=>in可视区域')
|
|
62
61
|
} else {
|
|
63
62
|
typeof outViewCallback === 'function' && outViewCallback()
|
|
64
63
|
console.log('app=>out可视区域')
|
|
65
64
|
}
|
|
66
65
|
}, [componentShowState])
|
|
67
66
|
|
|
68
67
|
const handleInOrOutView = (type: boolean) => {
|
|
69
68
|
componentShowStateRef.current = type
|
|
70
69
|
setComponentShowState(type)
|
|
71
70
|
}
|
|
72
71
|
|
|
73
72
|
const dealPageScrollInfo = res => {
|
|
74
73
|
const { displayHeight, offSetY } = getNativePageScrollRes(res) || {}
|
|
75
74
|
if (
|
|
76
75
|
typeof displayHeight === 'undefined' ||
|
|
77
76
|
typeof offSetY === 'undefined'
|
|
78
77
|
)
|
|
79
78
|
return
|
|
80
79
|
if (componentObserverRef.current) {
|
|
81
80
|
const eleClientRect = componentObserverRef.current.getBoundingClientRect()
|
|
82
81
|
const eleOffsetTop = Math.ceil(eleClientRect.top)
|
|
83
82
|
const eleHeight = Math.ceil(eleClientRect.height)
|
|
84
83
|
if (eleOffsetTop >= 0 && eleOffsetTop < displayHeight) {
|
|
85
84
|
const isOutView =
|
|
86
85
|
offSetY > eleOffsetTop + Math.ceil(eleHeight * (1 - threshold)) ||
|
|
87
86
|
displayHeight - (eleOffsetTop - offSetY) <
|
|
88
87
|
Math.ceil(eleHeight * threshold)
|
|
89
88
|
handleInOrOutView(!isOutView)
|
|
90
89
|
} else {
|
|
91
90
|
const isInView =
|
|
92
91
|
offSetY >
|
|
93
92
|
eleOffsetTop - displayHeight + Math.ceil(eleHeight * threshold) &&
|
|
94
93
|
offSetY < eleOffsetTop + Math.ceil(eleHeight * (1 - threshold))
|
|
95
94
|
handleInOrOutView(isInView)
|
|
96
95
|
}
|
|
97
96
|
}
|
|
98
97
|
}
|
|
99
98
|
return (
|
|
100
99
|
<View ref={componentObserverRef} style={style}>
|
|
101
100
|
{children}
|
|
102
101
|
</View>
|
|
103
102
|
)
|
|
104
103
|
} else {
|
|
105
104
|
const { ref, inView } = useInView({
|
|
106
105
|
delay: 100,
|
|
107
106
|
threshold,
|
|
108
107
|
triggerOnce: false,
|
|
109
108
|
root: rootDom || null,
|
|
110
109
|
rootMargin: `0px 0px 0px 0px`,
|
|
111
110
|
})
|
|
112
111
|
useEffect(() => {
|
|
113
112
|
if (inView) {
|
|
114
113
|
typeof inViewCallback === 'function' && inViewCallback()
|
|
115
114
|
console.log('其他h5=>in可视区域')
|
|
116
115
|
} else {
|
|
117
116
|
typeof outViewCallback === 'function' && outViewCallback()
|
|
118
117
|
console.log('其他h5=>out可视区域')
|
|
119
118
|
}
|
|
120
119
|
}, [inView])
|
|
121
120
|
return (
|
|
122
121
|
<View ref={ref} style={style}>
|
|
123
122
|
{children}
|
|
124
123
|
</View>
|
|
125
124
|
)
|
|
126
125
|
}
|
|
127
126
|
children: null,
|
|
128
127
|
style: {},
|
|
129
128
|
className: '',
|
|
130
129
|
inViewCallback: null,
|
|
131
130
|
outViewCallback: null,
|
|
132
131
|
threshold: 0,
|
|
132
|
+
import Taro from '@tarojs/taro'
|
|
133
133
|
isH5AndJdShopView,
|
|
134
134
|
isH5AndJdShopViewH5Scroll,
|
|
135
135
|
isAppClassifyPage,
|
|
136
136
|
TaroEventType,
|
|
137
137
|
WEBVIEW_STATE,
|
|
138
138
|
M_H5_ROOT_ELE_NODE,
|
|
139
139
|
latestFromNativeMsgStorage,
|
|
140
140
|
getNativePageScrollRes,
|
|
141
141
|
props: ComponentInterFace.InOrOutViewObserverProps,
|
|
142
142
|
const {
|
|
143
143
|
children,
|
|
144
144
|
style,
|
|
145
145
|
inViewCallback,
|
|
146
146
|
outViewCallback,
|
|
147
147
|
threshold = 0,
|
|
148
148
|
} = props
|
|
149
149
|
const [componentShowState, setComponentShowState] = useState(false)
|
|
150
150
|
const componentObserverRef = useRef<HTMLElement | null>(null)
|
|
151
151
|
const componentShowStateRef = useRef(false)
|
|
152
152
|
const needShowHighVersion =
|
|
153
153
|
isAppClassifyPage ||
|
|
154
154
|
(isH5AndJdShopViewH5Scroll &&
|
|
155
155
|
!(
|
|
156
156
|
global.info.queryInfo?.downgraded &&
|
|
157
157
|
global.info.queryInfo.downgraded === 'true'
|
|
158
158
|
))
|
|
159
159
|
const rootDom =
|
|
160
160
|
isH5AndJdShopView && needShowHighVersion
|
|
161
161
|
? null
|
|
162
162
|
: document.querySelector(`${M_H5_ROOT_ELE_NODE}`)
|
|
163
163
|
if (isH5AndJdShopView && !needShowHighVersion) {
|
|
164
164
|
console.log('视频========属于app原生滚动')
|
|
165
165
|
useEffect(() => {
|
|
166
166
|
const latestRes =
|
|
167
167
|
latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] || {}
|
|
168
168
|
dealPageScrollInfo(latestRes)
|
|
169
169
|
Taro.eventCenter.on(TaroEventType.PAGE_SCROLL, res => {
|
|
170
170
|
dealPageScrollInfo(res)
|
|
171
171
|
})
|
|
172
172
|
Taro.eventCenter.on(
|
|
173
173
|
TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE,
|
|
174
174
|
state => {
|
|
175
175
|
state === WEBVIEW_STATE.NOT_VISIBLE && handleInOrOutView(false)
|
|
176
176
|
},
|
|
177
177
|
)
|
|
178
178
|
return function cleanup() {
|
|
179
179
|
Taro.eventCenter.off(TaroEventType.PAGE_SCROLL, res => {
|
|
180
180
|
dealPageScrollInfo(res)
|
|
181
181
|
})
|
|
182
182
|
Taro.eventCenter.off(
|
|
183
183
|
TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE,
|
|
184
184
|
state => {
|
|
185
185
|
state === WEBVIEW_STATE.NOT_VISIBLE && handleInOrOutView(false)
|
|
186
186
|
},
|
|
187
187
|
)
|
|
188
188
|
}
|
|
189
189
|
}, [])
|
|
190
190
|
useEffect(() => {
|
|
191
191
|
if (componentShowState) {
|
|
192
192
|
typeof inViewCallback === 'function' && inViewCallback()
|
|
193
193
|
console.log('app=>in可视区域')
|
|
194
194
|
} else {
|
|
195
195
|
typeof outViewCallback === 'function' && outViewCallback()
|
|
196
196
|
console.log('app=>out可视区域')
|
|
197
197
|
}
|
|
198
198
|
}, [componentShowState])
|
|
199
199
|
|
|
200
200
|
const handleInOrOutView = (type: boolean) => {
|
|
201
201
|
componentShowStateRef.current = type
|
|
202
202
|
setComponentShowState(type)
|
|
203
203
|
console.log('handleInOrOutView', type)
|
|
204
204
|
}
|
|
205
205
|
|
|
206
206
|
const dealPageScrollInfo = res => {
|
|
207
207
|
console.log('dealPageScrollInfo===', res)
|
|
208
208
|
const { displayHeight, offSetY } = getNativePageScrollRes(res) || {}
|
|
209
209
|
if (
|
|
210
210
|
typeof displayHeight === 'undefined' ||
|
|
211
211
|
typeof offSetY === 'undefined'
|
|
212
212
|
)
|
|
213
213
|
return
|
|
214
214
|
console.log(
|
|
215
215
|
'处理后dealPageScrollInfo===displayHeight=offSetY',
|
|
216
216
|
displayHeight,
|
|
217
217
|
offSetY,
|
|
218
218
|
)
|
|
219
219
|
if (componentObserverRef.current) {
|
|
220
220
|
const eleClientRect = componentObserverRef.current.getBoundingClientRect()
|
|
221
221
|
const eleOffsetTop = Math.ceil(eleClientRect.top)
|
|
222
222
|
const eleHeight = Math.ceil(eleClientRect.height)
|
|
223
223
|
console.log(
|
|
224
224
|
'==========================eleOffsetTop, eleHeight',
|
|
225
225
|
eleOffsetTop,
|
|
226
226
|
eleHeight,
|
|
227
227
|
)
|
|
228
228
|
if (eleOffsetTop >= 0 && eleOffsetTop < displayHeight) {
|
|
229
229
|
const isOutView =
|
|
230
230
|
offSetY > eleOffsetTop + Math.ceil(eleHeight * (1 - threshold)) ||
|
|
231
231
|
displayHeight - (eleOffsetTop - offSetY) <
|
|
232
232
|
Math.ceil(eleHeight * threshold)
|
|
233
233
|
console.log(
|
|
234
234
|
'比较isOutView',
|
|
235
235
|
isOutView,
|
|
236
236
|
offSetY,
|
|
237
237
|
eleOffsetTop + Math.ceil(eleHeight * (1 - threshold)),
|
|
238
238
|
displayHeight - (eleOffsetTop - offSetY),
|
|
239
239
|
Math.ceil(eleHeight * threshold),
|
|
240
240
|
)
|
|
241
241
|
handleInOrOutView(!isOutView)
|
|
242
242
|
} else {
|
|
243
243
|
const isInView =
|
|
244
244
|
offSetY >
|
|
245
245
|
eleOffsetTop - displayHeight + Math.ceil(eleHeight * threshold) &&
|
|
246
246
|
offSetY < eleOffsetTop + Math.ceil(eleHeight * (1 - threshold))
|
|
247
247
|
console.log(
|
|
248
248
|
'比较isInView',
|
|
249
249
|
isInView,
|
|
250
250
|
offSetY,
|
|
251
251
|
eleOffsetTop - displayHeight + Math.ceil(eleHeight * threshold),
|
|
252
252
|
eleOffsetTop + Math.ceil(eleHeight * (1 - threshold)),
|
|
253
253
|
)
|
|
254
254
|
handleInOrOutView(isInView)
|
|
255
255
|
}
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
258
|
return (
|
|
259
259
|
<View ref={componentObserverRef} style={style}>
|
|
260
260
|
{children}
|
|
261
261
|
</View>
|
|
262
262
|
)
|
|
263
263
|
} else {
|
|
264
264
|
console.log('视频========h5滚动')
|
|
265
265
|
const { ref, inView } = useInView({
|
|
266
266
|
delay: 100,
|
|
267
267
|
threshold,
|
|
268
268
|
triggerOnce: false,
|
|
269
269
|
root: rootDom || null,
|
|
270
270
|
rootMargin: `0px 0px 0px 0px`,
|
|
271
271
|
})
|
|
272
272
|
useEffect(() => {
|
|
273
273
|
if (inView) {
|
|
274
274
|
typeof inViewCallback === 'function' && inViewCallback()
|
|
275
275
|
console.log('其他h5=>in可视区域')
|
|
276
276
|
} else {
|
|
277
277
|
typeof outViewCallback === 'function' && outViewCallback()
|
|
278
278
|
console.log('其他h5=>out可视区域')
|
|
279
279
|
}
|
|
280
280
|
}, [inView])
|
|
281
281
|
return (
|
|
282
282
|
<View ref={ref} style={style}>
|
|
283
283
|
{children}
|
|
284
284
|
</View>
|
|
285
285
|
)
|
|
286
286
|
}
|
|
287
287
|
children: null,
|
|
288
288
|
style: {},
|
|
289
289
|
className: '',
|
|
290
290
|
inViewCallback: null,
|
|
291
291
|
outViewCallback: null,
|
|
292
292
|
threshold: 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import Taro from '@tarojs/taro';
|
|
2
1
|
getNativePageScrollRes,
|
|
3
2
|
latestFromNativeMsgStorage,
|
|
4
3
|
const { children, placeholder, height, className, inViewCallback } = props;
|
|
5
4
|
const [componentShowState, setComponentShowState] = useState(false);
|
|
6
5
|
const [componentRenderShowState, setComponentRenderShowState] = useState(false);
|
|
7
6
|
const componentLazyRef = useRef<HTMLElement | null>(null);
|
|
8
7
|
const componentShowStateRef = useRef(false);
|
|
9
8
|
const needShowHighVersion =
|
|
10
9
|
isH5AndJdShopViewH5Scroll &&
|
|
11
10
|
!(global.info.queryInfo?.downgraded && global.info.queryInfo.downgraded === 'true');
|
|
12
11
|
const rootDom =
|
|
13
12
|
isH5AndJdShopView && needShowHighVersion ? null : document.querySelector('#J_shopHomeRoot');
|
|
14
13
|
if (isH5AndJdShopView && !needShowHighVersion && !isAppStowShop) {
|
|
15
14
|
useEffect(() => {
|
|
16
15
|
const latestRes = latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] || {};
|
|
17
16
|
!componentShowStateRef.current && dealPageScrollInfo(latestRes);
|
|
18
17
|
Taro.eventCenter.on(TaroEventType.PAGE_SCROLL, (res) => {
|
|
19
18
|
!componentShowStateRef.current && dealPageScrollInfo(res);
|
|
20
19
|
});
|
|
21
20
|
}, []);
|
|
22
21
|
useEffect(() => {
|
|
23
22
|
if (componentShowState) {
|
|
24
23
|
typeof inViewCallback === 'function' && inViewCallback();
|
|
25
24
|
}
|
|
26
25
|
}, [componentShowState]);
|
|
27
26
|
|
|
28
27
|
const dealPageScrollInfo = (res) => {
|
|
29
28
|
const { displayHeight, offSetY } = getNativePageScrollRes(res) || {};
|
|
30
29
|
if (typeof displayHeight === 'undefined' || typeof offSetY === 'undefined') return;
|
|
31
30
|
if (componentLazyRef.current) {
|
|
32
31
|
const eleClientRect = componentLazyRef.current.getBoundingClientRect();
|
|
33
32
|
const getContainerHeightOffSetY = displayHeight + offSetY;
|
|
34
33
|
const eleOffsetTop = Math.ceil(eleClientRect.top);
|
|
35
34
|
if (!componentShowStateRef.current) {
|
|
36
35
|
if (getContainerHeightOffSetY > eleOffsetTop) {
|
|
37
36
|
componentShowStateRef.current = true;
|
|
38
37
|
setComponentShowState(true);
|
|
39
38
|
Taro.nextTick(() => {
|
|
40
39
|
setComponentRenderShowState(true);
|
|
41
40
|
});
|
|
42
41
|
}
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
44
|
};
|
|
46
45
|
return (
|
|
47
46
|
<View
|
|
48
47
|
ref={componentLazyRef}
|
|
49
48
|
className={classNames(
|
|
50
49
|
lazyLayoutLoadStyle['d-app-floor-lazy-layout-load'],
|
|
51
50
|
'd-app-floor-lazy-load',
|
|
52
51
|
className,
|
|
53
52
|
)}
|
|
54
53
|
style={{
|
|
55
54
|
minHeight: `${
|
|
56
55
|
componentRenderShowState ? 'auto' : height + (typeof height === 'number' ? 'px' : '')
|
|
57
56
|
}`,
|
|
58
57
|
backgroundColor: componentRenderShowState ? 'transparent' : '#ffffff',
|
|
59
58
|
}}
|
|
60
59
|
>
|
|
61
60
|
{componentShowState ? children : placeholder}
|
|
62
61
|
</View>
|
|
63
62
|
);
|
|
64
63
|
} else {
|
|
65
64
|
const { ref, inView } = useInView({
|
|
66
65
|
threshold: 0.5,
|
|
67
66
|
triggerOnce: true,
|
|
68
67
|
root: rootDom || null,
|
|
69
68
|
rootMargin: `0px 0px 0px 0px`,
|
|
70
69
|
delay: 300,
|
|
71
70
|
});
|
|
72
71
|
useEffect(() => {
|
|
73
72
|
if (inView) {
|
|
74
73
|
typeof inViewCallback === 'function' && inViewCallback();
|
|
75
74
|
}
|
|
76
75
|
}, [inView]);
|
|
77
76
|
return (
|
|
78
77
|
<div
|
|
79
78
|
className={className}
|
|
80
79
|
ref={ref}
|
|
81
80
|
style={{
|
|
82
81
|
minHeight: inView ? 'auto' : typeof height === 'number' ? `${height}px` : height,
|
|
83
82
|
backgroundColor: 'transparent',
|
|
84
83
|
}}
|
|
85
84
|
>
|
|
86
85
|
{inView ? children : placeholder}
|
|
87
86
|
</div>
|
|
88
87
|
);
|
|
89
88
|
}
|
|
90
89
|
children: null,
|
|
91
90
|
placeholder: null,
|
|
92
91
|
height: 1,
|
|
93
92
|
className: '',
|
|
94
93
|
lazyNodeClassName: '',
|
|
95
94
|
inViewCallback: null,
|
|
95
|
+
import Taro from '@tarojs/taro'
|
|
96
96
|
getNativePageScrollRes,
|
|
97
97
|
latestFromNativeMsgStorage,
|
|
98
98
|
const { children, placeholder, height, className, inViewCallback } = props
|
|
99
99
|
const [componentShowState, setComponentShowState] = useState(false)
|
|
100
100
|
const [componentRenderShowState, setComponentRenderShowState] = useState(
|
|
101
101
|
false,
|
|
102
102
|
)
|
|
103
103
|
const componentLazyRef = useRef<HTMLElement | null>(null)
|
|
104
104
|
const componentShowStateRef = useRef(false)
|
|
105
105
|
const needShowHighVersion =
|
|
106
106
|
isH5AndJdShopViewH5Scroll &&
|
|
107
107
|
!(
|
|
108
108
|
global.info.queryInfo?.downgraded &&
|
|
109
109
|
global.info.queryInfo.downgraded === 'true'
|
|
110
110
|
)
|
|
111
111
|
const rootDom =
|
|
112
112
|
isH5AndJdShopView && needShowHighVersion
|
|
113
113
|
? null
|
|
114
114
|
: document.querySelector('#J_shopHomeRoot')
|
|
115
115
|
if (isH5AndJdShopView && !needShowHighVersion && !isAppStowShop) {
|
|
116
116
|
useEffect(() => {
|
|
117
117
|
const latestRes =
|
|
118
118
|
latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] || {}
|
|
119
119
|
!componentShowStateRef.current && dealPageScrollInfo(latestRes)
|
|
120
120
|
Taro.eventCenter.on(TaroEventType.PAGE_SCROLL, res => {
|
|
121
121
|
!componentShowStateRef.current && dealPageScrollInfo(res)
|
|
122
122
|
})
|
|
123
123
|
}, [])
|
|
124
124
|
useEffect(() => {
|
|
125
125
|
if (componentShowState) {
|
|
126
126
|
typeof inViewCallback === 'function' && inViewCallback()
|
|
127
127
|
}
|
|
128
128
|
}, [componentShowState])
|
|
129
129
|
|
|
130
130
|
const dealPageScrollInfo = res => {
|
|
131
131
|
const { displayHeight, offSetY } = getNativePageScrollRes(res) || {}
|
|
132
132
|
if (
|
|
133
133
|
typeof displayHeight === 'undefined' ||
|
|
134
134
|
typeof offSetY === 'undefined'
|
|
135
135
|
)
|
|
136
136
|
return
|
|
137
137
|
if (componentLazyRef.current) {
|
|
138
138
|
const eleClientRect = componentLazyRef.current.getBoundingClientRect()
|
|
139
139
|
const getContainerHeightOffSetY = displayHeight + offSetY
|
|
140
140
|
const eleOffsetTop = Math.ceil(eleClientRect.top)
|
|
141
141
|
if (!componentShowStateRef.current) {
|
|
142
142
|
if (getContainerHeightOffSetY > eleOffsetTop) {
|
|
143
143
|
componentShowStateRef.current = true
|
|
144
144
|
setComponentShowState(true)
|
|
145
145
|
Taro.nextTick(() => {
|
|
146
146
|
setComponentRenderShowState(true)
|
|
147
147
|
})
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
return (
|
|
153
153
|
<View
|
|
154
154
|
ref={componentLazyRef}
|
|
155
155
|
className={classNames(
|
|
156
156
|
lazyLayoutLoadStyle['d-app-floor-lazy-layout-load'],
|
|
157
157
|
'd-app-floor-lazy-load',
|
|
158
158
|
className,
|
|
159
159
|
)}
|
|
160
160
|
style={{
|
|
161
161
|
minHeight: `${
|
|
162
162
|
componentRenderShowState
|
|
163
163
|
? 'auto'
|
|
164
164
|
: height + (typeof height === 'number' ? 'px' : '')
|
|
165
165
|
}`,
|
|
166
166
|
backgroundColor: componentRenderShowState ? 'transparent' : '#ffffff',
|
|
167
167
|
}}
|
|
168
168
|
>
|
|
169
169
|
{componentShowState ? children : placeholder}
|
|
170
170
|
</View>
|
|
171
171
|
)
|
|
172
172
|
} else {
|
|
173
173
|
const { ref, inView } = useInView({
|
|
174
174
|
threshold: 0.5,
|
|
175
175
|
triggerOnce: true,
|
|
176
176
|
root: rootDom || null,
|
|
177
177
|
rootMargin: `0px 0px 0px 0px`,
|
|
178
178
|
delay: 300,
|
|
179
179
|
})
|
|
180
180
|
useEffect(() => {
|
|
181
181
|
if (inView) {
|
|
182
182
|
typeof inViewCallback === 'function' && inViewCallback()
|
|
183
183
|
}
|
|
184
184
|
}, [inView])
|
|
185
185
|
return (
|
|
186
186
|
<View
|
|
187
187
|
className={className}
|
|
188
188
|
ref={ref}
|
|
189
189
|
style={{
|
|
190
190
|
minHeight: inView
|
|
191
191
|
? 'auto'
|
|
192
192
|
: typeof height === 'number'
|
|
193
193
|
? `${height}px`
|
|
194
194
|
: height,
|
|
195
195
|
backgroundColor: 'transparent',
|
|
196
196
|
}}
|
|
197
197
|
>
|
|
198
198
|
{inView ? children : placeholder}
|
|
199
199
|
</View>
|
|
200
200
|
)
|
|
201
201
|
}
|
|
202
202
|
children: null,
|
|
203
203
|
placeholder: null,
|
|
204
204
|
height: 1,
|
|
205
205
|
className: '',
|
|
206
206
|
lazyNodeClassName: '',
|
|
207
207
|
inViewCallback: null,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import Taro from '@tarojs/taro'
|
|
2
1
|
SECTION_HOME_TAB_TYPE,
|
|
3
2
|
SECTION_HOME_TAB_NAME_TYPE,
|
|
4
3
|
const {
|
|
5
4
|
sectionType = SECTION_HOME_TAB_NAME_TYPE[
|
|
6
5
|
SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN
|
|
7
6
|
],
|
|
8
7
|
type = LazyType.FLOOR,
|
|
9
8
|
children = null,
|
|
10
9
|
placeholder = null,
|
|
11
10
|
height = 200,
|
|
12
11
|
className = '',
|
|
13
12
|
lazyNodeClassName = '',
|
|
14
13
|
containerId,
|
|
15
14
|
} = props
|
|
16
15
|
const [componentShowState, setComponentShowState] = useState(false)
|
|
17
16
|
const componentLazyRef = useRef<HTMLElement | null>(null)
|
|
18
17
|
const lazyLayoutLoadFloor =
|
|
19
18
|
'lazy-layout-load-floor' + Math.floor(Math.random() * 10000000)
|
|
20
19
|
useEffect(() => {
|
|
21
20
|
Taro.nextTick(() => {
|
|
22
21
|
const createIntersectionObserver = new intersectionObserver({
|
|
23
22
|
selector: `.${lazyLayoutLoadFloor}`,
|
|
24
23
|
context: this,
|
|
25
24
|
onFinal: () => {
|
|
26
25
|
setComponentShowState(true)
|
|
27
26
|
createIntersectionObserver.disconnect()
|
|
28
27
|
},
|
|
29
28
|
})
|
|
30
29
|
createIntersectionObserver.connect()
|
|
31
30
|
})
|
|
32
31
|
}, [])
|
|
33
32
|
return type === LazyType.IMAGE ? (
|
|
34
33
|
children
|
|
35
34
|
) : (
|
|
36
35
|
<View
|
|
37
36
|
id={`${containerId}_lazy`}
|
|
38
37
|
ref={componentLazyRef}
|
|
39
38
|
className={classNames(
|
|
40
39
|
lazyLayoutLoadStyle['d-app-floor-lazy-layout-load'],
|
|
41
40
|
'd-app-floor-lazy-load',
|
|
42
41
|
lazyLayoutLoadFloor,
|
|
43
42
|
)}
|
|
44
43
|
style={{
|
|
45
44
|
minHeight: `${componentShowState ? 'auto' : height + 'px'}`,
|
|
46
45
|
backgroundColor: componentShowState ? 'transparent' : '#ffffff',
|
|
47
46
|
}}
|
|
48
47
|
>
|
|
49
48
|
{componentShowState ? children : placeholder}
|
|
50
49
|
</View>
|
|
51
50
|
)
|
|
51
|
+
import Taro from '@tarojs/taro'
|