@mpxjs/webpack-plugin 2.9.67 → 2.9.69
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 +13 -8
- package/lib/platform/template/wx/component-config/canvas.js +8 -0
- package/lib/platform/template/wx/component-config/unsupported.js +1 -1
- package/lib/react/processStyles.js +14 -4
- package/lib/resolver/AddModePlugin.js +8 -8
- package/lib/runtime/components/react/context.ts +2 -0
- package/lib/runtime/components/react/dist/context.js +1 -0
- package/lib/runtime/components/react/dist/getInnerListeners.js +3 -12
- package/lib/runtime/components/react/dist/mpx-button.jsx +43 -8
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
- package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +214 -0
- package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +143 -84
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +69 -113
- package/lib/runtime/components/react/dist/mpx-view.jsx +45 -26
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +19 -5
- package/lib/runtime/components/react/dist/pickerFaces.js +75 -0
- package/lib/runtime/components/react/dist/pickerOverlay.jsx +21 -0
- package/lib/runtime/components/react/dist/utils.jsx +54 -3
- package/lib/runtime/components/react/getInnerListeners.ts +3 -17
- package/lib/runtime/components/react/mpx-button.tsx +41 -8
- package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
- package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
- package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
- package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
- package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
- package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
- package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
- package/lib/runtime/components/react/mpx-canvas/index.tsx +302 -0
- package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +232 -103
- package/lib/runtime/components/react/mpx-picker-view.tsx +126 -122
- package/lib/runtime/components/react/mpx-view.tsx +57 -27
- package/lib/runtime/components/react/mpx-web-view.tsx +22 -5
- package/lib/runtime/components/react/pickerFaces.ts +104 -0
- package/lib/runtime/components/react/pickerOverlay.tsx +32 -0
- package/lib/runtime/components/react/types/common.ts +2 -0
- package/lib/runtime/components/react/types/global.d.ts +2 -0
- package/lib/runtime/components/react/utils.tsx +78 -7
- package/lib/template-compiler/compiler.js +3 -2
- package/lib/template-compiler/gen-node-react.js +2 -2
- package/package.json +5 -4
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import { View } from 'react-native'
|
|
2
|
-
import {
|
|
3
|
-
import React, { forwardRef, useState, useRef, ReactElement, JSX } from 'react'
|
|
2
|
+
import React, { forwardRef, useState, useRef } from 'react'
|
|
4
3
|
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
5
|
-
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
6
|
-
import {
|
|
4
|
+
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
5
|
+
import {
|
|
6
|
+
useLayout,
|
|
7
|
+
splitProps,
|
|
8
|
+
splitStyle,
|
|
9
|
+
wrapChildren,
|
|
10
|
+
parseInlineStyle,
|
|
11
|
+
useTransformStyle,
|
|
12
|
+
useDebounceCallback,
|
|
13
|
+
useStableCallback,
|
|
14
|
+
extendObject
|
|
15
|
+
} from './utils'
|
|
16
|
+
import type { AnyFunc } from './types/common'
|
|
7
17
|
/**
|
|
8
18
|
* ✔ value
|
|
9
19
|
* ✔ bindchange
|
|
@@ -18,9 +28,10 @@ import { parseInlineStyle, useTransformStyle, splitStyle, splitProps, useLayout,
|
|
|
18
28
|
|
|
19
29
|
interface PickerViewProps {
|
|
20
30
|
children: React.ReactNode
|
|
21
|
-
// 初始的defaultValue数组中的数字依次表示 picker-view 内的 picker-view-column 选择的第几项(下标从 0
|
|
31
|
+
// 初始的defaultValue数组中的数字依次表示 picker-view 内的 picker-view-column 选择的第几项(下标从 0 开始),
|
|
32
|
+
// 数字大于 picker-view-column 可选项长度时,选择最后一项。
|
|
22
33
|
value?: Array<number>
|
|
23
|
-
bindchange?:
|
|
34
|
+
bindchange?: AnyFunc
|
|
24
35
|
style: {
|
|
25
36
|
[key: string]: any
|
|
26
37
|
}
|
|
@@ -48,27 +59,29 @@ const styles: { [key: string]: Object } = {
|
|
|
48
59
|
justifyContent: 'space-around',
|
|
49
60
|
overflow: 'hidden',
|
|
50
61
|
alignItems: 'center'
|
|
51
|
-
},
|
|
52
|
-
maskTop: {
|
|
53
|
-
position: 'absolute',
|
|
54
|
-
width: 1000,
|
|
55
|
-
zIndex: 100
|
|
56
|
-
},
|
|
57
|
-
maskBottom: {
|
|
58
|
-
position: 'absolute',
|
|
59
|
-
width: 1000,
|
|
60
|
-
zIndex: 100
|
|
61
62
|
}
|
|
62
63
|
}
|
|
64
|
+
|
|
63
65
|
const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProps>((props: PickerViewProps, ref) => {
|
|
64
|
-
const {
|
|
66
|
+
const {
|
|
67
|
+
children,
|
|
68
|
+
value = [],
|
|
69
|
+
bindchange,
|
|
70
|
+
style,
|
|
71
|
+
'enable-var': enableVar,
|
|
72
|
+
'external-var-context': externalVarContext
|
|
73
|
+
} = props
|
|
74
|
+
|
|
65
75
|
// indicatorStyle 需要转换为rn的style
|
|
66
76
|
// 微信设置到pick-view上上设置的normalStyle如border等需要转换成RN的style然后进行透传
|
|
67
77
|
const indicatorStyle = parseInlineStyle(props['indicator-style'])
|
|
68
|
-
const { height: indicatorH,
|
|
78
|
+
const { height: indicatorH, ...pickerOverlayStyle } = indicatorStyle
|
|
79
|
+
const [pickMaxH, setPickMaxH] = useState(0)
|
|
69
80
|
const nodeRef = useRef(null)
|
|
70
|
-
|
|
71
|
-
|
|
81
|
+
const cloneRef = useRef(null)
|
|
82
|
+
const activeValueRef = useRef(value)
|
|
83
|
+
activeValueRef.current = value.slice()
|
|
84
|
+
|
|
72
85
|
const {
|
|
73
86
|
normalStyle,
|
|
74
87
|
hasVarDec,
|
|
@@ -77,69 +90,85 @@ const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProp
|
|
|
77
90
|
setWidth,
|
|
78
91
|
setHeight
|
|
79
92
|
} = useTransformStyle(style, { enableVar, externalVarContext })
|
|
80
|
-
|
|
81
|
-
const { textProps } = splitProps(props)
|
|
93
|
+
useNodesRef<View, PickerViewProps>(props, ref, nodeRef, {})
|
|
82
94
|
const {
|
|
83
95
|
// 存储layout布局信息
|
|
84
96
|
layoutRef,
|
|
85
97
|
layoutProps,
|
|
86
98
|
layoutStyle
|
|
87
99
|
} = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: nodeRef })
|
|
100
|
+
const { textProps } = splitProps(props)
|
|
101
|
+
const { textStyle } = splitStyle(normalStyle)
|
|
88
102
|
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const itemH = pickH / 5
|
|
94
|
-
if (normalStyle?.height && pickH && pickH !== normalStyle?.height) {
|
|
95
|
-
maskPos.height = itemH * 2 + Math.ceil((normalStyle.height - pickH) / 2)
|
|
96
|
-
} else {
|
|
97
|
-
maskPos.height = itemH * 2
|
|
103
|
+
const onColumnItemRawHChange = (height: number) => {
|
|
104
|
+
if (height > pickMaxH) {
|
|
105
|
+
setPickMaxH(height)
|
|
106
|
+
}
|
|
98
107
|
}
|
|
99
108
|
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
109
|
+
const bindchangeDebounce = useDebounceCallback(useStableCallback(bindchange), 300)
|
|
110
|
+
|
|
111
|
+
const onSelectChange = (columnIndex: number, selectedIndex: number) => {
|
|
112
|
+
bindchangeDebounce.clear()
|
|
113
|
+
const activeValue = activeValueRef.current
|
|
114
|
+
activeValue[columnIndex] = selectedIndex
|
|
115
|
+
const eventData = getCustomEvent(
|
|
116
|
+
'change',
|
|
117
|
+
{},
|
|
118
|
+
{ detail: { value: activeValue, source: 'change' }, layoutRef }
|
|
119
|
+
)
|
|
120
|
+
bindchangeDebounce(eventData)
|
|
103
121
|
}
|
|
104
122
|
|
|
105
|
-
const
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
123
|
+
const onInitialChange = (value: number[]) => {
|
|
124
|
+
const eventData = getCustomEvent(
|
|
125
|
+
'change',
|
|
126
|
+
{},
|
|
127
|
+
{ detail: { value, source: 'change' }, layoutRef }
|
|
128
|
+
)
|
|
129
|
+
bindchange?.(eventData) // immediate
|
|
110
130
|
}
|
|
111
131
|
|
|
112
|
-
const innerProps = useInnerProps(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
132
|
+
const innerProps = useInnerProps(
|
|
133
|
+
props,
|
|
134
|
+
extendObject({
|
|
135
|
+
ref: nodeRef,
|
|
136
|
+
style: extendObject(
|
|
137
|
+
normalStyle,
|
|
138
|
+
layoutStyle,
|
|
139
|
+
{
|
|
140
|
+
position: 'relative',
|
|
141
|
+
overflow: 'hidden'
|
|
142
|
+
}
|
|
143
|
+
),
|
|
144
|
+
layoutProps
|
|
145
|
+
}),
|
|
146
|
+
['enable-offset'],
|
|
147
|
+
{ layoutRef }
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
const renderColumn = (child: React.ReactElement, index: number, columnData: React.ReactNode[], initialIndex: number) => {
|
|
127
151
|
const extraProps = {}
|
|
128
|
-
const childProps = {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
152
|
+
const childProps = child?.props || {}
|
|
153
|
+
const wrappedProps = extendObject(
|
|
154
|
+
childProps,
|
|
155
|
+
{
|
|
156
|
+
columnData,
|
|
157
|
+
ref: cloneRef,
|
|
158
|
+
columnIndex: index,
|
|
159
|
+
key: `pick-view-${index}`,
|
|
160
|
+
wrapperStyle: {
|
|
161
|
+
height: normalStyle?.height || 0,
|
|
162
|
+
itemHeight: indicatorH || 0
|
|
163
|
+
},
|
|
164
|
+
onColumnItemRawHChange,
|
|
165
|
+
onSelectChange: onSelectChange.bind(null, index),
|
|
166
|
+
initialIndex,
|
|
167
|
+
pickerOverlayStyle
|
|
136
168
|
},
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
...extraProps
|
|
141
|
-
}
|
|
142
|
-
const realElement = React.cloneElement(child as ReactElement, childProps)
|
|
169
|
+
extraProps
|
|
170
|
+
)
|
|
171
|
+
const realElement = React.cloneElement(child, wrappedProps)
|
|
143
172
|
return wrapChildren(
|
|
144
173
|
{
|
|
145
174
|
children: realElement
|
|
@@ -153,69 +182,44 @@ const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProp
|
|
|
153
182
|
)
|
|
154
183
|
}
|
|
155
184
|
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
colors: ['rgba(255,255,255,0.8)', 'rgba(255,255,255,0.2)'],
|
|
159
|
-
style: [
|
|
160
|
-
styles.maskTop,
|
|
161
|
-
{
|
|
162
|
-
height: maskPos.height,
|
|
163
|
-
top: 0,
|
|
164
|
-
pointerEvents: 'none'
|
|
165
|
-
}
|
|
166
|
-
]
|
|
167
|
-
}
|
|
168
|
-
return (<LinearGradient {...linearProps}/>)
|
|
185
|
+
const validateChildInitialIndex = (index: number, data: React.ReactNode[]) => {
|
|
186
|
+
return Math.max(0, Math.min(value[index] || 0, data.length - 1))
|
|
169
187
|
}
|
|
170
188
|
|
|
171
|
-
const
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
{
|
|
177
|
-
height: maskPos.height,
|
|
178
|
-
bottom: 0,
|
|
179
|
-
pointerEvents: 'none'
|
|
180
|
-
}
|
|
181
|
-
]
|
|
189
|
+
const flatColumnChildren = (data: React.ReactElement) => {
|
|
190
|
+
const columnData = React.Children.toArray(data?.props?.children)
|
|
191
|
+
if (columnData.length === 1 && React.isValidElement(columnData[0]) && columnData[0].type === React.Fragment) {
|
|
192
|
+
// 只有一个 Fragment 嵌套情况
|
|
193
|
+
return React.Children.toArray(columnData[0].props.children)
|
|
182
194
|
}
|
|
183
|
-
return
|
|
195
|
+
return columnData
|
|
184
196
|
}
|
|
185
197
|
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
+
const renderPickerColumns = () => {
|
|
199
|
+
const columns = React.Children.toArray(children)
|
|
200
|
+
const renderColumns: React.ReactNode[] = []
|
|
201
|
+
const validValue: number[] = []
|
|
202
|
+
let isInvalid = false
|
|
203
|
+
columns.forEach((item: React.ReactElement, index) => {
|
|
204
|
+
const columnData = flatColumnChildren(item)
|
|
205
|
+
const validIndex = validateChildInitialIndex(index, columnData)
|
|
206
|
+
if (validIndex !== value[index]) {
|
|
207
|
+
isInvalid = true
|
|
208
|
+
}
|
|
209
|
+
validValue.push(validIndex)
|
|
210
|
+
renderColumns.push(renderColumn(item, index, columnData, validIndex))
|
|
211
|
+
})
|
|
212
|
+
isInvalid && onInitialChange(validValue)
|
|
213
|
+
return renderColumns
|
|
198
214
|
}
|
|
199
215
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
return cloneChild(item, index)
|
|
204
|
-
})
|
|
205
|
-
} else {
|
|
206
|
-
return cloneChild(children, 0)
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
return (<View {...innerProps}>
|
|
210
|
-
{renderTopMask()}
|
|
211
|
-
<View style={[styles.wrapper]}>
|
|
212
|
-
{renderSubChild()}
|
|
216
|
+
return (
|
|
217
|
+
<View {...innerProps}>
|
|
218
|
+
<View style={[styles.wrapper]}>{renderPickerColumns()}</View>
|
|
213
219
|
</View>
|
|
214
|
-
|
|
215
|
-
{!isSetW && renderLine()}
|
|
216
|
-
</View>)
|
|
220
|
+
)
|
|
217
221
|
})
|
|
218
222
|
|
|
219
|
-
_PickerView.displayName = '
|
|
223
|
+
_PickerView.displayName = 'MpxPickerView'
|
|
220
224
|
|
|
221
225
|
export default _PickerView
|
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
* ✔ hover-start-time
|
|
5
5
|
* ✔ hover-stay-time
|
|
6
6
|
*/
|
|
7
|
-
import { View, TextStyle, NativeSyntheticEvent, ViewProps, ImageStyle,
|
|
8
|
-
import { useRef, useState, useEffect, forwardRef, ReactNode, JSX
|
|
7
|
+
import { View, TextStyle, NativeSyntheticEvent, ViewProps, ImageStyle, StyleSheet, Image, LayoutChangeEvent } from 'react-native'
|
|
8
|
+
import { useRef, useState, useEffect, forwardRef, ReactNode, JSX } from 'react'
|
|
9
9
|
import useInnerProps from './getInnerListeners'
|
|
10
10
|
import Animated from 'react-native-reanimated'
|
|
11
11
|
import useAnimationHooks from './useAnimationHooks'
|
|
12
12
|
import type { AnimationProp } from './useAnimationHooks'
|
|
13
13
|
import { ExtendedViewStyle } from './types/common'
|
|
14
14
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
15
|
-
import { parseUrl, PERCENT_REGEX, splitStyle, splitProps, useTransformStyle, wrapChildren, useLayout } from './utils'
|
|
15
|
+
import { parseUrl, PERCENT_REGEX, splitStyle, splitProps, useTransformStyle, wrapChildren, useLayout, renderImage, pickStyle } from './utils'
|
|
16
16
|
import LinearGradient from 'react-native-linear-gradient'
|
|
17
17
|
|
|
18
18
|
export interface _ViewProps extends ViewProps {
|
|
@@ -24,6 +24,7 @@ export interface _ViewProps extends ViewProps {
|
|
|
24
24
|
'hover-stay-time'?: number
|
|
25
25
|
'enable-background'?: boolean
|
|
26
26
|
'enable-var'?: boolean
|
|
27
|
+
'enable-fast-image'?: boolean
|
|
27
28
|
'external-var-context'?: Record<string, any>
|
|
28
29
|
'parent-font-size'?: number
|
|
29
30
|
'parent-width'?: number
|
|
@@ -76,9 +77,11 @@ type PreImageInfo = {
|
|
|
76
77
|
type ImageProps = {
|
|
77
78
|
style: ImageStyle,
|
|
78
79
|
src?: string,
|
|
80
|
+
source?: {uri: string },
|
|
79
81
|
colors: Array<string>,
|
|
80
82
|
locations?: Array<number>
|
|
81
83
|
angle?: number
|
|
84
|
+
resizeMode?: 'cover' | 'stretch'
|
|
82
85
|
}
|
|
83
86
|
|
|
84
87
|
const linearMap = new Map([
|
|
@@ -280,13 +283,14 @@ function backgroundSize (imageProps: ImageProps, preImageInfo: PreImageInfo, ima
|
|
|
280
283
|
if (!dimensions) return
|
|
281
284
|
} else { // 数值类型 ImageStyle
|
|
282
285
|
// 数值类型设置为 stretch
|
|
283
|
-
|
|
286
|
+
imageProps.resizeMode = 'stretch'
|
|
284
287
|
dimensions = {
|
|
285
288
|
width: isPercent(width) ? width : +width,
|
|
286
289
|
height: isPercent(height) ? height : +height
|
|
287
290
|
} as { width: NumberVal, height: NumberVal }
|
|
288
291
|
}
|
|
289
292
|
}
|
|
293
|
+
|
|
290
294
|
// 样式合并
|
|
291
295
|
imageProps.style = {
|
|
292
296
|
...imageProps.style as ImageStyle,
|
|
@@ -296,8 +300,9 @@ function backgroundSize (imageProps: ImageProps, preImageInfo: PreImageInfo, ima
|
|
|
296
300
|
|
|
297
301
|
// background-image转换为source
|
|
298
302
|
function backgroundImage (imageProps: ImageProps, preImageInfo: PreImageInfo) {
|
|
299
|
-
|
|
300
|
-
|
|
303
|
+
const src = preImageInfo.src
|
|
304
|
+
if (src) {
|
|
305
|
+
imageProps.source = { uri: src }
|
|
301
306
|
}
|
|
302
307
|
}
|
|
303
308
|
|
|
@@ -326,8 +331,8 @@ function linearGradient (imageProps: ImageProps, preImageInfo: PreImageInfo, ima
|
|
|
326
331
|
const imageStyleToProps = (preImageInfo: PreImageInfo, imageSize: Size, layoutInfo: Size) => {
|
|
327
332
|
// 初始化
|
|
328
333
|
const imageProps: ImageProps = {
|
|
334
|
+
resizeMode: 'cover',
|
|
329
335
|
style: {
|
|
330
|
-
resizeMode: 'cover' as ImageResizeMode,
|
|
331
336
|
position: 'absolute'
|
|
332
337
|
// ...StyleSheet.absoluteFillObject
|
|
333
338
|
},
|
|
@@ -533,7 +538,26 @@ function isDiagonalAngle (linearInfo?: LinearInfo): boolean {
|
|
|
533
538
|
return !!(linearInfo?.direction && diagonalAngleMap[linearInfo.direction])
|
|
534
539
|
}
|
|
535
540
|
|
|
536
|
-
function
|
|
541
|
+
function inheritStyle (innerStyle: ExtendedViewStyle = {}) {
|
|
542
|
+
const { borderWidth, borderRadius } = innerStyle
|
|
543
|
+
const borderStyles = ['borderRadius', 'borderTopLeftRadius', 'borderTopRightRadius', 'borderBottomRightRadius', 'borderBottomLeftRadius']
|
|
544
|
+
return pickStyle(innerStyle,
|
|
545
|
+
borderStyles,
|
|
546
|
+
borderWidth && borderRadius
|
|
547
|
+
? (key, val) => {
|
|
548
|
+
// 盒子内圆角borderWith与borderRadius的关系
|
|
549
|
+
// 当borderRadius 小于 当borderWith 内边框为直角
|
|
550
|
+
// 当borderRadius 大于等于 当borderWith 内边框为圆角
|
|
551
|
+
if (borderStyles.includes(key)) {
|
|
552
|
+
const borderVal = +val - borderWidth
|
|
553
|
+
return borderVal > 0 ? borderVal : 0
|
|
554
|
+
}
|
|
555
|
+
return val
|
|
556
|
+
}
|
|
557
|
+
: undefined)
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
function wrapImage (imageStyle?: ExtendedViewStyle, innerStyle?: Record<string, any>, enableFastImage?: boolean) {
|
|
537
561
|
// 预处理数据
|
|
538
562
|
const preImageInfo: PreImageInfo = preParseImage(imageStyle)
|
|
539
563
|
// 预解析
|
|
@@ -616,9 +640,9 @@ function wrapImage (imageStyle?: ExtendedViewStyle) {
|
|
|
616
640
|
}
|
|
617
641
|
}
|
|
618
642
|
|
|
619
|
-
return <View key='backgroundImage' {...needLayout ? { onLayout } : null} style={{ ...StyleSheet.absoluteFillObject, overflow: 'hidden' }}>
|
|
643
|
+
return <View key='backgroundImage' {...needLayout ? { onLayout } : null} style={{ ...inheritStyle(innerStyle), ...StyleSheet.absoluteFillObject, overflow: 'hidden' }}>
|
|
620
644
|
{show && type === 'linear' && <LinearGradient useAngle={true} {...imageStyleToProps(preImageInfo, sizeInfo.current as Size, layoutInfo.current as Size)} /> }
|
|
621
|
-
{show && type === 'image' &&
|
|
645
|
+
{show && type === 'image' && (renderImage(imageStyleToProps(preImageInfo, sizeInfo.current as Size, layoutInfo.current as Size), enableFastImage))}
|
|
622
646
|
</View>
|
|
623
647
|
}
|
|
624
648
|
|
|
@@ -629,9 +653,11 @@ interface WrapChildrenConfig {
|
|
|
629
653
|
backgroundStyle?: ExtendedViewStyle
|
|
630
654
|
varContext?: Record<string, any>
|
|
631
655
|
textProps?: Record<string, any>
|
|
656
|
+
innerStyle?: Record<string, any>
|
|
657
|
+
enableFastImage?: boolean
|
|
632
658
|
}
|
|
633
659
|
|
|
634
|
-
function wrapWithChildren (props: _ViewProps, { hasVarDec, enableBackground, textStyle, backgroundStyle, varContext, textProps }: WrapChildrenConfig) {
|
|
660
|
+
function wrapWithChildren (props: _ViewProps, { hasVarDec, enableBackground, textStyle, backgroundStyle, varContext, textProps, innerStyle, enableFastImage }: WrapChildrenConfig) {
|
|
635
661
|
const children = wrapChildren(props, {
|
|
636
662
|
hasVarDec,
|
|
637
663
|
varContext,
|
|
@@ -640,7 +666,7 @@ function wrapWithChildren (props: _ViewProps, { hasVarDec, enableBackground, tex
|
|
|
640
666
|
})
|
|
641
667
|
|
|
642
668
|
return [
|
|
643
|
-
enableBackground ? wrapImage(backgroundStyle) : null,
|
|
669
|
+
enableBackground ? wrapImage(backgroundStyle, innerStyle, enableFastImage) : null,
|
|
644
670
|
children
|
|
645
671
|
]
|
|
646
672
|
}
|
|
@@ -655,6 +681,7 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
|
|
|
655
681
|
'enable-var': enableVar,
|
|
656
682
|
'external-var-context': externalVarContext,
|
|
657
683
|
'enable-background': enableBackground,
|
|
684
|
+
'enable-fast-image': enableFastImage,
|
|
658
685
|
'enable-animation': enableAnimation,
|
|
659
686
|
'parent-font-size': parentFontSize,
|
|
660
687
|
'parent-width': parentWidth,
|
|
@@ -755,9 +782,22 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
|
|
|
755
782
|
} = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
|
|
756
783
|
|
|
757
784
|
const viewStyle = Object.assign({}, innerStyle, layoutStyle)
|
|
785
|
+
|
|
786
|
+
enableAnimation = enableAnimation || !!animation
|
|
787
|
+
const enableAnimationRef = useRef(enableAnimation)
|
|
788
|
+
if (enableAnimationRef.current !== enableAnimation) {
|
|
789
|
+
throw new Error('[Mpx runtime error]: animation use should be stable in the component lifecycle, or you can set [enable-animation] with true.')
|
|
790
|
+
}
|
|
791
|
+
const finalStyle = enableAnimation
|
|
792
|
+
? useAnimationHooks({
|
|
793
|
+
animation,
|
|
794
|
+
style: viewStyle
|
|
795
|
+
})
|
|
796
|
+
: viewStyle
|
|
797
|
+
|
|
758
798
|
const innerProps = useInnerProps(props, {
|
|
759
799
|
ref: nodeRef,
|
|
760
|
-
style:
|
|
800
|
+
style: finalStyle,
|
|
761
801
|
...layoutProps,
|
|
762
802
|
...(hoverStyle && {
|
|
763
803
|
bindtouchstart: onTouchStart,
|
|
@@ -772,29 +812,19 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
|
|
|
772
812
|
layoutRef
|
|
773
813
|
})
|
|
774
814
|
|
|
775
|
-
enableAnimation = enableAnimation || !!animation
|
|
776
|
-
const enableAnimationRef = useRef(enableAnimation)
|
|
777
|
-
if (enableAnimationRef.current !== enableAnimation) {
|
|
778
|
-
throw new Error('[Mpx runtime error]: animation use should be stable in the component lifecycle, or you can set [enable-animation] with true.')
|
|
779
|
-
}
|
|
780
|
-
const finalStyle = enableAnimation
|
|
781
|
-
? useAnimationHooks({
|
|
782
|
-
animation,
|
|
783
|
-
style: viewStyle
|
|
784
|
-
})
|
|
785
|
-
: viewStyle
|
|
786
815
|
const childNode = wrapWithChildren(props, {
|
|
787
816
|
hasVarDec,
|
|
788
817
|
enableBackground: enableBackgroundRef.current,
|
|
789
818
|
textStyle,
|
|
790
819
|
backgroundStyle,
|
|
791
820
|
varContext: varContextRef.current,
|
|
792
|
-
textProps
|
|
821
|
+
textProps,
|
|
822
|
+
innerStyle,
|
|
823
|
+
enableFastImage
|
|
793
824
|
})
|
|
794
|
-
return
|
|
825
|
+
return enableAnimation
|
|
795
826
|
? (<Animated.View
|
|
796
827
|
{...innerProps}
|
|
797
|
-
style={finalStyle}
|
|
798
828
|
>
|
|
799
829
|
{childNode}
|
|
800
830
|
</Animated.View>)
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { forwardRef, JSX, useEffect, useRef } from 'react'
|
|
1
|
+
import { forwardRef, JSX, useEffect, useRef, useContext, useMemo } from 'react'
|
|
2
2
|
import { noop, warn } from '@mpxjs/utils'
|
|
3
3
|
import { Portal } from '@ant-design/react-native'
|
|
4
4
|
import { getCustomEvent } from './getInnerListeners'
|
|
5
5
|
import { promisify, redirectTo, navigateTo, navigateBack, reLaunch, switchTab } from '@mpxjs/api-proxy'
|
|
6
6
|
import { WebView } from 'react-native-webview'
|
|
7
7
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
8
|
-
import {
|
|
8
|
+
import { getCurrentPage } from './utils'
|
|
9
|
+
import { WebViewNavigationEvent, WebViewErrorEvent, WebViewMessageEvent, WebViewNavigation } from 'react-native-webview/lib/WebViewTypes'
|
|
10
|
+
import { RouteContext } from './context'
|
|
9
11
|
|
|
10
12
|
type OnMessageCallbackEvent = {
|
|
11
13
|
detail: {
|
|
@@ -51,6 +53,9 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
51
53
|
if (props.style) {
|
|
52
54
|
warn('The web-view component does not support the style prop.')
|
|
53
55
|
}
|
|
56
|
+
const pageId = useContext(RouteContext)
|
|
57
|
+
const currentPage = useMemo(() => getCurrentPage(pageId), [pageId])
|
|
58
|
+
|
|
54
59
|
const defaultWebViewStyle = {
|
|
55
60
|
position: 'absolute' as 'absolute' | 'relative' | 'static',
|
|
56
61
|
left: 0 as number,
|
|
@@ -64,17 +69,23 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
64
69
|
defaultStyle: defaultWebViewStyle
|
|
65
70
|
})
|
|
66
71
|
|
|
67
|
-
const _messageList
|
|
72
|
+
const _messageList = useRef<any[]>([])
|
|
68
73
|
const handleUnload = () => {
|
|
69
74
|
// 这里是 WebView 销毁前执行的逻辑
|
|
70
75
|
bindmessage(getCustomEvent('messsage', {}, {
|
|
71
76
|
detail: {
|
|
72
|
-
data: _messageList
|
|
77
|
+
data: _messageList.current
|
|
73
78
|
},
|
|
74
79
|
layoutRef: webViewRef
|
|
75
80
|
}))
|
|
76
81
|
}
|
|
77
82
|
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
if (currentPage) {
|
|
85
|
+
currentPage.__webViewUrl = src
|
|
86
|
+
}
|
|
87
|
+
}, [src, currentPage])
|
|
88
|
+
|
|
78
89
|
useEffect(() => {
|
|
79
90
|
// 组件卸载时执行
|
|
80
91
|
return () => {
|
|
@@ -101,6 +112,11 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
101
112
|
}
|
|
102
113
|
binderror(result)
|
|
103
114
|
}
|
|
115
|
+
const _changeUrl = function (navState: WebViewNavigation) {
|
|
116
|
+
if (currentPage) {
|
|
117
|
+
currentPage.__webViewUrl = navState.url
|
|
118
|
+
}
|
|
119
|
+
}
|
|
104
120
|
const _message = function (res: WebViewMessageEvent) {
|
|
105
121
|
let data: MessageData = {}
|
|
106
122
|
let asyncCallback
|
|
@@ -116,7 +132,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
116
132
|
const postData: PayloadData = data.payload || {}
|
|
117
133
|
switch (data.type) {
|
|
118
134
|
case 'postMessage':
|
|
119
|
-
_messageList.push(postData.data)
|
|
135
|
+
_messageList.current.push(postData.data)
|
|
120
136
|
asyncCallback = Promise.resolve({
|
|
121
137
|
errMsg: 'invokeWebappApi:ok'
|
|
122
138
|
})
|
|
@@ -157,6 +173,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
157
173
|
onLoad={_load}
|
|
158
174
|
onError={_error}
|
|
159
175
|
onMessage={_message}
|
|
176
|
+
onNavigationStateChange={_changeUrl}
|
|
160
177
|
javaScriptEnabled={true}
|
|
161
178
|
></WebView>
|
|
162
179
|
</Portal>)
|