@mpxjs/webpack-plugin 2.9.69 → 2.9.70
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/parser.js +1 -1
- package/lib/platform/json/wx/index.js +21 -8
- package/lib/platform/style/wx/index.js +51 -54
- package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
- package/lib/platform/template/wx/component-config/index.js +1 -1
- package/lib/platform/template/wx/component-config/input.js +1 -1
- package/lib/platform/template/wx/component-config/rich-text.js +8 -0
- package/lib/platform/template/wx/component-config/swiper.js +1 -1
- package/lib/platform/template/wx/component-config/textarea.js +1 -1
- package/lib/platform/template/wx/component-config/unsupported.js +1 -1
- package/lib/react/processTemplate.js +3 -0
- package/lib/runtime/components/react/context.ts +4 -0
- package/lib/runtime/components/react/dist/context.js +1 -0
- package/lib/runtime/components/react/dist/event.config.js +24 -24
- package/lib/runtime/components/react/dist/getInnerListeners.js +183 -166
- package/lib/runtime/components/react/dist/mpx-button.jsx +35 -42
- package/lib/runtime/components/react/dist/mpx-canvas/html.js +2 -4
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +35 -13
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
- package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
- package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
- package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
- package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +13 -13
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
- package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +3 -1
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +5 -3
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
- package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
- package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +63 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +47 -41
- package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +4 -2
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +4 -2
- package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
- package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
- package/lib/runtime/components/react/dist/mpx-view.jsx +34 -46
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +105 -42
- package/lib/runtime/components/react/dist/useAnimationHooks.js +35 -10
- package/lib/runtime/components/react/dist/utils.jsx +107 -82
- package/lib/runtime/components/react/event.config.ts +25 -26
- package/lib/runtime/components/react/getInnerListeners.ts +238 -188
- package/lib/runtime/components/react/mpx-button.tsx +64 -50
- package/lib/runtime/components/react/mpx-canvas/html.ts +2 -4
- package/lib/runtime/components/react/mpx-canvas/index.tsx +46 -48
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +28 -25
- package/lib/runtime/components/react/mpx-checkbox.tsx +48 -49
- package/lib/runtime/components/react/mpx-form.tsx +25 -28
- package/lib/runtime/components/react/mpx-icon.tsx +12 -17
- package/lib/runtime/components/react/mpx-image.tsx +436 -0
- package/lib/runtime/components/react/mpx-input.tsx +77 -57
- package/lib/runtime/components/react/mpx-label.tsx +26 -27
- package/lib/runtime/components/react/mpx-movable-area.tsx +18 -23
- package/lib/runtime/components/react/mpx-movable-view.tsx +21 -25
- package/lib/runtime/components/react/mpx-navigator.tsx +2 -8
- package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
- package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
- package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +4 -1
- package/lib/runtime/components/react/mpx-picker-view.tsx +7 -1
- package/lib/runtime/components/react/mpx-radio-group.tsx +24 -27
- package/lib/runtime/components/react/mpx-radio.tsx +45 -54
- package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
- package/lib/runtime/components/react/mpx-rich-text/index.tsx +121 -0
- package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
- package/lib/runtime/components/react/mpx-scroll-view.tsx +72 -71
- package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +4 -2
- package/lib/runtime/components/react/mpx-swiper-item.tsx +3 -2
- package/lib/runtime/components/react/mpx-switch.tsx +29 -23
- package/lib/runtime/components/react/mpx-text.tsx +14 -18
- package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
- package/lib/runtime/components/react/mpx-view.tsx +55 -65
- package/lib/runtime/components/react/mpx-web-view.tsx +108 -63
- package/lib/runtime/components/react/types/global.d.ts +3 -17
- package/lib/runtime/components/react/useAnimationHooks.ts +36 -12
- package/lib/runtime/components/react/utils.tsx +113 -82
- package/lib/runtime/components/web/getInnerListeners.js +6 -6
- package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
- package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
- package/lib/runtime/components/web/mpx-picker.vue +382 -385
- package/lib/runtime/components/web/mpx-web-view.vue +175 -161
- package/lib/runtime/optionProcessor.js +7 -38
- package/lib/runtime/utils.js +2 -0
- package/lib/style-compiler/plugins/scope-id.js +30 -2
- package/lib/template-compiler/bind-this.js +7 -2
- package/lib/template-compiler/compiler.js +77 -46
- package/lib/template-compiler/gen-node-react.js +2 -2
- package/lib/utils/pre-process-json.js +9 -5
- package/package.json +5 -4
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
- package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
- package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
- package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
- package/lib/runtime/components/web/event.js +0 -105
|
@@ -1,345 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ✔ src
|
|
3
|
-
* - mode: Partially, Only SVG format do not support
|
|
4
|
-
* ✘ show-menu-by-longpress
|
|
5
|
-
* ✔ binderror
|
|
6
|
-
* ✔ bindload
|
|
7
|
-
* ✘ fade-in
|
|
8
|
-
* ✔ webp
|
|
9
|
-
* ✘ lazy-load
|
|
10
|
-
* ✔ bindtap
|
|
11
|
-
* ✔ DEFAULT_SIZE
|
|
12
|
-
*/
|
|
13
|
-
import { useEffect, useMemo, useState, useRef, forwardRef } from 'react'
|
|
14
|
-
|
|
15
|
-
import {
|
|
16
|
-
Image as RNImage,
|
|
17
|
-
View,
|
|
18
|
-
ImageStyle,
|
|
19
|
-
ImageSourcePropType,
|
|
20
|
-
ImageResizeMode,
|
|
21
|
-
StyleSheet,
|
|
22
|
-
NativeSyntheticEvent,
|
|
23
|
-
ImageErrorEventData,
|
|
24
|
-
LayoutChangeEvent,
|
|
25
|
-
DimensionValue,
|
|
26
|
-
ImageLoadEventData
|
|
27
|
-
} from 'react-native'
|
|
28
|
-
import useInnerProps, { getCustomEvent } from '../getInnerListeners'
|
|
29
|
-
import useNodesRef, { HandlerRef } from '../useNodesRef'
|
|
30
|
-
import { useLayout, useTransformStyle } from '../utils'
|
|
31
|
-
|
|
32
|
-
export type Mode =
|
|
33
|
-
| 'scaleToFill'
|
|
34
|
-
| 'aspectFit'
|
|
35
|
-
| 'aspectFill'
|
|
36
|
-
| 'widthFix'
|
|
37
|
-
| 'heightFix'
|
|
38
|
-
| 'top'
|
|
39
|
-
| 'bottom'
|
|
40
|
-
| 'center'
|
|
41
|
-
| 'left'
|
|
42
|
-
| 'right'
|
|
43
|
-
| 'top left'
|
|
44
|
-
| 'top right'
|
|
45
|
-
| 'bottom left'
|
|
46
|
-
| 'bottom right'
|
|
47
|
-
|
|
48
|
-
export type SvgNumberProp = string | number | undefined
|
|
49
|
-
|
|
50
|
-
export interface ImageProps {
|
|
51
|
-
src?: string
|
|
52
|
-
mode?: Mode
|
|
53
|
-
svg?: boolean
|
|
54
|
-
style?: ImageStyle & Record<string, any>
|
|
55
|
-
'enable-offset'?: boolean;
|
|
56
|
-
'enable-var'?: boolean
|
|
57
|
-
'external-var-context'?: Record<string, any>
|
|
58
|
-
'parent-font-size'?: number
|
|
59
|
-
'parent-width'?: number
|
|
60
|
-
'parent-height'?: number
|
|
61
|
-
bindload?: (evt: NativeSyntheticEvent<ImageLoadEventData> | unknown) => void
|
|
62
|
-
binderror?: (evt: NativeSyntheticEvent<ImageErrorEventData> | unknown) => void
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const DEFAULT_IMAGE_WIDTH = 320
|
|
66
|
-
const DEFAULT_IMAGE_HEIGHT = 240
|
|
67
|
-
// const REMOTE_SVG_REGEXP = /https?:\/\/.*\.(?:svg)/i
|
|
68
|
-
|
|
69
|
-
// const styls = StyleSheet.create({
|
|
70
|
-
// suspense: {
|
|
71
|
-
// display: 'flex',
|
|
72
|
-
// justifyContent: 'center',
|
|
73
|
-
// alignItems: 'center',
|
|
74
|
-
// width: '100%',
|
|
75
|
-
// height: '100%',
|
|
76
|
-
// },
|
|
77
|
-
// })
|
|
78
|
-
|
|
79
|
-
const cropMode: Mode[] = [
|
|
80
|
-
'top',
|
|
81
|
-
'bottom',
|
|
82
|
-
'center',
|
|
83
|
-
'right',
|
|
84
|
-
'left',
|
|
85
|
-
'top left',
|
|
86
|
-
'top right',
|
|
87
|
-
'bottom left',
|
|
88
|
-
'bottom right'
|
|
89
|
-
]
|
|
90
|
-
|
|
91
|
-
const ModeMap = new Map<Mode, ImageResizeMode | undefined>([
|
|
92
|
-
['scaleToFill', 'stretch'],
|
|
93
|
-
['aspectFit', 'contain'],
|
|
94
|
-
['aspectFill', 'cover'],
|
|
95
|
-
['widthFix', 'stretch'],
|
|
96
|
-
['heightFix', 'stretch'],
|
|
97
|
-
...cropMode.map<[Mode, ImageResizeMode]>(mode => [mode, 'stretch'])
|
|
98
|
-
])
|
|
99
|
-
|
|
100
|
-
const isNumber = (value: DimensionValue) => typeof value === 'number'
|
|
101
|
-
|
|
102
|
-
const relativeCenteredSize = (viewSize: number, imageSize: number) => (viewSize - imageSize) / 2
|
|
103
|
-
|
|
104
|
-
// const Svg = lazy(() => import('./svg'))
|
|
105
|
-
|
|
106
|
-
// const Fallback = (
|
|
107
|
-
// <View style={styls.suspense}>
|
|
108
|
-
// <Text>loading ...</Text>
|
|
109
|
-
// </View>
|
|
110
|
-
// )
|
|
111
|
-
|
|
112
|
-
const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, ref): JSX.Element => {
|
|
113
|
-
const {
|
|
114
|
-
src = '',
|
|
115
|
-
mode = 'scaleToFill',
|
|
116
|
-
// svg = false,
|
|
117
|
-
style = {},
|
|
118
|
-
'enable-var': enableVar,
|
|
119
|
-
'external-var-context': externalVarContext,
|
|
120
|
-
'parent-font-size': parentFontSize,
|
|
121
|
-
'parent-width': parentWidth,
|
|
122
|
-
'parent-height': parentHeight,
|
|
123
|
-
bindload,
|
|
124
|
-
binderror
|
|
125
|
-
} = props
|
|
126
|
-
|
|
127
|
-
const defaultStyle = {
|
|
128
|
-
width: DEFAULT_IMAGE_WIDTH,
|
|
129
|
-
height: DEFAULT_IMAGE_HEIGHT
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const styleObj = {
|
|
133
|
-
...defaultStyle,
|
|
134
|
-
...style,
|
|
135
|
-
overflow: 'hidden'
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const nodeRef = useRef(null)
|
|
139
|
-
useNodesRef(props, ref, nodeRef, {
|
|
140
|
-
defaultStyle
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
const onLayout = ({ nativeEvent: { layout: { width, height } } }: LayoutChangeEvent) => {
|
|
144
|
-
setViewWidth(width)
|
|
145
|
-
setViewHeight(height)
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
const { normalStyle, hasSelfPercent, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
|
|
149
|
-
|
|
150
|
-
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef, onLayout })
|
|
151
|
-
|
|
152
|
-
const { width, height } = normalStyle
|
|
153
|
-
|
|
154
|
-
const preSrc = useRef<string | undefined>()
|
|
155
|
-
|
|
156
|
-
const resizeMode: ImageResizeMode = ModeMap.get(mode) || 'stretch'
|
|
157
|
-
const isWidthFixMode = mode === 'widthFix'
|
|
158
|
-
const isHeightFixMode = mode === 'heightFix'
|
|
159
|
-
const isCropMode = cropMode.includes(mode)
|
|
160
|
-
|
|
161
|
-
const source: ImageSourcePropType = typeof src === 'string' ? { uri: src } : src
|
|
162
|
-
|
|
163
|
-
const [viewWidth, setViewWidth] = useState(isNumber(width) ? width : 0)
|
|
164
|
-
const [viewHeight, setViewHeight] = useState(isNumber(height) ? height : 0)
|
|
165
|
-
const [imageWidth, setImageWidth] = useState(0)
|
|
166
|
-
const [imageHeight, setImageHeight] = useState(0)
|
|
167
|
-
const [ratio, setRatio] = useState(0)
|
|
168
|
-
const [loaded, setLoaded] = useState(false)
|
|
169
|
-
|
|
170
|
-
const fixedHeight = useMemo(() => {
|
|
171
|
-
const fixed = viewWidth * ratio
|
|
172
|
-
return !fixed ? viewHeight : fixed
|
|
173
|
-
}, [ratio, viewWidth, viewHeight])
|
|
174
|
-
|
|
175
|
-
const fixedWidth = useMemo(() => {
|
|
176
|
-
if (!ratio) return viewWidth
|
|
177
|
-
const fixed = viewHeight / ratio
|
|
178
|
-
return !fixed ? viewWidth : fixed
|
|
179
|
-
}, [ratio, viewWidth, viewHeight])
|
|
180
|
-
|
|
181
|
-
const cropModeStyle: ImageStyle = useMemo(() => {
|
|
182
|
-
switch (mode) {
|
|
183
|
-
case 'top':
|
|
184
|
-
return { top: 0, left: relativeCenteredSize(viewWidth, imageWidth) }
|
|
185
|
-
case 'bottom':
|
|
186
|
-
return { top: 'auto', bottom: 0, left: relativeCenteredSize(viewWidth, imageWidth) }
|
|
187
|
-
case 'center':
|
|
188
|
-
return { top: relativeCenteredSize(viewHeight, imageHeight), left: relativeCenteredSize(viewWidth, imageWidth) }
|
|
189
|
-
case 'left':
|
|
190
|
-
return { top: relativeCenteredSize(viewHeight, imageHeight), left: 0 }
|
|
191
|
-
case 'right':
|
|
192
|
-
return { top: relativeCenteredSize(viewHeight, imageHeight), left: 'auto', right: 0 }
|
|
193
|
-
case 'top left':
|
|
194
|
-
return { top: 0, left: 0 }
|
|
195
|
-
case 'top right':
|
|
196
|
-
return { top: 0, left: 'auto', right: 0 }
|
|
197
|
-
case 'bottom left':
|
|
198
|
-
return { top: 'auto', bottom: 0, left: 0 }
|
|
199
|
-
case 'bottom right':
|
|
200
|
-
return { top: 'auto', bottom: 0, left: 'auto', right: 0 }
|
|
201
|
-
default:
|
|
202
|
-
return {}
|
|
203
|
-
}
|
|
204
|
-
}, [mode, viewWidth, viewHeight, imageWidth, imageHeight])
|
|
205
|
-
|
|
206
|
-
const onImageLoad = (evt: NativeSyntheticEvent<ImageLoadEventData>) => {
|
|
207
|
-
if (!bindload) return
|
|
208
|
-
if (typeof src === 'string') {
|
|
209
|
-
evt.persist()
|
|
210
|
-
RNImage.getSize(src, (width: number, height: number) => {
|
|
211
|
-
bindload(
|
|
212
|
-
getCustomEvent(
|
|
213
|
-
'load',
|
|
214
|
-
evt,
|
|
215
|
-
{
|
|
216
|
-
detail: { width, height },
|
|
217
|
-
layoutRef
|
|
218
|
-
},
|
|
219
|
-
props
|
|
220
|
-
)
|
|
221
|
-
)
|
|
222
|
-
})
|
|
223
|
-
} else {
|
|
224
|
-
const { width = 0, height = 0 } = RNImage.resolveAssetSource(src) || {}
|
|
225
|
-
bindload(
|
|
226
|
-
getCustomEvent(
|
|
227
|
-
'load',
|
|
228
|
-
evt,
|
|
229
|
-
{
|
|
230
|
-
detail: { width, height },
|
|
231
|
-
layoutRef
|
|
232
|
-
},
|
|
233
|
-
props
|
|
234
|
-
)
|
|
235
|
-
)
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
const onImageError = (evt: NativeSyntheticEvent<ImageErrorEventData>) => {
|
|
240
|
-
binderror &&
|
|
241
|
-
binderror(
|
|
242
|
-
getCustomEvent(
|
|
243
|
-
'error',
|
|
244
|
-
evt,
|
|
245
|
-
{
|
|
246
|
-
detail: { errMsg: evt.nativeEvent.error },
|
|
247
|
-
layoutRef
|
|
248
|
-
},
|
|
249
|
-
props
|
|
250
|
-
)
|
|
251
|
-
)
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
useEffect(() => {
|
|
255
|
-
if (!isWidthFixMode && !isHeightFixMode && !isCropMode) {
|
|
256
|
-
setLoaded(true)
|
|
257
|
-
return
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
const changed = preSrc.current !== src
|
|
261
|
-
preSrc.current = src
|
|
262
|
-
changed && setLoaded(false)
|
|
263
|
-
|
|
264
|
-
if (typeof src === 'string') {
|
|
265
|
-
RNImage.getSize(src, (width: number, height: number) => {
|
|
266
|
-
if (isWidthFixMode || isHeightFixMode) {
|
|
267
|
-
setRatio(width === 0 ? 0 : height / width)
|
|
268
|
-
}
|
|
269
|
-
if (isCropMode) {
|
|
270
|
-
setImageWidth(width)
|
|
271
|
-
setImageHeight(height)
|
|
272
|
-
}
|
|
273
|
-
changed && setLoaded(true)
|
|
274
|
-
})
|
|
275
|
-
} else {
|
|
276
|
-
const { width = 0, height = 0 } = RNImage.resolveAssetSource(src) || {}
|
|
277
|
-
if (isWidthFixMode || isHeightFixMode) {
|
|
278
|
-
setRatio(width === 0 ? 0 : height / width)
|
|
279
|
-
}
|
|
280
|
-
if (isCropMode) {
|
|
281
|
-
setImageWidth(width)
|
|
282
|
-
setImageHeight(height)
|
|
283
|
-
}
|
|
284
|
-
changed && setLoaded(true)
|
|
285
|
-
}
|
|
286
|
-
}, [isWidthFixMode, isHeightFixMode, isCropMode, src])
|
|
287
|
-
|
|
288
|
-
const innerProps = useInnerProps(props, {
|
|
289
|
-
ref: nodeRef,
|
|
290
|
-
style: {
|
|
291
|
-
...normalStyle,
|
|
292
|
-
...layoutStyle,
|
|
293
|
-
...(isHeightFixMode && { width: fixedWidth }),
|
|
294
|
-
...(isWidthFixMode && { height: fixedHeight })
|
|
295
|
-
},
|
|
296
|
-
...layoutProps
|
|
297
|
-
},
|
|
298
|
-
[],
|
|
299
|
-
{
|
|
300
|
-
layoutRef
|
|
301
|
-
})
|
|
302
|
-
|
|
303
|
-
// if (typeof src === 'string' && REMOTE_SVG_REGEXP.test(src)) {
|
|
304
|
-
// return (
|
|
305
|
-
// <Suspense fallback={Fallback} {...innerProps}>
|
|
306
|
-
// <View {...innerProps}>
|
|
307
|
-
// <Svg src={src} style={style} width={width as SvgNumberProp} height={height as SvgNumberProp} />
|
|
308
|
-
// </View>
|
|
309
|
-
// </Suspense>
|
|
310
|
-
// )
|
|
311
|
-
// }
|
|
312
|
-
|
|
313
|
-
// if (svg) {
|
|
314
|
-
// return (
|
|
315
|
-
// <Suspense fallback={Fallback}>
|
|
316
|
-
// <View {...innerProps}>
|
|
317
|
-
// <Svg local src={src} style={style} width={width as SvgNumberProp} height={height as SvgNumberProp} />
|
|
318
|
-
// </View>
|
|
319
|
-
// </Suspense>
|
|
320
|
-
// )
|
|
321
|
-
// }
|
|
322
|
-
|
|
323
|
-
return (
|
|
324
|
-
<View {...innerProps}>
|
|
325
|
-
{
|
|
326
|
-
loaded && <RNImage
|
|
327
|
-
source={source}
|
|
328
|
-
resizeMode={resizeMode}
|
|
329
|
-
onLoad={onImageLoad}
|
|
330
|
-
onError={onImageError}
|
|
331
|
-
style={{
|
|
332
|
-
...StyleSheet.absoluteFillObject,
|
|
333
|
-
width: isCropMode ? imageWidth : '100%',
|
|
334
|
-
height: isCropMode ? imageHeight : '100%',
|
|
335
|
-
...(isCropMode && cropModeStyle)
|
|
336
|
-
}}
|
|
337
|
-
/>
|
|
338
|
-
}
|
|
339
|
-
</View>
|
|
340
|
-
)
|
|
341
|
-
})
|
|
342
|
-
|
|
343
|
-
Image.displayName = 'MpxImage'
|
|
344
|
-
|
|
345
|
-
export default Image
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { JSX } from 'react'
|
|
2
|
-
import type { ImageSourcePropType, ImageStyle, StyleProp } from 'react-native'
|
|
3
|
-
import { SvgCssUri, WithLocalSvg } from 'react-native-svg/css'
|
|
4
|
-
interface SvgProps {
|
|
5
|
-
local?: boolean
|
|
6
|
-
src: string | ImageSourcePropType
|
|
7
|
-
style?: StyleProp<ImageStyle>
|
|
8
|
-
width?: string | number
|
|
9
|
-
height?: string | number
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const Svg = ({ local = false, src, style, width, height }: SvgProps): JSX.Element => {
|
|
13
|
-
return local
|
|
14
|
-
? (
|
|
15
|
-
<WithLocalSvg style={style} asset={src as ImageSourcePropType} width={width} height={height} />
|
|
16
|
-
)
|
|
17
|
-
: (
|
|
18
|
-
<SvgCssUri style={style} uri={src as string} width={width} height={height} />
|
|
19
|
-
)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export default Svg
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { extendEvent } from './getInnerListeners'
|
|
2
|
-
import { isBrowser } from '../../env'
|
|
3
|
-
|
|
4
|
-
function MpxEvent (layer) {
|
|
5
|
-
this.targetElement = null
|
|
6
|
-
|
|
7
|
-
this.touches = []
|
|
8
|
-
|
|
9
|
-
this.touchStartX = 0
|
|
10
|
-
|
|
11
|
-
this.touchStartY = 0
|
|
12
|
-
|
|
13
|
-
this.startTimer = null
|
|
14
|
-
|
|
15
|
-
this.needTap = true
|
|
16
|
-
|
|
17
|
-
this.isTouchDevice = document && ('ontouchstart' in document.documentElement)
|
|
18
|
-
|
|
19
|
-
this.onTouchStart = (event) => {
|
|
20
|
-
if (event.targetTouches?.length > 1) {
|
|
21
|
-
return true
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
this.touches = event.targetTouches
|
|
25
|
-
this.targetElement = event.target
|
|
26
|
-
this.needTap = true
|
|
27
|
-
this.startTimer = null
|
|
28
|
-
this.touchStartX = this.touches[0].pageX
|
|
29
|
-
this.touchStartY = this.touches[0].pageY
|
|
30
|
-
this.startTimer = setTimeout(() => {
|
|
31
|
-
this.needTap = false
|
|
32
|
-
this.sendEvent(this.targetElement, 'longpress', event)
|
|
33
|
-
this.sendEvent(this.targetElement, 'longtap', event)
|
|
34
|
-
}, 350)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
this.onTouchMove = (event) => {
|
|
38
|
-
const touch = event.changedTouches[0]
|
|
39
|
-
if (Math.abs(touch.pageX - this.touchStartX) > 1 || Math.abs(touch.pageY - this.touchStartY) > 1) {
|
|
40
|
-
this.needTap = false
|
|
41
|
-
this.startTimer && clearTimeout(this.startTimer)
|
|
42
|
-
this.startTimer = null
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
this.onTouchEnd = (event) => {
|
|
47
|
-
if (event.targetTouches?.length > 1) {
|
|
48
|
-
return true
|
|
49
|
-
}
|
|
50
|
-
this.startTimer && clearTimeout(this.startTimer)
|
|
51
|
-
this.startTimer = null
|
|
52
|
-
if (this.needTap) {
|
|
53
|
-
this.sendEvent(this.targetElement, 'tap', event)
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
this.onClick = (event) => {
|
|
58
|
-
this.targetElement = event.target
|
|
59
|
-
this.sendEvent(this.targetElement, 'tap', event)
|
|
60
|
-
}
|
|
61
|
-
this.sendEvent = (targetElement, type, event) => {
|
|
62
|
-
const touchEvent = new CustomEvent(type, {
|
|
63
|
-
bubbles: true,
|
|
64
|
-
cancelable: true
|
|
65
|
-
})
|
|
66
|
-
const changedTouches = event.changedTouches || []
|
|
67
|
-
extendEvent(touchEvent, {
|
|
68
|
-
timeStamp: event.timeStamp,
|
|
69
|
-
changedTouches,
|
|
70
|
-
touches: changedTouches,
|
|
71
|
-
detail: {
|
|
72
|
-
// pc端点击事件可能没有changedTouches,所以直接从 event中取
|
|
73
|
-
x: changedTouches[0]?.pageX || event.pageX || 0,
|
|
74
|
-
y: changedTouches[0]?.pageY || event.pageY || 0
|
|
75
|
-
}
|
|
76
|
-
})
|
|
77
|
-
targetElement && targetElement.dispatchEvent(touchEvent)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
this.addListener = () => {
|
|
81
|
-
if (this.isTouchDevice) {
|
|
82
|
-
layer.addEventListener('touchstart', this.onTouchStart, true)
|
|
83
|
-
layer.addEventListener('touchmove', this.onTouchMove, true)
|
|
84
|
-
layer.addEventListener('touchend', this.onTouchEnd, true)
|
|
85
|
-
} else {
|
|
86
|
-
layer.addEventListener('click', this.onClick, true)
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
this.addListener()
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function createEvent () {
|
|
93
|
-
if (isBrowser && !global.__mpxCreatedEvent) {
|
|
94
|
-
global.__mpxCreatedEvent = true
|
|
95
|
-
if (document.readyState === 'complete' || document.readyState === 'interactive') {
|
|
96
|
-
// eslint-disable-next-line no-new
|
|
97
|
-
new MpxEvent(document.body)
|
|
98
|
-
} else {
|
|
99
|
-
document.addEventListener('DOMContentLoaded', function () {
|
|
100
|
-
// eslint-disable-next-line no-new
|
|
101
|
-
new MpxEvent(document.body)
|
|
102
|
-
}, false)
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|