@mpxjs/webpack-plugin 2.9.56 → 2.9.58
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/platform/style/wx/index.js +29 -9
- package/lib/platform/template/wx/component-config/web-view.js +8 -0
- package/lib/react/index.js +0 -1
- package/lib/react/processStyles.js +14 -3
- package/lib/react/style-helper.js +6 -10
- package/lib/runtime/base.styl +27 -0
- package/lib/runtime/components/react/dist/event.config.js +27 -0
- package/lib/runtime/components/react/dist/getInnerListeners.js +230 -0
- package/lib/runtime/components/react/dist/mpx-button.jsx +270 -0
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +229 -0
- package/lib/runtime/components/react/dist/mpx-image/svg.jsx +6 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +203 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +294 -0
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +353 -0
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +57 -0
- package/lib/runtime/components/react/dist/mpx-swiper/type.js +1 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +25 -0
- package/lib/runtime/components/react/dist/mpx-text.jsx +67 -0
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +27 -0
- package/lib/runtime/components/react/dist/mpx-view.jsx +307 -0
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +115 -0
- package/lib/runtime/components/react/dist/types/getInnerListeners.js +1 -0
- package/lib/runtime/components/react/dist/useNodesRef.js +25 -0
- package/lib/runtime/components/react/dist/utils.js +80 -0
- package/lib/runtime/components/react/getInnerListeners.ts +1 -1
- package/lib/runtime/components/react/mpx-button.tsx +1 -2
- package/lib/runtime/components/react/mpx-image/svg.tsx +0 -1
- package/lib/runtime/components/react/mpx-web-view.tsx +171 -0
- package/lib/runtime/components/react/{getInnerListeners.type.ts → types/getInnerListeners.ts} +2 -2
- package/lib/runtime/components/react/types/global.d.ts +15 -0
- package/lib/runtime/components/react/utils.ts +1 -1
- package/lib/runtime/optionProcessor.js +27 -1
- package/lib/runtime/transRpxStyle.js +1 -1
- package/lib/style-compiler/plugins/rpx.js +2 -2
- package/lib/style-compiler/plugins/vw.js +2 -2
- package/lib/template-compiler/compiler.js +104 -42
- package/lib/web/processTemplate.js +1 -1
- package/package.json +8 -4
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ✔ value
|
|
3
|
+
* - type: Partially. Not support `safe-password`、`nickname`
|
|
4
|
+
* ✔ password
|
|
5
|
+
* ✔ placeholder
|
|
6
|
+
* - placeholder-style: Only support color.
|
|
7
|
+
* ✘ placeholder-class
|
|
8
|
+
* ✔ disabled
|
|
9
|
+
* ✔ maxlength
|
|
10
|
+
* ✘ cursor-spacing
|
|
11
|
+
* ✔ auto-focus
|
|
12
|
+
* ✔ focus
|
|
13
|
+
* ✔ confirm-type
|
|
14
|
+
* ✘ always-embed
|
|
15
|
+
* ✔ confirm-hold
|
|
16
|
+
* ✔ cursor
|
|
17
|
+
* ✔ cursor-color
|
|
18
|
+
* ✔ selection-start
|
|
19
|
+
* ✔ selection-end
|
|
20
|
+
* ✘ adjust-position
|
|
21
|
+
* ✘ hold-keyboard
|
|
22
|
+
* ✘ safe-password-cert-path
|
|
23
|
+
* ✘ safe-password-length
|
|
24
|
+
* ✘ safe-password-time-stamp
|
|
25
|
+
* ✘ safe-password-nonce
|
|
26
|
+
* ✘ safe-password-salt
|
|
27
|
+
* ✘ safe-password-custom-hash
|
|
28
|
+
* - bindinput: No `keyCode` info.
|
|
29
|
+
* - bindfocus: No `height` info.
|
|
30
|
+
* - bindblur: No `encryptedValue`、`encryptError` info.
|
|
31
|
+
* ✔ bindconfirm
|
|
32
|
+
* ✘ bindkeyboardheightchange
|
|
33
|
+
* ✘ bindnicknamereview
|
|
34
|
+
* ✔ bind:selectionchange
|
|
35
|
+
* ✘ bind:keyboardcompositionstart
|
|
36
|
+
* ✘ bind:keyboardcompositionupdate
|
|
37
|
+
* ✘ bind:keyboardcompositionend
|
|
38
|
+
* ✘ bind:onkeyboardheightchange
|
|
39
|
+
*/
|
|
40
|
+
import React, { forwardRef, useMemo, useRef, useState } from 'react';
|
|
41
|
+
import { Platform, TextInput } from 'react-native';
|
|
42
|
+
import { parseInlineStyle, useUpdateEffect } from './utils';
|
|
43
|
+
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
44
|
+
import useNodesRef from './useNodesRef';
|
|
45
|
+
const keyboardTypeMap = {
|
|
46
|
+
text: 'default',
|
|
47
|
+
number: 'numeric',
|
|
48
|
+
idcard: 'default',
|
|
49
|
+
digit: Platform.select({
|
|
50
|
+
ios: 'decimal-pad',
|
|
51
|
+
android: 'numeric',
|
|
52
|
+
}) || '',
|
|
53
|
+
};
|
|
54
|
+
const Input = forwardRef((props, ref) => {
|
|
55
|
+
const { style = [], type = 'text', value, password, 'placeholder-style': placeholderStyle, disabled, maxlength = 140, 'auto-focus': autoFocus, focus, 'confirm-type': confirmType = 'done', 'confirm-hold': confirmHold = false, cursor, 'cursor-color': cursorColor, 'selection-start': selectionStart = -1, 'selection-end': selectionEnd = -1, 'enable-offset': enableOffset, bindinput, bindfocus, bindblur, bindconfirm, bindselectionchange,
|
|
56
|
+
// private
|
|
57
|
+
multiline, 'auto-height': autoHeight, bindlinechange, } = props;
|
|
58
|
+
const { nodeRef } = useNodesRef(props, ref);
|
|
59
|
+
const keyboardType = keyboardTypeMap[type];
|
|
60
|
+
const defaultValue = type === 'number' && value ? value + '' : value;
|
|
61
|
+
const placeholderTextColor = parseInlineStyle(placeholderStyle)?.color;
|
|
62
|
+
const textAlignVertical = multiline ? 'top' : 'auto';
|
|
63
|
+
const layoutRef = useRef({});
|
|
64
|
+
const tmpValue = useRef();
|
|
65
|
+
const cursorIndex = useRef(0);
|
|
66
|
+
const lineCount = useRef(0);
|
|
67
|
+
const [inputValue, setInputValue] = useState();
|
|
68
|
+
const [contentHeight, setContentHeight] = useState(0);
|
|
69
|
+
const selection = useMemo(() => {
|
|
70
|
+
if (selectionStart >= 0 && selectionEnd >= 0) {
|
|
71
|
+
return { start: selectionStart, end: selectionEnd };
|
|
72
|
+
}
|
|
73
|
+
else if (typeof cursor === 'number') {
|
|
74
|
+
return { start: cursor, end: cursor };
|
|
75
|
+
}
|
|
76
|
+
}, [cursor, selectionStart, selectionEnd]);
|
|
77
|
+
const onTextInput = ({ nativeEvent }) => {
|
|
78
|
+
if (!bindinput && !bindblur)
|
|
79
|
+
return;
|
|
80
|
+
const { range: { start, end }, text, } = nativeEvent;
|
|
81
|
+
cursorIndex.current = start < end ? start : start + text.length;
|
|
82
|
+
};
|
|
83
|
+
const onChange = (evt) => {
|
|
84
|
+
tmpValue.current = evt.nativeEvent.text;
|
|
85
|
+
if (!bindinput)
|
|
86
|
+
return;
|
|
87
|
+
const result = bindinput(getCustomEvent('input', evt, {
|
|
88
|
+
detail: {
|
|
89
|
+
value: evt.nativeEvent.text,
|
|
90
|
+
cursor: cursorIndex.current,
|
|
91
|
+
},
|
|
92
|
+
layoutRef
|
|
93
|
+
}, props));
|
|
94
|
+
if (typeof result === 'string') {
|
|
95
|
+
tmpValue.current = result;
|
|
96
|
+
setInputValue(result);
|
|
97
|
+
}
|
|
98
|
+
else if (inputValue) {
|
|
99
|
+
setInputValue(undefined);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const onInputFocus = (evt) => {
|
|
103
|
+
bindfocus &&
|
|
104
|
+
bindfocus(getCustomEvent('focus', evt, {
|
|
105
|
+
detail: {
|
|
106
|
+
value: tmpValue.current || '',
|
|
107
|
+
},
|
|
108
|
+
layoutRef
|
|
109
|
+
}, props));
|
|
110
|
+
};
|
|
111
|
+
const onInputBlur = (evt) => {
|
|
112
|
+
bindblur &&
|
|
113
|
+
bindblur(getCustomEvent('blur', evt, {
|
|
114
|
+
detail: {
|
|
115
|
+
value: tmpValue.current || '',
|
|
116
|
+
cursor: cursorIndex.current,
|
|
117
|
+
},
|
|
118
|
+
layoutRef
|
|
119
|
+
}, props));
|
|
120
|
+
};
|
|
121
|
+
const onKeyPress = (evt) => {
|
|
122
|
+
bindconfirm &&
|
|
123
|
+
evt.nativeEvent.key === 'Enter' &&
|
|
124
|
+
bindconfirm(getCustomEvent('confirm', evt, {
|
|
125
|
+
detail: {
|
|
126
|
+
value: tmpValue.current || '',
|
|
127
|
+
},
|
|
128
|
+
layoutRef
|
|
129
|
+
}, props));
|
|
130
|
+
};
|
|
131
|
+
const onSubmitEditing = (evt) => {
|
|
132
|
+
bindconfirm &&
|
|
133
|
+
multiline &&
|
|
134
|
+
bindconfirm(getCustomEvent('confirm', evt, {
|
|
135
|
+
detail: {
|
|
136
|
+
value: tmpValue.current || '',
|
|
137
|
+
},
|
|
138
|
+
layoutRef
|
|
139
|
+
}, props));
|
|
140
|
+
};
|
|
141
|
+
const onContentSizeChange = (evt) => {
|
|
142
|
+
const { width, height } = evt.nativeEvent.contentSize;
|
|
143
|
+
if (width && height) {
|
|
144
|
+
if (!multiline || !autoHeight || height === contentHeight)
|
|
145
|
+
return;
|
|
146
|
+
lineCount.current += height > contentHeight ? 1 : -1;
|
|
147
|
+
const lineHeight = lineCount.current === 0 ? 0 : height / lineCount.current;
|
|
148
|
+
bindlinechange &&
|
|
149
|
+
bindlinechange(getCustomEvent('linechange', evt, {
|
|
150
|
+
detail: {
|
|
151
|
+
height,
|
|
152
|
+
lineHeight,
|
|
153
|
+
lineCount: lineCount.current,
|
|
154
|
+
},
|
|
155
|
+
layoutRef
|
|
156
|
+
}, props));
|
|
157
|
+
setContentHeight(height);
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
const onSelectionChange = (evt) => {
|
|
161
|
+
bindselectionchange &&
|
|
162
|
+
bindselectionchange(getCustomEvent('selectionchange', evt, {
|
|
163
|
+
detail: {
|
|
164
|
+
selectionStart: evt.nativeEvent.selection.start,
|
|
165
|
+
selectionEnd: evt.nativeEvent.selection.end,
|
|
166
|
+
},
|
|
167
|
+
layoutRef
|
|
168
|
+
}, props));
|
|
169
|
+
};
|
|
170
|
+
const onLayout = () => {
|
|
171
|
+
nodeRef.current?.measure((x, y, width, height, offsetLeft, offsetTop) => {
|
|
172
|
+
layoutRef.current = { x, y, width, height, offsetLeft, offsetTop };
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
useUpdateEffect(() => {
|
|
176
|
+
if (!nodeRef?.current) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
focus
|
|
180
|
+
? nodeRef.current?.focus()
|
|
181
|
+
: nodeRef.current?.blur();
|
|
182
|
+
}, [focus]);
|
|
183
|
+
const innerProps = useInnerProps(props, {
|
|
184
|
+
ref: nodeRef,
|
|
185
|
+
...(enableOffset ? { onLayout } : {}),
|
|
186
|
+
}, [
|
|
187
|
+
'enable-offset'
|
|
188
|
+
], {
|
|
189
|
+
layoutRef
|
|
190
|
+
});
|
|
191
|
+
return (<TextInput {...innerProps} keyboardType={keyboardType} secureTextEntry={!!password} defaultValue={defaultValue} value={inputValue} maxLength={maxlength === -1 ? undefined : maxlength} editable={!disabled} autoFocus={!!autoFocus || !!focus} returnKeyType={confirmType} selection={selection} selectionColor={cursorColor} blurOnSubmit={!multiline && !confirmHold} underlineColorAndroid="rgba(0,0,0,0)" textAlignVertical={textAlignVertical} placeholderTextColor={placeholderTextColor} multiline={!!multiline} onTextInput={onTextInput} onChange={onChange} onFocus={onInputFocus} onBlur={onInputBlur} onKeyPress={onKeyPress} onSubmitEditing={onSubmitEditing} onContentSizeChange={onContentSizeChange} onSelectionChange={onSelectionChange} style={[
|
|
192
|
+
{
|
|
193
|
+
padding: 0,
|
|
194
|
+
},
|
|
195
|
+
style,
|
|
196
|
+
multiline &&
|
|
197
|
+
autoHeight && {
|
|
198
|
+
height: Math.max(style?.minHeight || 35, contentHeight),
|
|
199
|
+
},
|
|
200
|
+
]}/>);
|
|
201
|
+
});
|
|
202
|
+
Input.displayName = 'mpx-input';
|
|
203
|
+
export default Input;
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ✔ scroll-x
|
|
3
|
+
* ✔ scroll-y
|
|
4
|
+
* ✔ upper-threshold
|
|
5
|
+
* ✔ lower-threshold
|
|
6
|
+
* ✔ scroll-top
|
|
7
|
+
* ✔ scroll-left
|
|
8
|
+
* ✘ scroll-into-view
|
|
9
|
+
* ✔ scroll-with-animation
|
|
10
|
+
* ✔ enable-back-to-top
|
|
11
|
+
* ✘ enable-passive
|
|
12
|
+
* ✔ refresher-enabled
|
|
13
|
+
* ✘ refresher-threshold
|
|
14
|
+
* ✔ refresher-default-style(仅 android 支持)
|
|
15
|
+
* ✔ refresher-background(仅 android 支持)
|
|
16
|
+
* ✔ refresher-triggered
|
|
17
|
+
* ✘ enable-flex(scroll-x,rn 默认支持)
|
|
18
|
+
* ✘ scroll-anchoring
|
|
19
|
+
* ✔ paging-enabled
|
|
20
|
+
* ✘ using-sticky
|
|
21
|
+
* ✔ show-scrollbar
|
|
22
|
+
* ✘ fast-deceleration
|
|
23
|
+
* ✔ binddragstart
|
|
24
|
+
* ✔ binddragging
|
|
25
|
+
* ✔ binddragend
|
|
26
|
+
* ✔ bindrefresherrefresh
|
|
27
|
+
* ✘ bindrefresherpulling
|
|
28
|
+
* ✘ bindrefresherrestore
|
|
29
|
+
* ✘ bindrefresherabort
|
|
30
|
+
* ✔ bindscrolltoupper
|
|
31
|
+
* ✔ bindscrolltolower
|
|
32
|
+
* ✔ bindscroll
|
|
33
|
+
*/
|
|
34
|
+
import { ScrollView, RefreshControl } from 'react-native';
|
|
35
|
+
import React, { useRef, useState, useEffect, forwardRef } from 'react';
|
|
36
|
+
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
37
|
+
import useNodesRef from './useNodesRef';
|
|
38
|
+
const _ScrollView = forwardRef((props = {}, ref) => {
|
|
39
|
+
const { children, enhanced = false, bounces = true, '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, 'enable-offset': enableOffset, 'show-scrollbar': showScrollbar = true } = props;
|
|
40
|
+
const [snapScrollTop, setSnapScrollTop] = useState(0);
|
|
41
|
+
const [snapScrollLeft, setSnapScrollLeft] = useState(0);
|
|
42
|
+
const [refreshing, setRefreshing] = useState(true);
|
|
43
|
+
const [scrollEnabled, setScrollEnabled] = useState(true);
|
|
44
|
+
const layoutRef = useRef({});
|
|
45
|
+
const scrollOptions = useRef({
|
|
46
|
+
contentLength: 0,
|
|
47
|
+
offset: 0,
|
|
48
|
+
scrollLeft: 0,
|
|
49
|
+
scrollTop: 0,
|
|
50
|
+
visibleLength: 0,
|
|
51
|
+
});
|
|
52
|
+
const scrollEventThrottle = 50;
|
|
53
|
+
const hasCallScrollToUpper = useRef(true);
|
|
54
|
+
const hasCallScrollToLower = useRef(false);
|
|
55
|
+
const initialTimeout = useRef(null);
|
|
56
|
+
const { nodeRef: scrollViewRef } = useNodesRef(props, ref, {
|
|
57
|
+
scrollOffset: scrollOptions,
|
|
58
|
+
node: {
|
|
59
|
+
scrollEnabled,
|
|
60
|
+
bounces,
|
|
61
|
+
showScrollbar,
|
|
62
|
+
pagingEnabled,
|
|
63
|
+
fastDeceleration: false,
|
|
64
|
+
decelerationDisabled: false,
|
|
65
|
+
scrollTo: scrollToOffset
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
if (snapScrollTop !== props['scroll-top'] ||
|
|
70
|
+
snapScrollLeft !== props['scroll-left']) {
|
|
71
|
+
setSnapScrollTop(props['scroll-top'] || 0);
|
|
72
|
+
setSnapScrollLeft(props['scroll-left'] || 0);
|
|
73
|
+
}
|
|
74
|
+
}, [props['scroll-top'], props['scroll-left']]);
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (refreshing !== props['refresher-triggered']) {
|
|
77
|
+
setRefreshing(!!props['refresher-triggered']);
|
|
78
|
+
}
|
|
79
|
+
}, [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
|
+
function selectLength(size) {
|
|
99
|
+
return !scrollX ? size.height : size.width;
|
|
100
|
+
}
|
|
101
|
+
function selectOffset(position) {
|
|
102
|
+
return !scrollX ? position.y : position.x;
|
|
103
|
+
}
|
|
104
|
+
function onStartReached(e) {
|
|
105
|
+
const { bindscrolltoupper } = props;
|
|
106
|
+
const { offset } = scrollOptions.current;
|
|
107
|
+
if (bindscrolltoupper && (offset <= upperThreshold)) {
|
|
108
|
+
if (!hasCallScrollToUpper.current) {
|
|
109
|
+
bindscrolltoupper(getCustomEvent('scrolltoupper', e, {
|
|
110
|
+
detail: {
|
|
111
|
+
direction: scrollX ? 'left' : 'top',
|
|
112
|
+
},
|
|
113
|
+
layoutRef
|
|
114
|
+
}, props));
|
|
115
|
+
hasCallScrollToUpper.current = true;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
hasCallScrollToUpper.current = false;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function onEndReached(e) {
|
|
123
|
+
const { bindscrolltolower } = props;
|
|
124
|
+
const { contentLength, visibleLength, offset } = scrollOptions.current;
|
|
125
|
+
const distanceFromEnd = contentLength - visibleLength - offset;
|
|
126
|
+
if (bindscrolltolower && (distanceFromEnd < lowerThreshold)) {
|
|
127
|
+
if (!hasCallScrollToLower.current) {
|
|
128
|
+
hasCallScrollToLower.current = true;
|
|
129
|
+
bindscrolltolower(getCustomEvent('scrolltolower', e, {
|
|
130
|
+
detail: {
|
|
131
|
+
direction: scrollX ? 'right' : 'botttom',
|
|
132
|
+
},
|
|
133
|
+
layoutRef
|
|
134
|
+
}, props));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
hasCallScrollToLower.current = false;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function onContentSizeChange(width, height) {
|
|
142
|
+
scrollOptions.current.contentLength = selectLength({ height, width });
|
|
143
|
+
}
|
|
144
|
+
function onLayout(e) {
|
|
145
|
+
scrollOptions.current.visibleLength = selectLength(e.nativeEvent.layout);
|
|
146
|
+
if (enableOffset) {
|
|
147
|
+
scrollViewRef.current?.measure((x, y, width, height, offsetLeft, offsetTop) => {
|
|
148
|
+
layoutRef.current = { x, y, width, height, offsetLeft, offsetTop };
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function onScroll(e) {
|
|
153
|
+
const { bindscroll } = props;
|
|
154
|
+
const { x: scrollLeft, y: scrollTop } = e.nativeEvent.contentOffset;
|
|
155
|
+
const { width: scrollWidth, height: scrollHeight } = e.nativeEvent.contentSize;
|
|
156
|
+
bindscroll &&
|
|
157
|
+
bindscroll(getCustomEvent('scroll', e, {
|
|
158
|
+
detail: {
|
|
159
|
+
scrollLeft,
|
|
160
|
+
scrollTop,
|
|
161
|
+
scrollHeight,
|
|
162
|
+
scrollWidth,
|
|
163
|
+
deltaX: scrollLeft - scrollOptions.current.scrollLeft,
|
|
164
|
+
deltaY: scrollTop - scrollOptions.current.scrollTop,
|
|
165
|
+
},
|
|
166
|
+
layoutRef
|
|
167
|
+
}, props));
|
|
168
|
+
const visibleLength = selectLength(e.nativeEvent.layoutMeasurement);
|
|
169
|
+
const contentLength = selectLength(e.nativeEvent.contentSize);
|
|
170
|
+
const offset = selectOffset(e.nativeEvent.contentOffset);
|
|
171
|
+
scrollOptions.current = {
|
|
172
|
+
...scrollOptions.current,
|
|
173
|
+
contentLength,
|
|
174
|
+
offset,
|
|
175
|
+
scrollLeft,
|
|
176
|
+
scrollTop,
|
|
177
|
+
visibleLength,
|
|
178
|
+
};
|
|
179
|
+
onStartReached(e);
|
|
180
|
+
onEndReached(e);
|
|
181
|
+
}
|
|
182
|
+
function scrollToOffset(x = 0, y = 0) {
|
|
183
|
+
if (scrollViewRef.current) {
|
|
184
|
+
scrollViewRef.current.scrollTo({ x, y, animated: !!scrollWithAnimation });
|
|
185
|
+
scrollOptions.current.scrollLeft = x;
|
|
186
|
+
scrollOptions.current.scrollTop = y;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function onRefresh() {
|
|
190
|
+
const { bindrefresherrefresh } = props;
|
|
191
|
+
bindrefresherrefresh &&
|
|
192
|
+
bindrefresherrefresh(getCustomEvent('refresherrefresh', {}, { layoutRef }, props));
|
|
193
|
+
}
|
|
194
|
+
function onScrollTouchStart(e) {
|
|
195
|
+
const { binddragstart, bindtouchstart, enhanced } = props;
|
|
196
|
+
bindtouchstart && bindtouchstart(e);
|
|
197
|
+
if (enhanced) {
|
|
198
|
+
binddragstart &&
|
|
199
|
+
binddragstart(getCustomEvent('dragstart', e, {
|
|
200
|
+
detail: {
|
|
201
|
+
scrollLeft: scrollOptions.current.scrollLeft || 0,
|
|
202
|
+
scrollTop: scrollOptions.current.scrollTop || 0,
|
|
203
|
+
},
|
|
204
|
+
layoutRef
|
|
205
|
+
}, props));
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
function onScrollTouchMove(e) {
|
|
209
|
+
const { binddragging, bindtouchmove, enhanced } = props;
|
|
210
|
+
bindtouchmove && bindtouchmove(e);
|
|
211
|
+
if (enhanced) {
|
|
212
|
+
binddragging &&
|
|
213
|
+
binddragging(getCustomEvent('dragging', e, {
|
|
214
|
+
detail: {
|
|
215
|
+
scrollLeft: scrollOptions.current.scrollLeft || 0,
|
|
216
|
+
scrollTop: scrollOptions.current.scrollTop || 0,
|
|
217
|
+
},
|
|
218
|
+
layoutRef
|
|
219
|
+
}, props));
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
function onScrollTouchEnd(e) {
|
|
223
|
+
const { binddragend, bindtouchend, enhanced } = props;
|
|
224
|
+
bindtouchend && bindtouchend(e);
|
|
225
|
+
if (enhanced) {
|
|
226
|
+
binddragend &&
|
|
227
|
+
binddragend(getCustomEvent('dragend', e, {
|
|
228
|
+
detail: {
|
|
229
|
+
scrollLeft: scrollOptions.current.scrollLeft || 0,
|
|
230
|
+
scrollTop: scrollOptions.current.scrollTop || 0,
|
|
231
|
+
},
|
|
232
|
+
layoutRef
|
|
233
|
+
}, props));
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
let scrollAdditionalProps = {
|
|
237
|
+
pinchGestureEnabled: false,
|
|
238
|
+
horizontal: scrollX || !scrollY,
|
|
239
|
+
scrollEventThrottle: scrollEventThrottle,
|
|
240
|
+
scrollsToTop: enableBackToTop,
|
|
241
|
+
showsHorizontalScrollIndicator: scrollX && showScrollbar,
|
|
242
|
+
showsVerticalScrollIndicator: scrollY && showScrollbar,
|
|
243
|
+
scrollEnabled: scrollEnabled,
|
|
244
|
+
ref: scrollViewRef,
|
|
245
|
+
onScroll: onScroll,
|
|
246
|
+
onContentSizeChange: onContentSizeChange,
|
|
247
|
+
bindtouchstart: onScrollTouchStart,
|
|
248
|
+
bindtouchend: onScrollTouchEnd,
|
|
249
|
+
bindtouchmove: onScrollTouchMove,
|
|
250
|
+
onLayout
|
|
251
|
+
};
|
|
252
|
+
if (enhanced) {
|
|
253
|
+
scrollAdditionalProps = {
|
|
254
|
+
...scrollAdditionalProps,
|
|
255
|
+
bounces,
|
|
256
|
+
pagingEnabled,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
const innerProps = useInnerProps(props, scrollAdditionalProps, [
|
|
260
|
+
'enable-offset',
|
|
261
|
+
'scroll-x',
|
|
262
|
+
'scroll-y',
|
|
263
|
+
'enable-back-to-top',
|
|
264
|
+
'paging-enabled',
|
|
265
|
+
'show-scrollbar',
|
|
266
|
+
'upper-threshold',
|
|
267
|
+
'lower-threshold',
|
|
268
|
+
'scroll-top',
|
|
269
|
+
'scroll-left',
|
|
270
|
+
'scroll-with-animation',
|
|
271
|
+
'refresher-triggered',
|
|
272
|
+
'refresher-enabled',
|
|
273
|
+
'refresher-default-style',
|
|
274
|
+
'refresher-background',
|
|
275
|
+
'children',
|
|
276
|
+
'enhanced',
|
|
277
|
+
'binddragstart',
|
|
278
|
+
'binddragging',
|
|
279
|
+
'binddragend',
|
|
280
|
+
'bindscroll',
|
|
281
|
+
'bindscrolltoupper',
|
|
282
|
+
'bindscrolltolower',
|
|
283
|
+
'bindrefresherrefresh'
|
|
284
|
+
], { layoutRef });
|
|
285
|
+
const refreshColor = {
|
|
286
|
+
'black': ['#000'],
|
|
287
|
+
'white': ['#fff']
|
|
288
|
+
};
|
|
289
|
+
return (<ScrollView {...innerProps} refreshControl={refresherEnabled ? (<RefreshControl progressBackgroundColor={refresherBackground} refreshing={refreshing} onRefresh={onRefresh} {...(refresherDefaultStyle && refresherDefaultStyle !== 'none' ? { colors: refreshColor[refresherDefaultStyle] } : {})}/>) : undefined}>
|
|
290
|
+
{children}
|
|
291
|
+
</ScrollView>);
|
|
292
|
+
});
|
|
293
|
+
_ScrollView.displayName = 'mpx-scroll-view';
|
|
294
|
+
export default _ScrollView;
|