diff --git a/packages/webpack-plugin/lib/runtime/components/react/mpx-camera.tsx b/packages/webpack-plugin/lib/runtime/components/react/mpx-camera.tsx index 06ae4b8427..bc44407948 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/mpx-camera.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/mpx-camera.tsx @@ -20,7 +20,7 @@ interface CameraProps { flash?: 'auto' | 'on' | 'off' 'frame-size'?: 'small' | 'medium' | 'large' style?: Record - bindstop?: () => void + bindstop?: (event: Record) => void binderror?: (error: { message: string }) => void bindinitdone?: (result: { type: string, data: string }) => void bindscancode?: (result: { type: string, data: string }) => void @@ -83,6 +83,8 @@ function getCameraPermissionCache (pageId: number | undefined) { const _camera = forwardRef, CameraProps>((props: CameraProps, ref): JSX.Element | null => { // eslint-disable-next-line @typescript-eslint/no-var-requires const cameraRef = useRef(null) + const propsRef = useRef(props) + propsRef.current = props const { mode = 'normal', resolution = 'medium', @@ -163,7 +165,7 @@ const _camera = forwardRef, CameraProps>((props: Ca type, scanArea: [parseInt(frame.x) || 0, parseInt(frame.y) || 0, parseInt(frame.width) || 0, parseInt(frame.height) || 0] } - })) + }, propsRef.current)) }) } }) @@ -173,11 +175,11 @@ const _camera = forwardRef, CameraProps>((props: Ca detail: { maxZoom } - })) + }, propsRef.current)) }, [bindinitdone, maxZoom]) const onStopped = useCallback(() => { - bindstop && bindstop() + bindstop && bindstop(getCustomEvent('stop', {}, { layoutRef }, propsRef.current)) }, [bindstop]) const camera: CameraRef = useMemo(() => ({ diff --git a/packages/webpack-plugin/lib/runtime/components/react/mpx-canvas/Image.ts b/packages/webpack-plugin/lib/runtime/components/react/mpx-canvas/Image.ts index e34fa0714c..074dbfecf5 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/mpx-canvas/Image.ts +++ b/packages/webpack-plugin/lib/runtime/components/react/mpx-canvas/Image.ts @@ -13,8 +13,8 @@ export class Image { canvas: any; width: number; height: number; - private _loadListener: any; - private _errorListener: any; + private _removeLoadListener?: () => void; + private _removeErrorListener?: () => void; private _onload: ((...args: any[]) => void); private _onerror: ((...args: any[]) => void); [key: string]: any; @@ -70,12 +70,8 @@ export class Image { set onload (callback: ((...args: any[]) => void)) { this._onload = callback - if (this._loadListener) { - this.canvas.removeMessageListener(this._loadListener) - } - if (callback) { - this._loadListener = this.addEventListener('load', callback) - } + this._removeLoadListener?.() + this._removeLoadListener = callback ? this.addEventListener('load', callback) : undefined } get onload (): ((...args: any[]) => void) { @@ -84,12 +80,8 @@ export class Image { set onerror (callback: ((...args: any[]) => void)) { this._onerror = callback - if (this._errorListener) { - this.canvas.removeMessageListener(this._errorListener) - } - if (callback) { - this._errorListener = this.addEventListener('error', callback) - } + this._removeErrorListener?.() + this._removeErrorListener = callback ? this.addEventListener('error', callback) : undefined } get onerror () : ((...args: any[]) => void) { diff --git a/packages/webpack-plugin/lib/runtime/components/react/mpx-canvas/index.tsx b/packages/webpack-plugin/lib/runtime/components/react/mpx-canvas/index.tsx index b2841d8834..83fca7a3ac 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/mpx-canvas/index.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/mpx-canvas/index.tsx @@ -200,7 +200,10 @@ const _Canvas = forwardRef, CanvasPr } const removeMessageListener = (listener: any) => { - canvasRef.current.listeners.splice(canvasRef.current.listeners.indexOf(listener), 1) + const index = canvasRef.current.listeners.indexOf(listener) + if (index > -1) { + canvasRef.current.listeners.splice(index, 1) + } } const onMessage = useCallback((e: { nativeEvent: { data: string } }) => { @@ -288,22 +291,22 @@ const _Canvas = forwardRef, CanvasPr allowUniversalAccessFromFileURLs: true }) ) + } else { + canvasComponent = createElement(View, innerProps, createElement(WebView, { + ref: (element: WebViewInstance | null) => { + if (canvasRef.current) { + canvasRef.current.webview = element + } + }, + style: [stylesheet.webview, { height, width }], + source: { html }, + originWhitelist: originWhitelist, + onMessage: onMessage, + onLoad: onLoad, + scrollEnabled: false + })) } - canvasComponent = createElement(View, innerProps, createElement(WebView, { - ref: (element: WebViewInstance | null) => { - if (canvasRef.current) { - canvasRef.current.webview = element - } - }, - style: [stylesheet.webview, { height, width }], - source: { html }, - originWhitelist: originWhitelist, - onMessage: onMessage, - onLoad: onLoad, - scrollEnabled: false - })) - if (hasPositionFixed) { canvasComponent = createElement(Portal, null, canvasComponent) } diff --git a/packages/webpack-plugin/lib/runtime/components/react/mpx-checkbox-group.tsx b/packages/webpack-plugin/lib/runtime/components/react/mpx-checkbox-group.tsx index 1e63226338..8579c41254 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/mpx-checkbox-group.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/mpx-checkbox-group.tsx @@ -138,7 +138,7 @@ const CheckboxGroup = forwardRef< bindchange && bindchange( getCustomEvent( - 'tap', + 'change', evt, { layoutRef, diff --git a/packages/webpack-plugin/lib/runtime/components/react/mpx-form.tsx b/packages/webpack-plugin/lib/runtime/components/react/mpx-form.tsx index 7851f6e544..12ad2865bb 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/mpx-form.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/mpx-form.tsx @@ -23,7 +23,7 @@ interface FormProps { value: any } }) => void - bindreset?: () => void + bindreset?: (evt: Record) => void } const _Form = forwardRef, FormProps>((fromProps: FormProps, ref): JSX.Element => { @@ -98,7 +98,7 @@ const _Form = forwardRef, FormProps>((fromProps: For const reset = () => { const { bindreset } = propsRef.current - bindreset && bindreset() + bindreset && bindreset(getCustomEvent('reset', {}, { layoutRef }, propsRef.current)) formValuesMap.forEach(item => item.resetValue()) } return { diff --git a/packages/webpack-plugin/lib/runtime/components/react/mpx-picker/date.tsx b/packages/webpack-plugin/lib/runtime/components/react/mpx-picker/date.tsx index 4508887a9e..643665cef2 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/mpx-picker/date.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/mpx-picker/date.tsx @@ -121,7 +121,7 @@ const valueChanged2Obj = (currentObj: FormatObj, value: number[], limit = 3) => const rangeArr = currentObj.rangeArr if (limit === 3 && (currentValue[0] !== value[0] || currentValue[1] !== value[1])) { - const days = daysInMonth(value[0], value[1] + 1) + const days = daysInMonth(value[0] + START_YEAR, value[1] + 1) rangeArr[2] = days const maxIndex = days.length - 1 if (value[2] > maxIndex) { diff --git a/packages/webpack-plugin/lib/runtime/components/react/mpx-picker/index.tsx b/packages/webpack-plugin/lib/runtime/components/react/mpx-picker/index.tsx index 5118c965cd..10758ad863 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/mpx-picker/index.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/mpx-picker/index.tsx @@ -250,7 +250,7 @@ const Picker = forwardRef, PickerProps>( } const onCancel = () => { - bindcancel?.() + bindcancel?.(getCustomEvent('cancel', {}, { layoutRef }, props)) hide() } diff --git a/packages/webpack-plugin/lib/runtime/components/react/mpx-radio-group.tsx b/packages/webpack-plugin/lib/runtime/components/react/mpx-radio-group.tsx index fc0a69ec03..903c710718 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/mpx-radio-group.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/mpx-radio-group.tsx @@ -118,7 +118,7 @@ const radioGroup = forwardRef< bindchange && bindchange( getCustomEvent( - 'tap', + 'change', evt, { layoutRef, diff --git a/packages/webpack-plugin/lib/runtime/components/react/mpx-sticky-header.tsx b/packages/webpack-plugin/lib/runtime/components/react/mpx-sticky-header.tsx index 86a06de3f1..b82a7dd6f0 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/mpx-sticky-header.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/mpx-sticky-header.tsx @@ -57,7 +57,7 @@ const _StickyHeader = forwardRef, StickyHead const headerTopRef = useRef(0) useEffect(() => { - registerStickyHeader({ key: id, updatePosition }) + registerStickyHeader({ id, updatePosition }) return () => { unregisterStickyHeader(id) } diff --git a/packages/webpack-plugin/lib/runtime/components/react/mpx-video.tsx b/packages/webpack-plugin/lib/runtime/components/react/mpx-video.tsx index 5e5d6dc312..b177b704e8 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/mpx-video.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/mpx-video.tsx @@ -213,7 +213,7 @@ const MpxVideo = forwardRef, VideoProps>((videoProp } function handleEnd () { - bindended!(getCustomEvent('end', {}, { layoutRef }, propsRef.current)) + bindended!(getCustomEvent('ended', {}, { layoutRef }, propsRef.current)) } function handleWaiting ({ isBuffering }: OnBufferData) { @@ -259,7 +259,7 @@ const MpxVideo = forwardRef, VideoProps>((videoProp function handleAndroidControlsVisibilityChange ({ isVisible }: OnControlsVisibilityChange) { bindcontrolstoggle!( - getCustomEvent('progress', + getCustomEvent('controlstoggle', {}, { detail: { @@ -292,7 +292,7 @@ const MpxVideo = forwardRef, VideoProps>((videoProp } function handleError ({ error }: OnVideoErrorData) { - binderror && binderror(getCustomEvent('play', {}, { detail: { errMsg: error.localizedFailureReason }, layoutRef }, propsRef.current)) + binderror && binderror(getCustomEvent('error', {}, { detail: { errMsg: error.localizedFailureReason }, layoutRef }, propsRef.current)) } function play () {