@mpxjs/webpack-plugin 2.9.59 → 2.9.64
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/lib/index.js +1 -3
- package/lib/platform/style/wx/index.js +344 -270
- package/lib/platform/template/wx/component-config/checkbox-group.js +8 -0
- package/lib/platform/template/wx/component-config/checkbox.js +8 -0
- package/lib/platform/template/wx/component-config/cover-image.js +15 -0
- package/lib/platform/template/wx/component-config/cover-view.js +9 -0
- package/lib/platform/template/wx/component-config/form.js +13 -1
- package/lib/platform/template/wx/component-config/icon.js +8 -0
- package/lib/platform/template/wx/component-config/index.js +5 -1
- package/lib/platform/template/wx/component-config/label.js +15 -0
- package/lib/platform/template/wx/component-config/movable-area.js +18 -1
- package/lib/platform/template/wx/component-config/movable-view.js +18 -1
- package/lib/platform/template/wx/component-config/navigator.js +8 -0
- package/lib/platform/template/wx/component-config/picker-view-column.js +8 -0
- package/lib/platform/template/wx/component-config/picker-view.js +18 -2
- package/lib/platform/template/wx/component-config/picker.js +14 -1
- package/lib/platform/template/wx/component-config/radio-group.js +8 -0
- package/lib/platform/template/wx/component-config/radio.js +8 -0
- package/lib/platform/template/wx/component-config/root-portal.js +15 -0
- package/lib/platform/template/wx/component-config/switch.js +8 -0
- package/lib/platform/template/wx/component-config/unsupported.js +1 -3
- package/lib/react/processScript.js +2 -0
- package/lib/react/processStyles.js +1 -0
- package/lib/react/processTemplate.js +2 -3
- package/lib/react/style-helper.js +12 -7
- package/lib/runtime/components/react/context.ts +40 -0
- package/lib/runtime/components/react/dist/context.js +8 -0
- package/lib/runtime/components/react/dist/getInnerListeners.js +34 -12
- package/lib/runtime/components/react/dist/mpx-button.jsx +88 -88
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +82 -0
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +139 -0
- package/lib/runtime/components/react/dist/mpx-form.jsx +61 -0
- package/lib/runtime/components/react/dist/mpx-icon.jsx +48 -0
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +39 -43
- package/lib/runtime/components/react/dist/mpx-image/svg.jsx +3 -2
- package/lib/runtime/components/react/dist/mpx-input.jsx +63 -37
- package/lib/runtime/components/react/dist/mpx-label.jsx +55 -0
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +41 -0
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +346 -0
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +35 -0
- package/lib/runtime/components/react/dist/mpx-picker/date.jsx +69 -0
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +138 -0
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +142 -0
- package/lib/runtime/components/react/dist/mpx-picker/region.jsx +94 -0
- package/lib/runtime/components/react/dist/mpx-picker/regionData.js +6099 -0
- package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +76 -0
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +244 -0
- package/lib/runtime/components/react/dist/mpx-picker/type.js +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +107 -0
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +162 -0
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +80 -0
- package/lib/runtime/components/react/dist/mpx-radio.jsx +154 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +15 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +93 -70
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +281 -157
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +21 -11
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +19 -11
- package/lib/runtime/components/react/dist/mpx-switch.jsx +79 -0
- package/lib/runtime/components/react/dist/mpx-text.jsx +21 -49
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-view.jsx +451 -146
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +17 -20
- package/lib/runtime/components/react/dist/parser.js +218 -0
- package/lib/runtime/components/react/dist/types/common.js +1 -0
- package/lib/runtime/components/react/dist/useNodesRef.js +3 -8
- package/lib/runtime/components/react/dist/utils.jsx +433 -0
- package/lib/runtime/components/react/getInnerListeners.ts +43 -21
- package/lib/runtime/components/react/mpx-button.tsx +129 -119
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +152 -0
- package/lib/runtime/components/react/mpx-checkbox.tsx +234 -0
- package/lib/runtime/components/react/mpx-form.tsx +117 -0
- package/lib/runtime/components/react/mpx-icon.tsx +106 -0
- package/lib/runtime/components/react/mpx-image/index.tsx +62 -68
- package/lib/runtime/components/react/mpx-image/svg.tsx +7 -5
- package/lib/runtime/components/react/mpx-input.tsx +90 -42
- package/lib/runtime/components/react/mpx-label.tsx +110 -0
- package/lib/runtime/components/react/mpx-movable-area.tsx +81 -0
- package/lib/runtime/components/react/mpx-movable-view.tsx +424 -0
- package/lib/runtime/components/react/mpx-navigator.tsx +67 -0
- package/lib/runtime/components/react/mpx-picker/date.tsx +82 -0
- package/lib/runtime/components/react/mpx-picker/index.tsx +155 -0
- package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +156 -0
- package/lib/runtime/components/react/mpx-picker/region.tsx +107 -0
- package/lib/runtime/components/react/mpx-picker/regionData.ts +6101 -0
- package/lib/runtime/components/react/mpx-picker/selector.tsx +91 -0
- package/lib/runtime/components/react/mpx-picker/time.tsx +270 -0
- package/lib/runtime/components/react/mpx-picker/type.ts +107 -0
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +156 -0
- package/lib/runtime/components/react/mpx-picker-view.tsx +220 -0
- package/lib/runtime/components/react/mpx-radio-group.tsx +150 -0
- package/lib/runtime/components/react/mpx-radio.tsx +230 -0
- package/lib/runtime/components/react/mpx-root-portal.tsx +27 -0
- package/lib/runtime/components/react/mpx-scroll-view.tsx +184 -130
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +308 -183
- package/lib/runtime/components/react/mpx-swiper/index.tsx +27 -19
- package/lib/runtime/components/react/mpx-swiper/type.ts +23 -5
- package/lib/runtime/components/react/mpx-swiper-item.tsx +49 -14
- package/lib/runtime/components/react/mpx-switch.tsx +148 -0
- package/lib/runtime/components/react/mpx-text.tsx +53 -77
- package/lib/runtime/components/react/mpx-textarea.tsx +3 -3
- package/lib/runtime/components/react/mpx-view.tsx +576 -195
- package/lib/runtime/components/react/mpx-web-view.tsx +34 -39
- package/lib/runtime/components/react/parser.ts +245 -0
- package/lib/runtime/components/react/types/common.ts +12 -0
- package/lib/runtime/components/react/types/getInnerListeners.ts +2 -1
- package/lib/runtime/components/react/types/global.d.ts +17 -1
- package/lib/runtime/components/react/useNodesRef.ts +4 -10
- package/lib/runtime/components/react/utils.tsx +505 -0
- package/lib/runtime/optionProcessor.js +19 -17
- package/lib/template-compiler/compiler.js +84 -61
- package/lib/template-compiler/gen-node-react.js +7 -9
- package/lib/web/processStyles.js +2 -5
- package/package.json +8 -3
- package/lib/runtime/components/react/dist/utils.js +0 -80
- package/lib/runtime/components/react/utils.ts +0 -92
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ✔ value
|
|
3
|
+
* ✔ disabled
|
|
4
|
+
* ✔ checked
|
|
5
|
+
* ✔ color
|
|
6
|
+
*/
|
|
7
|
+
import { useState, forwardRef, useEffect, useContext } from 'react';
|
|
8
|
+
import { View, StyleSheet } from 'react-native';
|
|
9
|
+
import { warn } from '@mpxjs/utils';
|
|
10
|
+
import { LabelContext, RadioGroupContext } from './context';
|
|
11
|
+
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
12
|
+
import useNodesRef from './useNodesRef';
|
|
13
|
+
import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren } from './utils';
|
|
14
|
+
import Icon from './mpx-icon';
|
|
15
|
+
const styles = StyleSheet.create({
|
|
16
|
+
container: {
|
|
17
|
+
flexDirection: 'row',
|
|
18
|
+
alignItems: 'center'
|
|
19
|
+
},
|
|
20
|
+
wrapper: {
|
|
21
|
+
alignItems: 'center',
|
|
22
|
+
justifyContent: 'center',
|
|
23
|
+
width: 24,
|
|
24
|
+
height: 24,
|
|
25
|
+
borderColor: '#D1D1D1',
|
|
26
|
+
borderWidth: 1,
|
|
27
|
+
borderRadius: 12,
|
|
28
|
+
backgroundColor: '#ffffff',
|
|
29
|
+
marginRight: 5,
|
|
30
|
+
overflow: 'hidden'
|
|
31
|
+
},
|
|
32
|
+
wrapperChecked: {
|
|
33
|
+
borderWidth: 0
|
|
34
|
+
},
|
|
35
|
+
wrapperDisabled: {
|
|
36
|
+
backgroundColor: '#E1E1E1'
|
|
37
|
+
},
|
|
38
|
+
icon: {
|
|
39
|
+
opacity: 0
|
|
40
|
+
},
|
|
41
|
+
iconDisabled: {
|
|
42
|
+
backgroundColor: '#ADADAD'
|
|
43
|
+
},
|
|
44
|
+
iconChecked: {
|
|
45
|
+
opacity: 1
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
const Radio = forwardRef((radioProps, ref) => {
|
|
49
|
+
const { textProps, innerProps: props = {} } = splitProps(radioProps);
|
|
50
|
+
const { value = '', disabled = false, checked = false, color = '#09BB07', style = [], 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, bindtap, catchtap } = props;
|
|
51
|
+
const [isChecked, setIsChecked] = useState(!!checked);
|
|
52
|
+
const groupContext = useContext(RadioGroupContext);
|
|
53
|
+
let groupValue;
|
|
54
|
+
let notifyChange;
|
|
55
|
+
const labelContext = useContext(LabelContext);
|
|
56
|
+
const defaultStyle = {
|
|
57
|
+
...styles.wrapper,
|
|
58
|
+
...(isChecked && styles.wrapperChecked),
|
|
59
|
+
...(disabled && styles.wrapperDisabled)
|
|
60
|
+
};
|
|
61
|
+
const styleObj = {
|
|
62
|
+
...styles.container,
|
|
63
|
+
...style
|
|
64
|
+
};
|
|
65
|
+
const onChange = (evt) => {
|
|
66
|
+
if (disabled || isChecked)
|
|
67
|
+
return;
|
|
68
|
+
setIsChecked(!isChecked);
|
|
69
|
+
if (groupValue) {
|
|
70
|
+
for (const [key, radio] of Object.entries(groupValue)) {
|
|
71
|
+
if (!radio)
|
|
72
|
+
continue;
|
|
73
|
+
radio.setValue(key === value);
|
|
74
|
+
radio.checked = key === value;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
notifyChange && notifyChange(evt);
|
|
78
|
+
};
|
|
79
|
+
const onTap = (evt) => {
|
|
80
|
+
if (disabled)
|
|
81
|
+
return;
|
|
82
|
+
bindtap && bindtap(getCustomEvent('tap', evt, { layoutRef }, props));
|
|
83
|
+
onChange(evt);
|
|
84
|
+
};
|
|
85
|
+
const catchTap = (evt) => {
|
|
86
|
+
if (disabled)
|
|
87
|
+
return;
|
|
88
|
+
catchtap && catchtap(getCustomEvent('tap', evt, { layoutRef }, props));
|
|
89
|
+
};
|
|
90
|
+
const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
|
|
91
|
+
const { textStyle, backgroundStyle, innerStyle } = splitStyle(normalStyle);
|
|
92
|
+
if (backgroundStyle) {
|
|
93
|
+
warn('Radio does not support background image-related styles!');
|
|
94
|
+
}
|
|
95
|
+
const { nodeRef } = useNodesRef(props, ref, {
|
|
96
|
+
defaultStyle,
|
|
97
|
+
change: onChange
|
|
98
|
+
});
|
|
99
|
+
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
|
|
100
|
+
if (groupContext) {
|
|
101
|
+
groupValue = groupContext.groupValue;
|
|
102
|
+
notifyChange = groupContext.notifyChange;
|
|
103
|
+
}
|
|
104
|
+
if (labelContext) {
|
|
105
|
+
labelContext.current.triggerChange = onChange;
|
|
106
|
+
}
|
|
107
|
+
const innerProps = useInnerProps(props, {
|
|
108
|
+
ref: nodeRef,
|
|
109
|
+
style: { ...innerStyle, ...layoutStyle },
|
|
110
|
+
...layoutProps,
|
|
111
|
+
bindtap: onTap,
|
|
112
|
+
catchtap: catchTap
|
|
113
|
+
}, [], {
|
|
114
|
+
layoutRef
|
|
115
|
+
});
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
if (groupValue) {
|
|
118
|
+
groupValue[value] = {
|
|
119
|
+
checked: checked,
|
|
120
|
+
setValue: setIsChecked
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return () => {
|
|
124
|
+
if (groupValue) {
|
|
125
|
+
delete groupValue[value];
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}, []);
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
if (checked !== isChecked) {
|
|
131
|
+
setIsChecked(checked);
|
|
132
|
+
if (groupValue) {
|
|
133
|
+
groupValue[value].checked = checked;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}, [checked]);
|
|
137
|
+
return (<View {...innerProps}>
|
|
138
|
+
<View style={defaultStyle}>
|
|
139
|
+
<Icon type='success' size={24} color={disabled ? '#E1E1E1' : color} style={{
|
|
140
|
+
...styles.icon,
|
|
141
|
+
...(isChecked && styles.iconChecked),
|
|
142
|
+
...(disabled && styles.iconDisabled)
|
|
143
|
+
}}/>
|
|
144
|
+
</View>
|
|
145
|
+
{wrapChildren(props, {
|
|
146
|
+
hasVarDec,
|
|
147
|
+
varContext: varContextRef.current,
|
|
148
|
+
textStyle,
|
|
149
|
+
textProps
|
|
150
|
+
})}
|
|
151
|
+
</View>);
|
|
152
|
+
});
|
|
153
|
+
Radio.displayName = 'mpx-radio';
|
|
154
|
+
export default Radio;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Portal } from '@ant-design/react-native';
|
|
2
|
+
import { warn } from '@mpxjs/utils';
|
|
3
|
+
const _RootPortal = (props) => {
|
|
4
|
+
const { children, enable = true } = props;
|
|
5
|
+
if (props.style) {
|
|
6
|
+
warn('The root-portal component does not support the style prop.');
|
|
7
|
+
}
|
|
8
|
+
return enable
|
|
9
|
+
? <Portal>
|
|
10
|
+
{children}
|
|
11
|
+
</Portal>
|
|
12
|
+
: <>{children}</>;
|
|
13
|
+
};
|
|
14
|
+
_RootPortal.displayName = 'mpx-root-portal';
|
|
15
|
+
export default _RootPortal;
|
|
@@ -31,32 +31,36 @@
|
|
|
31
31
|
* ✔ bindscrolltolower
|
|
32
32
|
* ✔ bindscroll
|
|
33
33
|
*/
|
|
34
|
-
import { ScrollView
|
|
35
|
-
import
|
|
34
|
+
import { ScrollView } from 'react-native-gesture-handler';
|
|
35
|
+
import { RefreshControl } from 'react-native';
|
|
36
|
+
import { useRef, useState, useEffect, forwardRef } from 'react';
|
|
37
|
+
import { warn } from '@mpxjs/utils';
|
|
36
38
|
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
37
39
|
import useNodesRef from './useNodesRef';
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
const
|
|
40
|
+
import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren } from './utils';
|
|
41
|
+
const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
42
|
+
const { textProps, innerProps: props = {} } = splitProps(scrollViewProps);
|
|
43
|
+
const { enhanced = false, bounces = true, style = {}, 'scroll-x': scrollX = false, 'scroll-y': scrollY = false, 'enable-back-to-top': enableBackToTop = false, 'paging-enabled': pagingEnabled = false, 'upper-threshold': upperThreshold = 50, 'lower-threshold': lowerThreshold = 50, 'scroll-with-animation': scrollWithAnimation, 'refresher-enabled': refresherEnabled, 'refresher-default-style': refresherDefaultStyle, 'refresher-background': refresherBackground, 'show-scrollbar': showScrollbar = true, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props;
|
|
42
44
|
const [refreshing, setRefreshing] = useState(true);
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
+
const snapScrollTop = useRef(0);
|
|
46
|
+
const snapScrollLeft = useRef(0);
|
|
45
47
|
const scrollOptions = useRef({
|
|
46
48
|
contentLength: 0,
|
|
47
49
|
offset: 0,
|
|
48
50
|
scrollLeft: 0,
|
|
49
51
|
scrollTop: 0,
|
|
50
|
-
visibleLength: 0
|
|
52
|
+
visibleLength: 0
|
|
51
53
|
});
|
|
52
54
|
const scrollEventThrottle = 50;
|
|
53
55
|
const hasCallScrollToUpper = useRef(true);
|
|
54
56
|
const hasCallScrollToLower = useRef(false);
|
|
55
57
|
const initialTimeout = useRef(null);
|
|
58
|
+
const { normalStyle, hasVarDec, varContextRef, hasSelfPercent, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
|
|
59
|
+
const { textStyle, innerStyle } = splitStyle(normalStyle);
|
|
56
60
|
const { nodeRef: scrollViewRef } = useNodesRef(props, ref, {
|
|
57
61
|
scrollOffset: scrollOptions,
|
|
58
62
|
node: {
|
|
59
|
-
scrollEnabled,
|
|
63
|
+
scrollEnabled: scrollX || scrollY,
|
|
60
64
|
bounces,
|
|
61
65
|
showScrollbar,
|
|
62
66
|
pagingEnabled,
|
|
@@ -65,11 +69,21 @@ const _ScrollView = forwardRef((props = {}, ref) => {
|
|
|
65
69
|
scrollTo: scrollToOffset
|
|
66
70
|
}
|
|
67
71
|
});
|
|
72
|
+
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: scrollViewRef, onLayout });
|
|
73
|
+
if (scrollX && scrollY) {
|
|
74
|
+
warn('scroll-x and scroll-y cannot be set to true at the same time, Mpx will use the value of scroll-y as the criterion');
|
|
75
|
+
}
|
|
68
76
|
useEffect(() => {
|
|
69
|
-
if (snapScrollTop !== props['scroll-top'] ||
|
|
70
|
-
snapScrollLeft !== props['scroll-left']) {
|
|
71
|
-
|
|
72
|
-
|
|
77
|
+
if (snapScrollTop.current !== props['scroll-top'] ||
|
|
78
|
+
snapScrollLeft.current !== props['scroll-left']) {
|
|
79
|
+
snapScrollTop.current = props['scroll-top'] || 0;
|
|
80
|
+
snapScrollLeft.current = props['scroll-left'] || 0;
|
|
81
|
+
initialTimeout.current = setTimeout(() => {
|
|
82
|
+
scrollToOffset(snapScrollLeft.current, snapScrollTop.current);
|
|
83
|
+
}, 0);
|
|
84
|
+
return () => {
|
|
85
|
+
initialTimeout.current && clearTimeout(initialTimeout.current);
|
|
86
|
+
};
|
|
73
87
|
}
|
|
74
88
|
}, [props['scroll-top'], props['scroll-left']]);
|
|
75
89
|
useEffect(() => {
|
|
@@ -77,24 +91,6 @@ const _ScrollView = forwardRef((props = {}, ref) => {
|
|
|
77
91
|
setRefreshing(!!props['refresher-triggered']);
|
|
78
92
|
}
|
|
79
93
|
}, [props['refresher-triggered']]);
|
|
80
|
-
useEffect(() => {
|
|
81
|
-
if (!props['scroll-x'] && !props['scroll-y']) {
|
|
82
|
-
setScrollEnabled(false);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
setScrollEnabled(true);
|
|
86
|
-
}
|
|
87
|
-
}, [props['scroll-x'], props['scroll-y']]);
|
|
88
|
-
useEffect(() => {
|
|
89
|
-
if (snapScrollTop || snapScrollLeft) {
|
|
90
|
-
initialTimeout.current = setTimeout(() => {
|
|
91
|
-
scrollToOffset(snapScrollLeft, snapScrollTop);
|
|
92
|
-
}, 0);
|
|
93
|
-
}
|
|
94
|
-
return () => {
|
|
95
|
-
initialTimeout.current && clearTimeout(initialTimeout.current);
|
|
96
|
-
};
|
|
97
|
-
}, [snapScrollTop, snapScrollLeft]);
|
|
98
94
|
function selectLength(size) {
|
|
99
95
|
return !scrollX ? size.height : size.width;
|
|
100
96
|
}
|
|
@@ -108,7 +104,7 @@ const _ScrollView = forwardRef((props = {}, ref) => {
|
|
|
108
104
|
if (!hasCallScrollToUpper.current) {
|
|
109
105
|
bindscrolltoupper(getCustomEvent('scrolltoupper', e, {
|
|
110
106
|
detail: {
|
|
111
|
-
direction: scrollX ? 'left' : 'top'
|
|
107
|
+
direction: scrollX ? 'left' : 'top'
|
|
112
108
|
},
|
|
113
109
|
layoutRef
|
|
114
110
|
}, props));
|
|
@@ -128,7 +124,7 @@ const _ScrollView = forwardRef((props = {}, ref) => {
|
|
|
128
124
|
hasCallScrollToLower.current = true;
|
|
129
125
|
bindscrolltolower(getCustomEvent('scrolltolower', e, {
|
|
130
126
|
detail: {
|
|
131
|
-
direction: scrollX ? 'right' : 'botttom'
|
|
127
|
+
direction: scrollX ? 'right' : 'botttom'
|
|
132
128
|
},
|
|
133
129
|
layoutRef
|
|
134
130
|
}, props));
|
|
@@ -142,12 +138,21 @@ const _ScrollView = forwardRef((props = {}, ref) => {
|
|
|
142
138
|
scrollOptions.current.contentLength = selectLength({ height, width });
|
|
143
139
|
}
|
|
144
140
|
function onLayout(e) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
141
|
+
const layout = e.nativeEvent.layout || {};
|
|
142
|
+
scrollOptions.current.visibleLength = selectLength(layout);
|
|
143
|
+
}
|
|
144
|
+
function updateScrollOptions(e, position) {
|
|
145
|
+
const visibleLength = selectLength(e.nativeEvent.layoutMeasurement);
|
|
146
|
+
const contentLength = selectLength(e.nativeEvent.contentSize);
|
|
147
|
+
const offset = selectOffset(e.nativeEvent.contentOffset);
|
|
148
|
+
scrollOptions.current = {
|
|
149
|
+
...scrollOptions.current,
|
|
150
|
+
contentLength,
|
|
151
|
+
offset,
|
|
152
|
+
scrollLeft: position.scrollLeft,
|
|
153
|
+
scrollTop: position.scrollTop,
|
|
154
|
+
visibleLength
|
|
155
|
+
};
|
|
151
156
|
}
|
|
152
157
|
function onScroll(e) {
|
|
153
158
|
const { bindscroll } = props;
|
|
@@ -161,21 +166,27 @@ const _ScrollView = forwardRef((props = {}, ref) => {
|
|
|
161
166
|
scrollHeight,
|
|
162
167
|
scrollWidth,
|
|
163
168
|
deltaX: scrollLeft - scrollOptions.current.scrollLeft,
|
|
164
|
-
deltaY: scrollTop - scrollOptions.current.scrollTop
|
|
169
|
+
deltaY: scrollTop - scrollOptions.current.scrollTop
|
|
165
170
|
},
|
|
166
171
|
layoutRef
|
|
167
172
|
}, props));
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
173
|
+
updateScrollOptions(e, { scrollLeft, scrollTop });
|
|
174
|
+
}
|
|
175
|
+
function onScrollEnd(e) {
|
|
176
|
+
const { bindscrollend } = props;
|
|
177
|
+
const { x: scrollLeft, y: scrollTop } = e.nativeEvent.contentOffset;
|
|
178
|
+
const { width: scrollWidth, height: scrollHeight } = e.nativeEvent.contentSize;
|
|
179
|
+
bindscrollend &&
|
|
180
|
+
bindscrollend(getCustomEvent('scrollend', e, {
|
|
181
|
+
detail: {
|
|
182
|
+
scrollLeft,
|
|
183
|
+
scrollTop,
|
|
184
|
+
scrollHeight,
|
|
185
|
+
scrollWidth
|
|
186
|
+
},
|
|
187
|
+
layoutRef
|
|
188
|
+
}, props));
|
|
189
|
+
updateScrollOptions(e, { scrollLeft, scrollTop });
|
|
179
190
|
onStartReached(e);
|
|
180
191
|
onEndReached(e);
|
|
181
192
|
}
|
|
@@ -198,8 +209,8 @@ const _ScrollView = forwardRef((props = {}, ref) => {
|
|
|
198
209
|
binddragstart &&
|
|
199
210
|
binddragstart(getCustomEvent('dragstart', e, {
|
|
200
211
|
detail: {
|
|
201
|
-
scrollLeft: scrollOptions.current.scrollLeft
|
|
202
|
-
scrollTop: scrollOptions.current.scrollTop
|
|
212
|
+
scrollLeft: scrollOptions.current.scrollLeft,
|
|
213
|
+
scrollTop: scrollOptions.current.scrollTop
|
|
203
214
|
},
|
|
204
215
|
layoutRef
|
|
205
216
|
}, props));
|
|
@@ -213,51 +224,56 @@ const _ScrollView = forwardRef((props = {}, ref) => {
|
|
|
213
224
|
binddragging(getCustomEvent('dragging', e, {
|
|
214
225
|
detail: {
|
|
215
226
|
scrollLeft: scrollOptions.current.scrollLeft || 0,
|
|
216
|
-
scrollTop: scrollOptions.current.scrollTop || 0
|
|
227
|
+
scrollTop: scrollOptions.current.scrollTop || 0
|
|
217
228
|
},
|
|
218
229
|
layoutRef
|
|
219
230
|
}, props));
|
|
220
231
|
}
|
|
221
232
|
}
|
|
222
|
-
function
|
|
223
|
-
const { binddragend,
|
|
224
|
-
bindtouchend && bindtouchend(e);
|
|
233
|
+
function onScrollEndDrag(e) {
|
|
234
|
+
const { binddragend, enhanced } = props;
|
|
225
235
|
if (enhanced) {
|
|
236
|
+
const { x: scrollLeft, y: scrollTop } = e.nativeEvent.contentOffset;
|
|
237
|
+
const { width: scrollWidth, height: scrollHeight } = e.nativeEvent.contentSize;
|
|
226
238
|
binddragend &&
|
|
227
239
|
binddragend(getCustomEvent('dragend', e, {
|
|
228
240
|
detail: {
|
|
229
|
-
scrollLeft:
|
|
230
|
-
scrollTop:
|
|
241
|
+
scrollLeft: scrollLeft,
|
|
242
|
+
scrollTop: scrollTop,
|
|
243
|
+
scrollHeight,
|
|
244
|
+
scrollWidth
|
|
231
245
|
},
|
|
232
246
|
layoutRef
|
|
233
247
|
}, props));
|
|
248
|
+
updateScrollOptions(e, { scrollLeft, scrollTop });
|
|
234
249
|
}
|
|
235
250
|
}
|
|
236
251
|
let scrollAdditionalProps = {
|
|
252
|
+
style: { ...innerStyle, ...layoutStyle },
|
|
237
253
|
pinchGestureEnabled: false,
|
|
238
|
-
horizontal: scrollX
|
|
254
|
+
horizontal: scrollX && !scrollY,
|
|
239
255
|
scrollEventThrottle: scrollEventThrottle,
|
|
240
256
|
scrollsToTop: enableBackToTop,
|
|
241
257
|
showsHorizontalScrollIndicator: scrollX && showScrollbar,
|
|
242
258
|
showsVerticalScrollIndicator: scrollY && showScrollbar,
|
|
243
|
-
scrollEnabled:
|
|
259
|
+
scrollEnabled: scrollX || scrollY,
|
|
244
260
|
ref: scrollViewRef,
|
|
245
261
|
onScroll: onScroll,
|
|
246
262
|
onContentSizeChange: onContentSizeChange,
|
|
247
263
|
bindtouchstart: onScrollTouchStart,
|
|
248
|
-
bindtouchend: onScrollTouchEnd,
|
|
249
264
|
bindtouchmove: onScrollTouchMove,
|
|
250
|
-
|
|
265
|
+
onScrollEndDrag,
|
|
266
|
+
onMomentumScrollEnd: onScrollEnd,
|
|
267
|
+
...layoutProps
|
|
251
268
|
};
|
|
252
269
|
if (enhanced) {
|
|
253
270
|
scrollAdditionalProps = {
|
|
254
271
|
...scrollAdditionalProps,
|
|
255
272
|
bounces,
|
|
256
|
-
pagingEnabled
|
|
273
|
+
pagingEnabled
|
|
257
274
|
};
|
|
258
275
|
}
|
|
259
276
|
const innerProps = useInnerProps(props, scrollAdditionalProps, [
|
|
260
|
-
'enable-offset',
|
|
261
277
|
'scroll-x',
|
|
262
278
|
'scroll-y',
|
|
263
279
|
'enable-back-to-top',
|
|
@@ -283,11 +299,18 @@ const _ScrollView = forwardRef((props = {}, ref) => {
|
|
|
283
299
|
'bindrefresherrefresh'
|
|
284
300
|
], { layoutRef });
|
|
285
301
|
const refreshColor = {
|
|
286
|
-
|
|
287
|
-
|
|
302
|
+
black: ['#000'],
|
|
303
|
+
white: ['#fff']
|
|
288
304
|
};
|
|
289
|
-
return (<ScrollView {...innerProps} refreshControl={refresherEnabled
|
|
290
|
-
|
|
305
|
+
return (<ScrollView {...innerProps} refreshControl={refresherEnabled
|
|
306
|
+
? (<RefreshControl progressBackgroundColor={refresherBackground} refreshing={refreshing} onRefresh={onRefresh} {...(refresherDefaultStyle && refresherDefaultStyle !== 'none' ? { colors: refreshColor[refresherDefaultStyle] } : {})}/>)
|
|
307
|
+
: undefined}>
|
|
308
|
+
{wrapChildren(props, {
|
|
309
|
+
hasVarDec,
|
|
310
|
+
varContext: varContextRef.current,
|
|
311
|
+
textStyle,
|
|
312
|
+
textProps
|
|
313
|
+
})}
|
|
291
314
|
</ScrollView>);
|
|
292
315
|
});
|
|
293
316
|
_ScrollView.displayName = 'mpx-scroll-view';
|