@mpxjs/webpack-plugin 2.9.65 → 2.9.67
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/dependencies/RecordGlobalComponentsDependency.js +11 -12
- package/lib/dependencies/RecordRuntimeInfoDependency.js +1 -1
- package/lib/index.js +28 -8
- package/lib/json-compiler/index.js +2 -11
- package/lib/loader.js +24 -45
- package/lib/native-loader.js +49 -64
- package/lib/platform/json/wx/index.js +3 -10
- package/lib/platform/style/wx/index.js +32 -56
- package/lib/react/index.js +4 -3
- package/lib/react/processJSON.js +5 -13
- package/lib/react/processMainScript.js +7 -3
- package/lib/react/processScript.js +3 -4
- package/lib/react/processTemplate.js +6 -4
- package/lib/resolver/AddModePlugin.js +17 -4
- package/lib/runtime/components/react/context.ts +8 -0
- package/lib/runtime/components/react/dist/context.js +1 -0
- package/lib/runtime/components/react/dist/mpx-button.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +30 -17
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-form.jsx +33 -24
- package/lib/runtime/components/react/dist/mpx-icon.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-input.jsx +44 -38
- package/lib/runtime/components/react/dist/mpx-label.jsx +10 -7
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +10 -17
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +378 -294
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +30 -17
- package/lib/runtime/components/react/dist/mpx-radio.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +58 -30
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +77 -77
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-switch.jsx +8 -1
- package/lib/runtime/components/react/dist/mpx-text.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-view.jsx +31 -12
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +2 -2
- package/lib/runtime/components/react/dist/useAnimationHooks.js +303 -0
- package/lib/runtime/components/react/dist/utils.jsx +13 -3
- package/lib/runtime/components/react/getInnerListeners.ts +1 -0
- package/lib/runtime/components/react/mpx-button.tsx +1 -1
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +52 -29
- package/lib/runtime/components/react/mpx-checkbox.tsx +1 -1
- package/lib/runtime/components/react/mpx-form.tsx +42 -34
- package/lib/runtime/components/react/mpx-icon.tsx +1 -1
- package/lib/runtime/components/react/mpx-image/index.tsx +2 -3
- package/lib/runtime/components/react/mpx-input.tsx +68 -66
- package/lib/runtime/components/react/mpx-label.tsx +11 -8
- package/lib/runtime/components/react/mpx-movable-area.tsx +11 -19
- package/lib/runtime/components/react/mpx-movable-view.tsx +456 -334
- package/lib/runtime/components/react/mpx-navigator.tsx +1 -1
- package/lib/runtime/components/react/mpx-radio-group.tsx +55 -29
- package/lib/runtime/components/react/mpx-radio.tsx +1 -1
- package/lib/runtime/components/react/mpx-root-portal.tsx +1 -1
- package/lib/runtime/components/react/mpx-scroll-view.tsx +92 -37
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +77 -76
- package/lib/runtime/components/react/mpx-swiper/index.tsx +2 -1
- package/lib/runtime/components/react/mpx-swiper-item.tsx +1 -1
- package/lib/runtime/components/react/mpx-switch.tsx +10 -2
- package/lib/runtime/components/react/mpx-text.tsx +1 -1
- package/lib/runtime/components/react/mpx-textarea.tsx +1 -1
- package/lib/runtime/components/react/mpx-view.tsx +40 -20
- package/lib/runtime/components/react/mpx-web-view.tsx +2 -2
- package/lib/runtime/components/react/types/common.ts +8 -2
- package/lib/runtime/components/react/useAnimationHooks.ts +332 -0
- package/lib/runtime/components/react/useNodesRef.ts +1 -0
- package/lib/runtime/components/react/utils.tsx +23 -6
- package/lib/runtime/optionProcessorReact.js +0 -15
- package/lib/runtime/swanHelper.wxs +1 -1
- package/lib/style-compiler/index.js +1 -1
- package/lib/style-compiler/plugins/scope-id.js +1 -0
- package/lib/template-compiler/compiler.js +68 -33
- package/lib/template-compiler/index.js +4 -4
- package/lib/utils/pre-process-json.js +113 -0
- package/lib/web/index.js +5 -4
- package/lib/web/processJSON.js +5 -13
- package/lib/web/processTemplate.js +2 -2
- package/package.json +5 -4
|
@@ -87,6 +87,8 @@ const _Carouse = forwardRef<HandlerRef<ScrollView & View, CarouseProps>, Carouse
|
|
|
87
87
|
const initOffsetIndex = initIndex + (props.circular && totalElements > 1 ? 1 : 0)
|
|
88
88
|
const defaultX = (defaultWidth * initOffsetIndex) || 0
|
|
89
89
|
const defaultY = (defaultHeight * initOffsetIndex) || 0
|
|
90
|
+
// 主动scorllTo时是否要出发onScrollEnd
|
|
91
|
+
const needTriggerScrollEnd = useRef(true)
|
|
90
92
|
// 内部存储上一次的offset值
|
|
91
93
|
const autoplayTimerRef = useRef<ReturnType <typeof setTimeout> | null>(null)
|
|
92
94
|
const scrollViewRef = useRef<ScrollView & View>(null)
|
|
@@ -100,22 +102,21 @@ const _Carouse = forwardRef<HandlerRef<ScrollView & View, CarouseProps>, Carouse
|
|
|
100
102
|
// 内部存储上一次的偏移量
|
|
101
103
|
const internalsRef = useRef({
|
|
102
104
|
offset: {
|
|
103
|
-
x:
|
|
104
|
-
y:
|
|
105
|
+
x: 0,
|
|
106
|
+
y: 0
|
|
105
107
|
},
|
|
106
108
|
isScrolling: false
|
|
107
109
|
})
|
|
108
110
|
const isDragRef = useRef(false)
|
|
109
111
|
const [state, setState] = useState({
|
|
110
|
-
children: newChild,
|
|
111
112
|
width: dir === 'x' && typeof defaultWidth === 'number' ? defaultWidth - previousMargin - nextMargin : defaultWidth,
|
|
112
113
|
height: dir === 'y' && typeof defaultHeight === 'number' ? defaultHeight - previousMargin - nextMargin : defaultHeight,
|
|
113
114
|
// 真正的游标索引, 从0开始
|
|
114
115
|
index: initIndex,
|
|
115
116
|
total: totalElements,
|
|
116
117
|
offset: {
|
|
117
|
-
x:
|
|
118
|
-
y:
|
|
118
|
+
x: 0,
|
|
119
|
+
y: 0
|
|
119
120
|
},
|
|
120
121
|
dir
|
|
121
122
|
} as CarouseState)
|
|
@@ -138,25 +139,38 @@ const _Carouse = forwardRef<HandlerRef<ScrollView & View, CarouseProps>, Carouse
|
|
|
138
139
|
|
|
139
140
|
useEffect(() => {
|
|
140
141
|
// 确认这个是变化的props变化的时候才执行,还是初始化的时候就执行
|
|
141
|
-
if (!props.autoplay && props.current !== state.index) {
|
|
142
|
+
if (!props.autoplay && props.current !== undefined && props.current !== state.index) {
|
|
142
143
|
const initIndex = props.current || 0
|
|
143
144
|
// 这里要排除超过元素个数的设置
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
145
|
+
const { nextIndex, nextOffset } = getMultiNextConfig(props.current)
|
|
146
|
+
// 1. 安卓需要主动更新下内部状态, 2. IOS不能触发完wcrollTo之后立即updateState, 会造成滑动两次
|
|
147
|
+
// 2. setTimeout 是fix 当再渲染过程中触发scrollTo失败的问题
|
|
148
|
+
if (Platform.OS === 'ios') {
|
|
149
|
+
needTriggerScrollEnd.current = false
|
|
150
|
+
setTimeout(() => {
|
|
151
|
+
scrollViewRef.current?.scrollTo({
|
|
152
|
+
...nextOffset,
|
|
153
|
+
animated: true
|
|
154
|
+
})
|
|
155
|
+
}, 50)
|
|
156
|
+
} else {
|
|
157
|
+
updateState(nextIndex, nextOffset)
|
|
149
158
|
}
|
|
150
|
-
state.offset = offset
|
|
151
|
-
internalsRef.current.offset = offset
|
|
152
|
-
setState((preState) => {
|
|
153
|
-
return {
|
|
154
|
-
...preState,
|
|
155
|
-
offset
|
|
156
|
-
}
|
|
157
|
-
})
|
|
158
159
|
}
|
|
159
|
-
}, [props.current])
|
|
160
|
+
}, [props.current, state.width, state.height])
|
|
161
|
+
|
|
162
|
+
function getMultiNextConfig (target: number) {
|
|
163
|
+
const step = state.dir === 'x' ? state.width : state.height
|
|
164
|
+
const targetPos = step * props.current
|
|
165
|
+
const targetOffset = {
|
|
166
|
+
x: dir === 'x' ? targetPos : 0,
|
|
167
|
+
y: dir === 'y' ? targetPos : 0
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
nextIndex: target,
|
|
171
|
+
nextOffset: targetOffset
|
|
172
|
+
}
|
|
173
|
+
}
|
|
160
174
|
/**
|
|
161
175
|
* @desc: 更新状态: index和offset, 并响应索引变化的事件
|
|
162
176
|
* scrollViewOffset: 移动到的目标位置
|
|
@@ -208,7 +222,6 @@ const _Carouse = forwardRef<HandlerRef<ScrollView & View, CarouseProps>, Carouse
|
|
|
208
222
|
nextIndex = isBack ? nextIndex - 2 : nextIndex
|
|
209
223
|
}
|
|
210
224
|
if (!props.circular) {
|
|
211
|
-
// nextIndex = isBack ? nextIndex - 2 : nextIndex
|
|
212
225
|
nextOffset = Object.assign({}, currentOffset, { [state.dir]: step * nextIndex })
|
|
213
226
|
} else {
|
|
214
227
|
if (isBack) {
|
|
@@ -254,13 +267,12 @@ const _Carouse = forwardRef<HandlerRef<ScrollView & View, CarouseProps>, Carouse
|
|
|
254
267
|
createAutoPlay()
|
|
255
268
|
return
|
|
256
269
|
}
|
|
257
|
-
if (!Array.isArray(
|
|
270
|
+
if (!Array.isArray(props.children)) {
|
|
258
271
|
return
|
|
259
272
|
}
|
|
260
273
|
const step = state.dir === 'x' ? state.width : state.height
|
|
261
274
|
const { nextOffset, autoMoveOffset, isAutoEnd } = getNextConfig(state.offset)
|
|
262
275
|
// 这里可以scroll到下一个元素, 但是把scrollView的偏移量在设置为content,视觉效果就没了吧
|
|
263
|
-
// scrollViewRef.current?.scrollTo({ x: nextOffset['x'], y: nextOffset['y'], animated: true })
|
|
264
276
|
if (Platform.OS === 'ios') {
|
|
265
277
|
if (!isAutoEnd) {
|
|
266
278
|
scrollViewRef.current?.scrollTo({ x: nextOffset.x, y: nextOffset.y, animated: true })
|
|
@@ -286,7 +298,6 @@ const _Carouse = forwardRef<HandlerRef<ScrollView & View, CarouseProps>, Carouse
|
|
|
286
298
|
// 安卓无法实现视觉的无缝连接, 只能回到真正的位置, 且安卓调用scrollTo不能触发onMomentumScrollEnd,还未找到为啥
|
|
287
299
|
if (state.dir === 'x') {
|
|
288
300
|
scrollViewRef.current?.scrollTo({ x: step, y: step, animated: true })
|
|
289
|
-
// scrollViewRef.current?.scrollTo({ x: autoMoveOffset.x, y: autoMoveOffset.y, animated: true })
|
|
290
301
|
} else {
|
|
291
302
|
scrollViewRef.current?.scrollTo({ x: autoMoveOffset.x, y: step, animated: true })
|
|
292
303
|
}
|
|
@@ -304,9 +315,15 @@ const _Carouse = forwardRef<HandlerRef<ScrollView & View, CarouseProps>, Carouse
|
|
|
304
315
|
|
|
305
316
|
/**
|
|
306
317
|
* 当用户开始拖动结束
|
|
318
|
+
* 注意: 当手动调用scrollTo的时候, 安卓不会触发onMomentumScrollEnd, IOS会触发onMomentumScrollEnd
|
|
307
319
|
*/
|
|
308
320
|
function onScrollEnd (event: NativeSyntheticEvent<NativeScrollEvent>) {
|
|
309
|
-
|
|
321
|
+
if (Platform.OS === 'ios' && !needTriggerScrollEnd.current) {
|
|
322
|
+
const { nextIndex, nextOffset } = getMultiNextConfig(props.current)
|
|
323
|
+
updateState(nextIndex, nextOffset)
|
|
324
|
+
needTriggerScrollEnd.current = true
|
|
325
|
+
return
|
|
326
|
+
}
|
|
310
327
|
if (totalElements === 1) {
|
|
311
328
|
return
|
|
312
329
|
}
|
|
@@ -334,57 +351,41 @@ const _Carouse = forwardRef<HandlerRef<ScrollView & View, CarouseProps>, Carouse
|
|
|
334
351
|
* @desc: 水平方向时,获取元素的布局,更新, 其中如果传递100%时需要依赖measure计算元算的宽高
|
|
335
352
|
*/
|
|
336
353
|
function onWrapperLayout (e: LayoutChangeEvent) {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
const isWDiff = state.width !== width
|
|
346
|
-
const isHDiff = state.height !== height
|
|
347
|
-
if (isWDiff || isHDiff) {
|
|
348
|
-
const changeState = {
|
|
349
|
-
width: isWDiff ? width : state.width,
|
|
350
|
-
height: isHDiff ? height : state.height
|
|
351
|
-
}
|
|
352
|
-
const attr = state.dir === 'x' ? 'width' : 'height'
|
|
353
|
-
changeState[attr] = changeState[attr] - previousMargin - nextMargin
|
|
354
|
-
const correctOffset = Object.assign({}, state.offset, {
|
|
355
|
-
[state.dir]: initOffsetIndex * (state.dir === 'x' ? changeState.width : changeState.height)
|
|
356
|
-
})
|
|
357
|
-
state.offset = correctOffset
|
|
358
|
-
state.width = changeState.width
|
|
359
|
-
state.height = changeState.height
|
|
360
|
-
setState((preState) => {
|
|
361
|
-
return {
|
|
362
|
-
...preState,
|
|
363
|
-
offset: correctOffset,
|
|
364
|
-
width: changeState.width,
|
|
365
|
-
height: changeState.height
|
|
366
|
-
}
|
|
367
|
-
})
|
|
368
|
-
scrollViewRef.current?.scrollTo({ x: correctOffset.x, y: correctOffset.y, animated: false })
|
|
354
|
+
scrollViewRef.current?.measure((x: number, y: number, width: number, height: number, offsetLeft: number, offsetTop: number) => {
|
|
355
|
+
layoutRef.current = { x, y, width, height, offsetLeft, offsetTop }
|
|
356
|
+
const isWDiff = state.width !== width
|
|
357
|
+
const isHDiff = state.height !== height
|
|
358
|
+
if (isWDiff || isHDiff) {
|
|
359
|
+
const changeState = {
|
|
360
|
+
width: isWDiff ? width : state.width,
|
|
361
|
+
height: isHDiff ? height : state.height
|
|
369
362
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
363
|
+
const attr = state.dir === 'x' ? 'width' : 'height'
|
|
364
|
+
changeState[attr] = changeState[attr] - previousMargin - nextMargin
|
|
365
|
+
const correctOffset = Object.assign({}, state.offset, {
|
|
366
|
+
[state.dir]: initOffsetIndex * (state.dir === 'x' ? changeState.width : changeState.height)
|
|
367
|
+
})
|
|
368
|
+
state.width = changeState.width
|
|
369
|
+
state.height = changeState.height
|
|
370
|
+
// 这里setState之后,会再触发重新渲染, renderScrollView会再次触发onScrollEnd,
|
|
371
|
+
setState((preState) => {
|
|
372
|
+
return {
|
|
373
|
+
...preState,
|
|
374
|
+
width: changeState.width,
|
|
375
|
+
height: changeState.height
|
|
376
|
+
}
|
|
377
|
+
})
|
|
378
|
+
}
|
|
379
|
+
props.getInnerLayout && props.getInnerLayout(layoutRef)
|
|
380
|
+
})
|
|
373
381
|
}
|
|
374
382
|
|
|
375
383
|
function getOffset (): Array<number> {
|
|
376
384
|
const step = state.dir === 'x' ? state.width : state.height
|
|
377
385
|
if (!step || Number.isNaN(+step)) return []
|
|
378
386
|
const offsetArray = []
|
|
379
|
-
|
|
380
|
-
offsetArray.push(
|
|
381
|
-
for (let i = 1; i < totalElements; i++) {
|
|
382
|
-
offsetArray.push(i * step - previousMargin)
|
|
383
|
-
}
|
|
384
|
-
} else {
|
|
385
|
-
for (let i = 0; i < totalElements; i++) {
|
|
386
|
-
offsetArray.push(i * step)
|
|
387
|
-
}
|
|
387
|
+
for (let i = 0; i < totalElements; i++) {
|
|
388
|
+
offsetArray.push(i * step)
|
|
388
389
|
}
|
|
389
390
|
return offsetArray
|
|
390
391
|
}
|
|
@@ -394,7 +395,7 @@ const _Carouse = forwardRef<HandlerRef<ScrollView & View, CarouseProps>, Carouse
|
|
|
394
395
|
const scrollElementProps = {
|
|
395
396
|
ref: scrollViewRef,
|
|
396
397
|
horizontal: props.horizontal,
|
|
397
|
-
pagingEnabled:
|
|
398
|
+
pagingEnabled: true,
|
|
398
399
|
snapToOffsets: offsetsArray,
|
|
399
400
|
decelerationRate: 0.99, // 'fast'
|
|
400
401
|
showsHorizontalScrollIndicator: false,
|
|
@@ -461,20 +462,21 @@ const _Carouse = forwardRef<HandlerRef<ScrollView & View, CarouseProps>, Carouse
|
|
|
461
462
|
}
|
|
462
463
|
|
|
463
464
|
function renderPages () {
|
|
464
|
-
const { width, height
|
|
465
|
+
const { width, height } = state
|
|
466
|
+
const { children } = props
|
|
465
467
|
const { circular } = props
|
|
466
468
|
const pageStyle = { width: width, height: height }
|
|
467
469
|
// 设置了previousMargin或者nextMargin,
|
|
468
470
|
// 1. 元素的宽度是减去这两个数目之和
|
|
469
471
|
// 2. previousMargin设置marginLeft正值, nextmargin设置marginRight负值
|
|
470
472
|
// 3. 第一个元素设置previousMargin 和 nextMargin, 最后一个元素
|
|
471
|
-
if (
|
|
473
|
+
if (totalElements > 1 && Array.isArray(children)) {
|
|
472
474
|
let arrElements: (Array<ReactNode>) = []
|
|
473
475
|
// pages = ["2", "0", "1", "2", "0"]
|
|
474
476
|
const pages = Array.isArray(children) ? Object.keys(children) : []
|
|
475
477
|
/* 无限循环的时候 */
|
|
476
478
|
if (circular) {
|
|
477
|
-
pages.unshift(
|
|
479
|
+
pages.unshift(totalElements - 1 + '')
|
|
478
480
|
pages.push('0')
|
|
479
481
|
}
|
|
480
482
|
arrElements = pages.map((page, i) => {
|
|
@@ -486,8 +488,7 @@ const _Carouse = forwardRef<HandlerRef<ScrollView & View, CarouseProps>, Carouse
|
|
|
486
488
|
} else if (i === pages.length - 1 && typeof width === 'number') {
|
|
487
489
|
nextMargin && (extraStyle.marginRight = nextMargin)
|
|
488
490
|
}
|
|
489
|
-
|
|
490
|
-
return (<View style={[pageStyle, styles.slide, extraStyle]} key={ 'page' + i}>
|
|
491
|
+
return (<View style={[pageStyle, styles.slide, extraStyle]} key={'page' + i}>
|
|
491
492
|
{wrapChildren(
|
|
492
493
|
{
|
|
493
494
|
children: children[+page]
|
|
@@ -519,6 +520,6 @@ const _Carouse = forwardRef<HandlerRef<ScrollView & View, CarouseProps>, Carouse
|
|
|
519
520
|
</View>)
|
|
520
521
|
})
|
|
521
522
|
|
|
522
|
-
_Carouse.displayName = '
|
|
523
|
+
_Carouse.displayName = 'MpxCarouse'
|
|
523
524
|
|
|
524
525
|
export default _Carouse
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* ✔ disabled
|
|
5
5
|
* ✔ color
|
|
6
6
|
*/
|
|
7
|
-
import { Switch, SwitchProps, ViewStyle, NativeSyntheticEvent
|
|
7
|
+
import { Switch, SwitchProps, ViewStyle, NativeSyntheticEvent } from 'react-native'
|
|
8
8
|
import { useRef, useEffect, forwardRef, JSX, useState, useContext } from 'react'
|
|
9
9
|
import { warn } from '@mpxjs/utils'
|
|
10
10
|
import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
|
|
@@ -111,6 +111,14 @@ const _Switch = forwardRef<HandlerRef<Switch, _SwitchProps>, _SwitchProps>((prop
|
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
return () => {
|
|
116
|
+
if (formValuesMap && props.name) {
|
|
117
|
+
formValuesMap.delete(props.name)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}, [])
|
|
121
|
+
|
|
114
122
|
const innerProps = useInnerProps(props, {
|
|
115
123
|
ref: nodeRef,
|
|
116
124
|
style: { ...normalStyle, ...layoutStyle },
|
|
@@ -144,6 +152,6 @@ const _Switch = forwardRef<HandlerRef<Switch, _SwitchProps>, _SwitchProps>((prop
|
|
|
144
152
|
/>
|
|
145
153
|
})
|
|
146
154
|
|
|
147
|
-
_Switch.displayName = '
|
|
155
|
+
_Switch.displayName = 'MpxSwitch'
|
|
148
156
|
|
|
149
157
|
export default _Switch
|
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
import { View, TextStyle, NativeSyntheticEvent, ViewProps, ImageStyle, ImageResizeMode, StyleSheet, Image, LayoutChangeEvent, Text } from 'react-native'
|
|
8
8
|
import { useRef, useState, useEffect, forwardRef, ReactNode, JSX, Children, cloneElement } from 'react'
|
|
9
9
|
import useInnerProps from './getInnerListeners'
|
|
10
|
+
import Animated from 'react-native-reanimated'
|
|
11
|
+
import useAnimationHooks from './useAnimationHooks'
|
|
12
|
+
import type { AnimationProp } from './useAnimationHooks'
|
|
10
13
|
import { ExtendedViewStyle } from './types/common'
|
|
11
14
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
12
15
|
import { parseUrl, PERCENT_REGEX, splitStyle, splitProps, useTransformStyle, wrapChildren, useLayout } from './utils'
|
|
@@ -14,6 +17,7 @@ import LinearGradient from 'react-native-linear-gradient'
|
|
|
14
17
|
|
|
15
18
|
export interface _ViewProps extends ViewProps {
|
|
16
19
|
style?: ExtendedViewStyle
|
|
20
|
+
animation?: AnimationProp
|
|
17
21
|
children?: ReactNode | ReactNode[]
|
|
18
22
|
'hover-style'?: ExtendedViewStyle
|
|
19
23
|
'hover-start-time'?: number
|
|
@@ -24,6 +28,7 @@ export interface _ViewProps extends ViewProps {
|
|
|
24
28
|
'parent-font-size'?: number
|
|
25
29
|
'parent-width'?: number
|
|
26
30
|
'parent-height'?: number
|
|
31
|
+
'enable-animation'?: boolean
|
|
27
32
|
bindtouchstart?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void
|
|
28
33
|
bindtouchmove?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void
|
|
29
34
|
bindtouchend?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void
|
|
@@ -650,9 +655,11 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
|
|
|
650
655
|
'enable-var': enableVar,
|
|
651
656
|
'external-var-context': externalVarContext,
|
|
652
657
|
'enable-background': enableBackground,
|
|
658
|
+
'enable-animation': enableAnimation,
|
|
653
659
|
'parent-font-size': parentFontSize,
|
|
654
660
|
'parent-width': parentWidth,
|
|
655
|
-
'parent-height': parentHeight
|
|
661
|
+
'parent-height': parentHeight,
|
|
662
|
+
animation
|
|
656
663
|
} = props
|
|
657
664
|
|
|
658
665
|
const [isHover, setIsHover] = useState(false)
|
|
@@ -747,9 +754,10 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
|
|
|
747
754
|
layoutProps
|
|
748
755
|
} = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
|
|
749
756
|
|
|
757
|
+
const viewStyle = Object.assign({}, innerStyle, layoutStyle)
|
|
750
758
|
const innerProps = useInnerProps(props, {
|
|
751
759
|
ref: nodeRef,
|
|
752
|
-
style:
|
|
760
|
+
style: viewStyle,
|
|
753
761
|
...layoutProps,
|
|
754
762
|
...(hoverStyle && {
|
|
755
763
|
bindtouchstart: onTouchStart,
|
|
@@ -764,27 +772,39 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
|
|
|
764
772
|
layoutRef
|
|
765
773
|
})
|
|
766
774
|
|
|
767
|
-
|
|
768
|
-
|
|
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
|
+
const childNode = wrapWithChildren(props, {
|
|
787
|
+
hasVarDec,
|
|
788
|
+
enableBackground: enableBackgroundRef.current,
|
|
789
|
+
textStyle,
|
|
790
|
+
backgroundStyle,
|
|
791
|
+
varContext: varContextRef.current,
|
|
792
|
+
textProps
|
|
793
|
+
})
|
|
794
|
+
return animation?.actions?.length
|
|
795
|
+
? (<Animated.View
|
|
769
796
|
{...innerProps}
|
|
797
|
+
style={finalStyle}
|
|
770
798
|
>
|
|
771
|
-
{
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
backgroundStyle,
|
|
779
|
-
varContext: varContextRef.current,
|
|
780
|
-
textProps
|
|
781
|
-
}
|
|
782
|
-
)
|
|
783
|
-
}
|
|
784
|
-
</View>
|
|
785
|
-
)
|
|
799
|
+
{childNode}
|
|
800
|
+
</Animated.View>)
|
|
801
|
+
: (<View
|
|
802
|
+
{...innerProps}
|
|
803
|
+
>
|
|
804
|
+
{childNode}
|
|
805
|
+
</View>)
|
|
786
806
|
})
|
|
787
807
|
|
|
788
|
-
_View.displayName = '
|
|
808
|
+
_View.displayName = 'MpxView'
|
|
789
809
|
|
|
790
810
|
export default _View
|
|
@@ -47,7 +47,7 @@ interface FormRef {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((props, ref): JSX.Element => {
|
|
50
|
-
const { src, bindmessage = noop, bindload = noop, binderror = noop } = props
|
|
50
|
+
const { src = '', bindmessage = noop, bindload = noop, binderror = noop } = props
|
|
51
51
|
if (props.style) {
|
|
52
52
|
warn('The web-view component does not support the style prop.')
|
|
53
53
|
}
|
|
@@ -162,6 +162,6 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
162
162
|
</Portal>)
|
|
163
163
|
})
|
|
164
164
|
|
|
165
|
-
_WebView.displayName = '
|
|
165
|
+
_WebView.displayName = 'MpxWebview'
|
|
166
166
|
|
|
167
167
|
export default _WebView
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { ViewStyle
|
|
1
|
+
import { ViewStyle } from 'react-native'
|
|
2
|
+
import { FunctionComponent } from 'react'
|
|
2
3
|
|
|
3
4
|
type NumberVal = number | `${number}%`
|
|
4
|
-
type backgroundPositionList = [
|
|
5
|
+
type backgroundPositionList = ['left' | 'right', NumberVal, 'top' | 'bottom', NumberVal] | []
|
|
5
6
|
|
|
6
7
|
export type ExtendedViewStyle = ViewStyle & {
|
|
7
8
|
backgroundImage?: string
|
|
@@ -9,4 +10,9 @@ export type ExtendedViewStyle = ViewStyle & {
|
|
|
9
10
|
borderRadius?: string | number
|
|
10
11
|
backgroundPosition?: backgroundPositionList
|
|
11
12
|
[key: string]: any
|
|
13
|
+
transform?: {[key: string]: number | string}[]
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type ExtendedFunctionComponent = FunctionComponent & {
|
|
17
|
+
isCustomText?: boolean
|
|
12
18
|
}
|