Skip to content

Commit 9ef2a7a

Browse files
authored
Merge branch 'master' into feat-border-none
2 parents e6481fc + 7de8615 commit 9ef2a7a

File tree

4 files changed

+82
-49
lines changed

4 files changed

+82
-49
lines changed

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/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: 15 additions & 6 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,
@@ -587,7 +596,7 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
587596
'worklet'
588597
if (enableScrollValue.value !== newValue) {
589598
enableScrollValue.value = newValue
590-
runOnJS(setEnableScroll)(newValue)
599+
runOnJS(runOnJSCallback)('setEnableScroll', newValue)
591600
}
592601
}
593602

@@ -600,7 +609,7 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
600609
'worklet'
601610
if (bouncesValue.value !== newValue) {
602611
bouncesValue.value = newValue
603-
runOnJS(setScrollBounces)(newValue)
612+
runOnJS(runOnJSCallback)('setScrollBounces', newValue)
604613
}
605614
}
606615

@@ -649,19 +658,19 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
649658
if ((event.translationY > 0 && translateY.value < refresherThreshold) || event.translationY < 0) {
650659
translateY.value = withTiming(0)
651660
updateScrollState(true)
652-
runOnJS(setRefreshing)(false)
661+
runOnJS(runOnJSCallback)('setRefreshing', false)
653662
} else {
654663
translateY.value = withTiming(refresherHeight.value)
655664
}
656665
} else if (event.translationY >= refresherHeight.value) {
657666
// 触发刷新
658667
translateY.value = withTiming(refresherHeight.value)
659-
runOnJS(onRefresh)()
668+
runOnJS(runOnJSCallback)('onRefresh')
660669
} else {
661670
// 回弹
662671
translateY.value = withTiming(0)
663672
updateScrollState(true)
664-
runOnJS(setRefreshing)(false)
673+
runOnJS(runOnJSCallback)('setRefreshing', false)
665674
}
666675
})
667676
.simultaneousWithExternalGesture(scrollViewRef)

0 commit comments

Comments
 (0)