@mpxjs/webpack-plugin 2.10.7-beta.9 → 2.10.7
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/LICENSE +433 -0
- package/lib/dependencies/RecordPageConfigsMapDependency.js +1 -1
- package/lib/index.js +5 -6
- package/lib/platform/style/wx/index.js +0 -7
- package/lib/platform/template/wx/component-config/index.js +1 -5
- package/lib/platform/template/wx/component-config/movable-view.js +10 -1
- package/lib/platform/template/wx/index.js +2 -1
- package/lib/runtime/components/react/context.ts +4 -23
- package/lib/runtime/components/react/dist/context.js +2 -5
- package/lib/runtime/components/react/dist/getInnerListeners.js +1 -1
- package/lib/runtime/components/react/dist/mpx-button.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +9 -63
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +63 -308
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +15 -31
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +27 -53
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +14 -28
- package/lib/runtime/components/react/dist/useAnimationHooks.js +2 -87
- package/lib/runtime/components/react/getInnerListeners.ts +1 -1
- package/lib/runtime/components/react/mpx-button.tsx +2 -3
- package/lib/runtime/components/react/mpx-movable-area.tsx +11 -98
- package/lib/runtime/components/react/mpx-movable-view.tsx +64 -358
- package/lib/runtime/components/react/mpx-scroll-view.tsx +59 -84
- package/lib/runtime/components/react/mpx-swiper.tsx +25 -53
- package/lib/runtime/components/react/mpx-web-view.tsx +13 -33
- package/lib/runtime/components/react/types/global.d.ts +15 -0
- package/lib/runtime/components/react/useAnimationHooks.ts +2 -85
- package/lib/runtime/components/web/mpx-scroll-view.vue +4 -18
- package/lib/template-compiler/bind-this.js +1 -2
- package/lib/template-compiler/compiler.js +2 -2
- package/package.json +4 -4
- package/lib/platform/template/wx/component-config/sticky-header.js +0 -23
- package/lib/platform/template/wx/component-config/sticky-section.js +0 -23
- package/lib/runtime/components/react/AsyncContainer.tsx +0 -189
- package/lib/runtime/components/react/dist/AsyncContainer.jsx +0 -141
- package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +0 -117
- package/lib/runtime/components/react/dist/mpx-sticky-section.jsx +0 -45
- package/lib/runtime/components/react/mpx-sticky-header.tsx +0 -181
- package/lib/runtime/components/react/mpx-sticky-section.tsx +0 -96
- package/lib/runtime/components/web/mpx-sticky-header.vue +0 -99
- package/lib/runtime/components/web/mpx-sticky-section.vue +0 -15
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef, useContext, forwardRef, useMemo, createElement, ReactNode, useId } from 'react'
|
|
2
|
-
import { Animated, StyleSheet, View, NativeSyntheticEvent, ViewStyle, LayoutChangeEvent, useAnimatedValue } from 'react-native'
|
|
3
|
-
import { ScrollViewContext, StickyContext } from './context'
|
|
4
|
-
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
5
|
-
import { splitProps, splitStyle, useTransformStyle, wrapChildren, useLayout, extendObject } from './utils'
|
|
6
|
-
import { error } from '@mpxjs/utils'
|
|
7
|
-
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
8
|
-
|
|
9
|
-
interface StickyHeaderProps {
|
|
10
|
-
children?: ReactNode;
|
|
11
|
-
style?: ViewStyle;
|
|
12
|
-
padding?: [number, number, number, number];
|
|
13
|
-
'offset-top'?: number;
|
|
14
|
-
'enable-var'?: boolean;
|
|
15
|
-
'external-var-context'?: Record<string, any>;
|
|
16
|
-
'parent-font-size'?: number;
|
|
17
|
-
'parent-width'?: number;
|
|
18
|
-
'parent-height'?: number;
|
|
19
|
-
bindstickontopchange?: (e: NativeSyntheticEvent<unknown>) => void;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const _StickyHeader = forwardRef<HandlerRef<View, StickyHeaderProps>, StickyHeaderProps>((stickyHeaderProps: StickyHeaderProps = {}, ref): JSX.Element => {
|
|
23
|
-
const { textProps, innerProps: props = {} } = splitProps(stickyHeaderProps)
|
|
24
|
-
const {
|
|
25
|
-
style,
|
|
26
|
-
bindstickontopchange,
|
|
27
|
-
padding = [0, 0, 0, 0],
|
|
28
|
-
'offset-top': offsetTop = 0,
|
|
29
|
-
'enable-var': enableVar,
|
|
30
|
-
'external-var-context': externalVarContext,
|
|
31
|
-
'parent-font-size': parentFontSize,
|
|
32
|
-
'parent-width': parentWidth,
|
|
33
|
-
'parent-height': parentHeight
|
|
34
|
-
} = props
|
|
35
|
-
|
|
36
|
-
const scrollViewContext = useContext(ScrollViewContext)
|
|
37
|
-
const stickyContext = useContext(StickyContext)
|
|
38
|
-
const { scrollOffset } = scrollViewContext
|
|
39
|
-
const { registerStickyHeader, unregisterStickyHeader } = stickyContext
|
|
40
|
-
const headerRef = useRef<View>(null)
|
|
41
|
-
const isStickOnTopRef = useRef(false)
|
|
42
|
-
const id = useId()
|
|
43
|
-
|
|
44
|
-
const {
|
|
45
|
-
normalStyle,
|
|
46
|
-
hasVarDec,
|
|
47
|
-
varContextRef,
|
|
48
|
-
hasSelfPercent,
|
|
49
|
-
setWidth,
|
|
50
|
-
setHeight
|
|
51
|
-
} = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
|
|
52
|
-
|
|
53
|
-
const { layoutRef, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: headerRef, onLayout })
|
|
54
|
-
|
|
55
|
-
const { textStyle, innerStyle = {} } = splitStyle(normalStyle)
|
|
56
|
-
|
|
57
|
-
const headerTopAnimated = useAnimatedValue(0)
|
|
58
|
-
// harmony animatedValue 不支持通过 _value 访问
|
|
59
|
-
const headerTopRef = useRef(0)
|
|
60
|
-
|
|
61
|
-
useEffect(() => {
|
|
62
|
-
registerStickyHeader({ key: id, updatePosition })
|
|
63
|
-
return () => {
|
|
64
|
-
unregisterStickyHeader(id)
|
|
65
|
-
}
|
|
66
|
-
}, [])
|
|
67
|
-
|
|
68
|
-
function updatePosition () {
|
|
69
|
-
if (headerRef.current) {
|
|
70
|
-
const scrollViewRef = scrollViewContext.gestureRef
|
|
71
|
-
if (scrollViewRef && scrollViewRef.current) {
|
|
72
|
-
headerRef.current.measureLayout(
|
|
73
|
-
scrollViewRef.current,
|
|
74
|
-
(left: number, top: number) => {
|
|
75
|
-
Animated.timing(headerTopAnimated, {
|
|
76
|
-
toValue: top,
|
|
77
|
-
duration: 0,
|
|
78
|
-
useNativeDriver: true
|
|
79
|
-
}).start()
|
|
80
|
-
headerTopRef.current = top
|
|
81
|
-
}
|
|
82
|
-
)
|
|
83
|
-
} else {
|
|
84
|
-
error('StickyHeader measureLayout error: scrollViewRef is not a valid native component reference')
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function onLayout (e: LayoutChangeEvent) {
|
|
90
|
-
updatePosition()
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
useNodesRef(props, ref, headerRef, {
|
|
94
|
-
style: normalStyle
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
useEffect(() => {
|
|
98
|
-
if (!bindstickontopchange) return
|
|
99
|
-
|
|
100
|
-
const listener = scrollOffset.addListener((state: { value: number }) => {
|
|
101
|
-
const currentScrollValue = state.value
|
|
102
|
-
const newIsStickOnTop = currentScrollValue > headerTopRef.current
|
|
103
|
-
if (newIsStickOnTop !== isStickOnTopRef.current) {
|
|
104
|
-
isStickOnTopRef.current = newIsStickOnTop
|
|
105
|
-
bindstickontopchange(
|
|
106
|
-
getCustomEvent('stickontopchange', {}, {
|
|
107
|
-
detail: {
|
|
108
|
-
isStickOnTop: newIsStickOnTop
|
|
109
|
-
},
|
|
110
|
-
layoutRef
|
|
111
|
-
}, props))
|
|
112
|
-
}
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
return () => {
|
|
116
|
-
scrollOffset.removeListener(listener)
|
|
117
|
-
}
|
|
118
|
-
}, [])
|
|
119
|
-
|
|
120
|
-
const animatedStyle = useMemo(() => {
|
|
121
|
-
const translateY = Animated.subtract(scrollOffset, headerTopAnimated).interpolate({
|
|
122
|
-
inputRange: [0, 1],
|
|
123
|
-
outputRange: [0, 1],
|
|
124
|
-
extrapolateLeft: 'clamp',
|
|
125
|
-
extrapolateRight: 'extend'
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
const finalTranslateY = offsetTop === 0
|
|
129
|
-
? translateY
|
|
130
|
-
: Animated.add(
|
|
131
|
-
translateY,
|
|
132
|
-
Animated.subtract(scrollOffset, headerTopAnimated).interpolate({
|
|
133
|
-
inputRange: [0, 1],
|
|
134
|
-
outputRange: [0, offsetTop],
|
|
135
|
-
extrapolate: 'clamp'
|
|
136
|
-
})
|
|
137
|
-
)
|
|
138
|
-
|
|
139
|
-
return {
|
|
140
|
-
transform: [{ translateY: finalTranslateY }]
|
|
141
|
-
}
|
|
142
|
-
}, [scrollOffset, headerTopAnimated, offsetTop])
|
|
143
|
-
|
|
144
|
-
const innerProps = useInnerProps(extendObject({}, props, {
|
|
145
|
-
ref: headerRef,
|
|
146
|
-
style: extendObject({}, styles.content, innerStyle, animatedStyle, {
|
|
147
|
-
paddingTop: padding[0] || 0,
|
|
148
|
-
paddingRight: padding[1] || 0,
|
|
149
|
-
paddingBottom: padding[2] || 0,
|
|
150
|
-
paddingLeft: padding[3] || 0
|
|
151
|
-
})
|
|
152
|
-
}, layoutProps), [], { layoutRef })
|
|
153
|
-
|
|
154
|
-
return (
|
|
155
|
-
createElement(
|
|
156
|
-
Animated.View,
|
|
157
|
-
innerProps,
|
|
158
|
-
wrapChildren(
|
|
159
|
-
props,
|
|
160
|
-
{
|
|
161
|
-
hasVarDec,
|
|
162
|
-
varContext: varContextRef.current,
|
|
163
|
-
textStyle,
|
|
164
|
-
textProps
|
|
165
|
-
}
|
|
166
|
-
)
|
|
167
|
-
)
|
|
168
|
-
)
|
|
169
|
-
})
|
|
170
|
-
|
|
171
|
-
const styles = StyleSheet.create({
|
|
172
|
-
content: {
|
|
173
|
-
width: '100%',
|
|
174
|
-
zIndex: 10,
|
|
175
|
-
// harmony 需要手动设置 relative, zIndex 才生效
|
|
176
|
-
position: 'relative'
|
|
177
|
-
}
|
|
178
|
-
})
|
|
179
|
-
|
|
180
|
-
_StickyHeader.displayName = 'MpxStickyHeader'
|
|
181
|
-
export default _StickyHeader
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { useRef, forwardRef, createElement, ReactNode, useCallback, useMemo } from 'react'
|
|
3
|
-
import { View, ViewStyle } from 'react-native'
|
|
4
|
-
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
5
|
-
import { splitProps, splitStyle, useTransformStyle, wrapChildren, useLayout, extendObject } from './utils'
|
|
6
|
-
import { StickyContext } from './context'
|
|
7
|
-
import useInnerProps from './getInnerListeners'
|
|
8
|
-
|
|
9
|
-
interface StickySectionProps {
|
|
10
|
-
children?: ReactNode;
|
|
11
|
-
style?: ViewStyle;
|
|
12
|
-
'offset-top'?: number;
|
|
13
|
-
'enable-var'?: boolean;
|
|
14
|
-
'external-var-context'?: Record<string, any>;
|
|
15
|
-
'parent-font-size'?: number;
|
|
16
|
-
'parent-width'?: number;
|
|
17
|
-
'parent-height'?: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const _StickySection = forwardRef<HandlerRef<View, StickySectionProps>, StickySectionProps>((stickySectionProps: StickySectionProps = {}, ref): JSX.Element => {
|
|
21
|
-
const { textProps, innerProps: props = {} } = splitProps(stickySectionProps)
|
|
22
|
-
const {
|
|
23
|
-
style,
|
|
24
|
-
'enable-var': enableVar,
|
|
25
|
-
'external-var-context': externalVarContext,
|
|
26
|
-
'parent-font-size': parentFontSize,
|
|
27
|
-
'parent-width': parentWidth,
|
|
28
|
-
'parent-height': parentHeight
|
|
29
|
-
} = props
|
|
30
|
-
const sectionRef = useRef<View>(null)
|
|
31
|
-
|
|
32
|
-
const {
|
|
33
|
-
normalStyle,
|
|
34
|
-
hasVarDec,
|
|
35
|
-
varContextRef,
|
|
36
|
-
hasSelfPercent,
|
|
37
|
-
setWidth,
|
|
38
|
-
setHeight
|
|
39
|
-
} = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
|
|
40
|
-
|
|
41
|
-
const { layoutRef, layoutProps, layoutStyle } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: sectionRef, onLayout })
|
|
42
|
-
|
|
43
|
-
const { textStyle, innerStyle = {} } = splitStyle(normalStyle)
|
|
44
|
-
|
|
45
|
-
const stickyHeaders = useRef<Map<string, any>>(new Map())
|
|
46
|
-
|
|
47
|
-
const registerStickyHeader = useCallback((item: { id: string, updatePosition: Function }) => {
|
|
48
|
-
stickyHeaders.current.set(item.id, item)
|
|
49
|
-
}, [])
|
|
50
|
-
|
|
51
|
-
const unregisterStickyHeader = useCallback((id: string) => {
|
|
52
|
-
stickyHeaders.current.delete(id)
|
|
53
|
-
}, [])
|
|
54
|
-
|
|
55
|
-
const contextValue = useMemo(() => ({
|
|
56
|
-
registerStickyHeader,
|
|
57
|
-
unregisterStickyHeader
|
|
58
|
-
}), [])
|
|
59
|
-
|
|
60
|
-
useNodesRef(props, ref, sectionRef, {
|
|
61
|
-
style: normalStyle
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
function onLayout () {
|
|
65
|
-
stickyHeaders.current.forEach(item => {
|
|
66
|
-
item.updatePosition()
|
|
67
|
-
})
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const innerProps = useInnerProps(extendObject({}, props, {
|
|
71
|
-
style: extendObject(innerStyle, layoutStyle),
|
|
72
|
-
ref: sectionRef
|
|
73
|
-
}, layoutProps), [], { layoutRef })
|
|
74
|
-
|
|
75
|
-
return (
|
|
76
|
-
createElement(
|
|
77
|
-
View,
|
|
78
|
-
innerProps,
|
|
79
|
-
createElement(
|
|
80
|
-
StickyContext.Provider,
|
|
81
|
-
{ value: contextValue },
|
|
82
|
-
wrapChildren(
|
|
83
|
-
props,
|
|
84
|
-
{
|
|
85
|
-
hasVarDec,
|
|
86
|
-
varContext: varContextRef.current,
|
|
87
|
-
textStyle,
|
|
88
|
-
textProps
|
|
89
|
-
}
|
|
90
|
-
)
|
|
91
|
-
))
|
|
92
|
-
)
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
_StickySection.displayName = 'MpxStickySection'
|
|
96
|
-
export default _StickySection
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import { warn } from '@mpxjs/utils'
|
|
3
|
-
import { getCustomEvent } from './getInnerListeners'
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
name: 'mpx-sticky-header',
|
|
7
|
-
inject: ['scrollOffset', 'refreshVersion'],
|
|
8
|
-
props: {
|
|
9
|
-
offsetTop: {
|
|
10
|
-
type: Number,
|
|
11
|
-
default: 0
|
|
12
|
-
},
|
|
13
|
-
padding: Array
|
|
14
|
-
},
|
|
15
|
-
data() {
|
|
16
|
-
return {
|
|
17
|
-
headerTop: 0,
|
|
18
|
-
isStickOnTop: false
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
watch: {
|
|
22
|
-
scrollOffset: {
|
|
23
|
-
handler(newScrollOffset) {
|
|
24
|
-
const newIsStickOnTop = newScrollOffset > this.headerTop
|
|
25
|
-
if (newIsStickOnTop !== this.isStickOnTop) {
|
|
26
|
-
this.isStickOnTop = newIsStickOnTop
|
|
27
|
-
this.$emit('stickontopchange', getCustomEvent('stickontopchange', {
|
|
28
|
-
isStickOnTop: newIsStickOnTop
|
|
29
|
-
}, this))
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
this.setTransformStyle()
|
|
33
|
-
},
|
|
34
|
-
immediate: true
|
|
35
|
-
},
|
|
36
|
-
refreshVersion: {
|
|
37
|
-
handler() {
|
|
38
|
-
this.setHeaderTop()
|
|
39
|
-
this.setTransformStyle()
|
|
40
|
-
},
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
mounted() {
|
|
44
|
-
this.setPaddingStyle()
|
|
45
|
-
this.setHeaderTop()
|
|
46
|
-
},
|
|
47
|
-
methods: {
|
|
48
|
-
setHeaderTop () {
|
|
49
|
-
const parentElement = this.$el.parentElement
|
|
50
|
-
if (!parentElement) return
|
|
51
|
-
|
|
52
|
-
const parentClass = parentElement.className || ''
|
|
53
|
-
const isStickySection = /mpx-sticky-section/.test(parentClass)
|
|
54
|
-
const isScrollViewWrapper = /mpx-inner-wrapper/.test(parentClass)
|
|
55
|
-
|
|
56
|
-
if (!isStickySection && !isScrollViewWrapper) {
|
|
57
|
-
warn('sticky-header only supports being a direct child of a scroll-view or sticky-section component.')
|
|
58
|
-
return
|
|
59
|
-
}
|
|
60
|
-
this.headerTop = isStickySection
|
|
61
|
-
? this.$el.offsetTop + parentElement.offsetTop
|
|
62
|
-
: this.$el.offsetTop
|
|
63
|
-
},
|
|
64
|
-
setPaddingStyle() {
|
|
65
|
-
const stickyHeader = this.$refs.stickyHeader
|
|
66
|
-
if (!stickyHeader) return
|
|
67
|
-
|
|
68
|
-
if (this.padding && Array.isArray(this.padding)) {
|
|
69
|
-
const [top = 0, right = 0, bottom = 0, left = 0] = this.padding
|
|
70
|
-
stickyHeader.style.padding = `${top}px ${right}px ${bottom}px ${left}px`
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
setTransformStyle () {
|
|
74
|
-
const stickyHeader = this.$refs.stickyHeader
|
|
75
|
-
if (!stickyHeader) return
|
|
76
|
-
|
|
77
|
-
// 设置 transform
|
|
78
|
-
if (this.scrollOffset > this.headerTop) {
|
|
79
|
-
stickyHeader.style.transform = `translateY(${this.scrollOffset - this.headerTop + this.offsetTop}px)`
|
|
80
|
-
} else {
|
|
81
|
-
stickyHeader.style.transform = 'none'
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
render(h) {
|
|
86
|
-
const style = {
|
|
87
|
-
width: '100%',
|
|
88
|
-
boxSizing: 'border-box',
|
|
89
|
-
position: 'relative',
|
|
90
|
-
zIndex: 10
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return h('div', {
|
|
94
|
-
style,
|
|
95
|
-
ref: 'stickyHeader'
|
|
96
|
-
}, this.$slots.default)
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
</script>
|