Skip to content

Commit 4dda86f

Browse files
authored
Merge branch 'master' into feat-setup-getOpenerEventChannel
2 parents 0895d19 + 9953b01 commit 4dda86f

File tree

7 files changed

+149
-85
lines changed

7 files changed

+149
-85
lines changed

packages/core/src/core/proxy.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,11 +502,19 @@ export default class MpxProxy {
502502
const hooks = this.hooks[hookName] || []
503503
let result
504504
if (isFunction(hook) && !hooksOnly) {
505+
const setContext = hookName !== BEFORECREATE
506+
if (setContext) {
507+
setCurrentInstance(this)
508+
}
505509
result = callWithErrorHandling(hook.bind(this.target), this, `${hookName} hook`, params)
510+
if (setContext) {
511+
unsetCurrentInstance()
512+
}
506513
}
507514
hooks.forEach((hook) => {
508515
result = params ? hook(...params) : hook()
509516
})
517+
510518
return result
511519
}
512520

packages/webpack-plugin/lib/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,6 +1726,23 @@ class MpxWebpackPlugin {
17261726
source.add('// inject pageconfigmap for screen\n' +
17271727
'var context = (function() { return this })() || Function("return this")();\n')
17281728
source.add(`context.__mpxPageConfigsMap = ${JSON.stringify(mpx.pageConfigsMap)};\n`)
1729+
1730+
if (process.env.NODE_ENV !== 'production') {
1731+
source.add(`
1732+
${globalObject}.__mpxClearAsyncChunkCache = ${globalObject}.__mpxClearAsyncChunkCache || function (ids) {
1733+
ids = JSON.stringify(ids)
1734+
var arr = ${globalObject}['${chunkLoadingGlobal}'] || []
1735+
for (var i = arr.length - 1; i >= 0; i--) {
1736+
if (JSON.stringify(arr[i][0]) === ids) {
1737+
arr.splice(i, 1)
1738+
}
1739+
}
1740+
};\n`)
1741+
}
1742+
} else {
1743+
if (process.env.NODE_ENV !== 'production') {
1744+
source.add(`${globalObject}.__mpxClearAsyncChunkCache && ${globalObject}.__mpxClearAsyncChunkCache(${JSON.stringify(chunk.ids)});\n`)
1745+
}
17291746
}
17301747
source.add(originalSource)
17311748
compilation.assets[chunkFile] = source
@@ -1825,6 +1842,7 @@ try {
18251842

18261843
compilation.chunkGroups.forEach((chunkGroup) => {
18271844
if (!chunkGroup.isInitial()) {
1845+
isReact(mpx.mode) && chunkGroup.chunks.forEach((chunk) => processChunk(chunk, false, []))
18281846
return
18291847
}
18301848

packages/webpack-plugin/lib/platform/style/wx/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,17 @@ module.exports = function getSpec ({ warn, error }) {
547547
// })
548548
// return cssMap
549549
// }
550+
const formatBorder = ({ prop, value, selector }, { mode }) => {
551+
value = value.trim()
552+
if (value === 'none') {
553+
return {
554+
prop: 'borderWidth',
555+
value: 0
556+
}
557+
} else {
558+
return formatAbbreviation({ prop, value, selector }, { mode })
559+
}
560+
}
550561

551562
return {
552563
supportedModes: ['ios', 'android', 'harmony'],
@@ -593,6 +604,12 @@ module.exports = function getSpec ({ warn, error }) {
593604
// android: formatBoxShadow,
594605
// harmony: formatBoxShadow
595606
// },
607+
{
608+
test: 'border',
609+
ios: formatBorder,
610+
android: formatBorder,
611+
harmony: formatBorder
612+
},
596613
// 通用的简写格式匹配
597614
{
598615
test: new RegExp('^(' + Object.keys(AbbreviationMap).join('|') + ')$'),

packages/webpack-plugin/lib/runtime/components/react/mpx-movable-view.tsx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@ import { StyleSheet, View, LayoutChangeEvent } from 'react-native'
2222
import useInnerProps, { getCustomEvent } from './getInnerListeners'
2323
import useNodesRef, { HandlerRef } from './useNodesRef'
2424
import { MovableAreaContext } from './context'
25-
import { useTransformStyle, splitProps, splitStyle, HIDDEN_STYLE, wrapChildren, GestureHandler, flatGesture, extendObject, omit, useNavigation } from './utils'
25+
import { useTransformStyle, splitProps, splitStyle, HIDDEN_STYLE, wrapChildren, GestureHandler, flatGesture, extendObject, omit, useNavigation, useRunOnJSCallback } from './utils'
2626
import { GestureDetector, Gesture, GestureTouchEvent, GestureStateChangeEvent, PanGestureHandlerEventPayload, PanGesture } from 'react-native-gesture-handler'
2727
import Animated, {
2828
useSharedValue,
2929
useAnimatedStyle,
3030
withDecay,
3131
runOnJS,
3232
runOnUI,
33-
useAnimatedReaction,
3433
withSpring
3534
} from 'react-native-reanimated'
3635
import { collectDataset, noop } from '@mpxjs/utils'
@@ -87,7 +86,6 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
8786
const layoutRef = useRef<any>({})
8887
const changeSource = useRef<any>('')
8988
const hasLayoutRef = useRef(false)
90-
9189
const propsRef = useRef<any>({})
9290
propsRef.current = (props || {}) as MovableViewProps
9391

@@ -208,7 +206,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
208206
const now = Date.now()
209207
if (now - lastChangeTime.value >= changeThrottleTime) {
210208
lastChangeTime.value = now
211-
runOnJS(handleTriggerChange)({ x, y, type })
209+
runOnJS(runOnJSCallback)('handleTriggerChange', { x, y, type })
212210
}
213211
}, [changeThrottleTime])
214212

@@ -233,7 +231,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
233231
: newY
234232
}
235233
if (bindchange) {
236-
runOnJS(handleTriggerChange)({
234+
runOnJS(runOnJSCallback)('handleTriggerChange', {
237235
x: newX,
238236
y: newY,
239237
type: 'setData'
@@ -408,13 +406,21 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
408406
catchtouchend && catchtouchend(e)
409407
}
410408

409+
const runOnJSCallbackRef = useRef({
410+
handleTriggerChange,
411+
triggerStartOnJS,
412+
triggerMoveOnJS,
413+
triggerEndOnJS
414+
})
415+
const runOnJSCallback = useRunOnJSCallback(runOnJSCallbackRef)
416+
411417
const gesture = useMemo(() => {
412418
const handleTriggerMove = (e: GestureTouchEvent) => {
413419
'worklet'
414420
const hasTouchmove = !!bindhtouchmove || !!bindvtouchmove || !!bindtouchmove
415421
const hasCatchTouchmove = !!catchhtouchmove || !!catchvtouchmove || !!catchtouchmove
416422
if (hasTouchmove || hasCatchTouchmove) {
417-
runOnJS(triggerMoveOnJS)({
423+
runOnJS(runOnJSCallback)('triggerMoveOnJS', {
418424
e,
419425
touchEvent: touchEvent.value,
420426
hasTouchmove,
@@ -433,7 +439,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
433439
y: changedTouches.y
434440
}
435441
if (bindtouchstart || catchtouchstart) {
436-
runOnJS(triggerStartOnJS)({ e })
442+
runOnJS(runOnJSCallback)('triggerStartOnJS', { e })
437443
}
438444
})
439445
.onStart(() => {
@@ -487,7 +493,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
487493
isFirstTouch.value = true
488494
isMoving.value = false
489495
if (bindtouchend || catchtouchend) {
490-
runOnJS(triggerEndOnJS)({ e })
496+
runOnJS(runOnJSCallback)('triggerEndOnJS', { e })
491497
}
492498
})
493499
.onEnd((e: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => {
@@ -515,7 +521,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
515521
: y
516522
}
517523
if (bindchange) {
518-
runOnJS(handleTriggerChange)({
524+
runOnJS(runOnJSCallback)('handleTriggerChange', {
519525
x,
520526
y
521527
})
@@ -532,7 +538,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
532538
}, () => {
533539
xInertialMotion.value = false
534540
if (bindchange) {
535-
runOnJS(handleTriggerChange)({
541+
runOnJS(runOnJSCallback)('handleTriggerChange', {
536542
x: offsetX.value,
537543
y: offsetY.value
538544
})
@@ -548,7 +554,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
548554
}, () => {
549555
yInertialMotion.value = false
550556
if (bindchange) {
551-
runOnJS(handleTriggerChange)({
557+
runOnJS(runOnJSCallback)('handleTriggerChange', {
552558
x: offsetX.value,
553559
y: offsetY.value
554560
})

packages/webpack-plugin/lib/runtime/components/react/mpx-scroll-view.tsx

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import Animated, { useSharedValue, withTiming, useAnimatedStyle, runOnJS } from
3838
import { warn, hasOwn } from '@mpxjs/utils'
3939
import useInnerProps, { getCustomEvent } from './getInnerListeners'
4040
import useNodesRef, { HandlerRef } from './useNodesRef'
41-
import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren, extendObject, flatGesture, GestureHandler, HIDDEN_STYLE } from './utils'
41+
import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren, extendObject, flatGesture, GestureHandler, HIDDEN_STYLE, useRunOnJSCallback } from './utils'
4242
import { IntersectionObserverContext, ScrollViewContext } from './context'
4343
import Portal from './mpx-portal'
4444

@@ -210,6 +210,15 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
210210
const { textStyle, innerStyle = {} } = splitStyle(normalStyle)
211211

212212
const scrollViewRef = useRef<ScrollView>(null)
213+
214+
const runOnJSCallbackRef = useRef({
215+
setEnableScroll,
216+
setScrollBounces,
217+
setRefreshing,
218+
onRefresh
219+
})
220+
const runOnJSCallback = useRunOnJSCallback(runOnJSCallbackRef)
221+
213222
useNodesRef(props, ref, scrollViewRef, {
214223
style: normalStyle,
215224
scrollOffset: scrollOptions,
@@ -446,22 +455,6 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
446455
}
447456
}
448457

449-
function onScrollTouchStart (e: NativeSyntheticEvent<TouchEvent>) {
450-
const { bindtouchstart } = props
451-
bindtouchstart && bindtouchstart(e)
452-
if (enhanced) {
453-
binddragstart &&
454-
binddragstart(
455-
getCustomEvent('dragstart', e, {
456-
detail: {
457-
scrollLeft: scrollOptions.current.scrollLeft,
458-
scrollTop: scrollOptions.current.scrollTop
459-
},
460-
layoutRef
461-
}, props)
462-
)
463-
}
464-
}
465458
function onScrollTouchMove (e: NativeSyntheticEvent<TouchEvent>) {
466459
bindtouchmove && bindtouchmove(e)
467460
if (enhanced) {
@@ -478,22 +471,6 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
478471
}
479472
}
480473

481-
function onScrollTouchEnd (e: NativeSyntheticEvent<TouchEvent>) {
482-
bindtouchend && bindtouchend(e)
483-
if (enhanced) {
484-
binddragend &&
485-
binddragend(
486-
getCustomEvent('dragend', e, {
487-
detail: {
488-
scrollLeft: scrollOptions.current.scrollLeft || 0,
489-
scrollTop: scrollOptions.current.scrollTop || 0
490-
},
491-
layoutRef
492-
}, props)
493-
)
494-
}
495-
}
496-
497474
function onScrollDrag (e: NativeSyntheticEvent<NativeScrollEvent>) {
498475
const { x: scrollLeft, y: scrollTop } = e.nativeEvent.contentOffset
499476
updateScrollOptions(e, { scrollLeft, scrollTop })
@@ -514,6 +491,35 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
514491
hasCallScrollToLower.current = false
515492
hasCallScrollToUpper.current = false
516493
onScrollDrag(e)
494+
if (enhanced) {
495+
binddragstart &&
496+
binddragstart(
497+
getCustomEvent('dragstart', e, {
498+
detail: {
499+
scrollLeft: scrollOptions.current.scrollLeft,
500+
scrollTop: scrollOptions.current.scrollTop
501+
},
502+
layoutRef
503+
}, props)
504+
)
505+
}
506+
}
507+
508+
function onScrollDragEnd (e: NativeSyntheticEvent<NativeScrollEvent>) {
509+
onScrollDrag(e)
510+
if (enhanced) {
511+
// 安卓上如果触发了默认的下拉刷新,binddragend可能不触发,只会触发 binddragstart
512+
binddragend &&
513+
binddragend(
514+
getCustomEvent('dragend', e, {
515+
detail: {
516+
scrollLeft: scrollOptions.current.scrollLeft || 0,
517+
scrollTop: scrollOptions.current.scrollTop || 0
518+
},
519+
layoutRef
520+
}, props)
521+
)
522+
}
517523
}
518524

519525
// 处理刷新
@@ -587,7 +593,7 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
587593
'worklet'
588594
if (enableScrollValue.value !== newValue) {
589595
enableScrollValue.value = newValue
590-
runOnJS(setEnableScroll)(newValue)
596+
runOnJS(runOnJSCallback)('setEnableScroll', newValue)
591597
}
592598
}
593599

@@ -600,7 +606,7 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
600606
'worklet'
601607
if (bouncesValue.value !== newValue) {
602608
bouncesValue.value = newValue
603-
runOnJS(setScrollBounces)(newValue)
609+
runOnJS(runOnJSCallback)('setScrollBounces', newValue)
604610
}
605611
}
606612

@@ -649,19 +655,19 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
649655
if ((event.translationY > 0 && translateY.value < refresherThreshold) || event.translationY < 0) {
650656
translateY.value = withTiming(0)
651657
updateScrollState(true)
652-
runOnJS(setRefreshing)(false)
658+
runOnJS(runOnJSCallback)('setRefreshing', false)
653659
} else {
654660
translateY.value = withTiming(refresherHeight.value)
655661
}
656662
} else if (event.translationY >= refresherHeight.value) {
657663
// 触发刷新
658664
translateY.value = withTiming(refresherHeight.value)
659-
runOnJS(onRefresh)()
665+
runOnJS(runOnJSCallback)('onRefresh')
660666
} else {
661667
// 回弹
662668
translateY.value = withTiming(0)
663669
updateScrollState(true)
664-
runOnJS(setRefreshing)(false)
670+
runOnJS(runOnJSCallback)('setRefreshing', false)
665671
}
666672
})
667673
.simultaneousWithExternalGesture(scrollViewRef)
@@ -686,11 +692,9 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
686692
ref: scrollViewRef,
687693
onScroll: enableSticky ? scrollHandler : onScroll,
688694
onContentSizeChange: onContentSizeChange,
689-
bindtouchstart: ((enhanced && binddragstart) || bindtouchstart) && onScrollTouchStart,
690695
bindtouchmove: ((enhanced && binddragging) || bindtouchmove) && onScrollTouchMove,
691-
bindtouchend: ((enhanced && binddragend) || bindtouchend) && onScrollTouchEnd,
692696
onScrollBeginDrag: onScrollDragStart,
693-
onScrollEndDrag: onScrollDrag,
697+
onScrollEndDrag: onScrollDragEnd,
694698
onMomentumScrollEnd: onScrollEnd
695699
},
696700
(simultaneousHandlers ? { simultaneousHandlers } : {}),

0 commit comments

Comments
 (0)