From ad20862f2f4cafda3a78eb67ca2804c192d80838 Mon Sep 17 00:00:00 2001 From: wenwen Date: Mon, 23 Dec 2024 17:07:03 +0800 Subject: [PATCH 1/7] =?UTF-8?q?add=20parseValueFromParentheses=20=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=20translateY(10px)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/webpack-plugin/lib/platform/style/wx/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/webpack-plugin/lib/platform/style/wx/index.js b/packages/webpack-plugin/lib/platform/style/wx/index.js index d28c27947..054ba0542 100644 --- a/packages/webpack-plugin/lib/platform/style/wx/index.js +++ b/packages/webpack-plugin/lib/platform/style/wx/index.js @@ -128,7 +128,7 @@ module.exports = function getSpec ({ warn, error }) { } else if (char === ')') { stack-- if (stack === 0) { - val = values.substring(start, i + 1) + val = values.substring(start + 1, i) } } } From b51a7297a4baf1f6dc72ea248428ef23720b45b9 Mon Sep 17 00:00:00 2001 From: lareinayanyu Date: Mon, 23 Dec 2024 17:15:15 +0800 Subject: [PATCH 2/7] =?UTF-8?q?fix:=20=E4=BA=8B=E4=BB=B6=E9=92=A9=E5=AD=90?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E4=B8=8D=E7=A8=B3=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/runtime/components/react/getInnerListeners.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/webpack-plugin/lib/runtime/components/react/getInnerListeners.ts b/packages/webpack-plugin/lib/runtime/components/react/getInnerListeners.ts index 4a8b5c067..2bd4da644 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/getInnerListeners.ts +++ b/packages/webpack-plugin/lib/runtime/components/react/getInnerListeners.ts @@ -317,11 +317,10 @@ const useInnerProps = ( } } - if (!rawEventKeys.length || config.disableTouch) { - return omit(propsRef.current, removeProps) - } - const events = useMemo(() => { + if (!rawEventKeys.length || config.disableTouch) { + return {} + } const transformedEventKeys = rawEventKeys.reduce((acc: string[], key) => { if (propsRef.current[key]) { return acc.concat(eventConfig[key]) @@ -339,7 +338,7 @@ const useInnerProps = ( }) return events - }, [hashEventKey]) + }, [hashEventKey, config.disableTouch]) return extendObject( {}, From 3f781aa6c31f364e8209179b095b569f1e9f30c7 Mon Sep 17 00:00:00 2001 From: wenwen Date: Mon, 23 Dec 2024 17:28:02 +0800 Subject: [PATCH 3/7] fix Parentheses --- .../lib/runtime/components/react/useAnimationHooks.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/webpack-plugin/lib/runtime/components/react/useAnimationHooks.ts b/packages/webpack-plugin/lib/runtime/components/react/useAnimationHooks.ts index 4dd83152e..f9adad4c5 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/useAnimationHooks.ts +++ b/packages/webpack-plugin/lib/runtime/components/react/useAnimationHooks.ts @@ -125,7 +125,7 @@ const parseValueFromParentheses = (values: string) => { } else if (char === ')') { stack-- if (stack === 0) { - val = values.substring(start, i + 1) + val = values.substring(start + 1, i) } } } From 95ee3e54f54ddf5cad4c04192267fef57698a80c Mon Sep 17 00:00:00 2001 From: wangshunnn Date: Mon, 23 Dec 2024 17:44:41 +0800 Subject: [PATCH 4/7] fix(picker-view): Android config --- .../react/mpx-picker-view-column.tsx | 24 +++++++++++++------ .../components/react/mpx-picker-view.tsx | 2 +- .../lib/runtime/components/react/utils.tsx | 5 +++- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/packages/webpack-plugin/lib/runtime/components/react/mpx-picker-view-column.tsx b/packages/webpack-plugin/lib/runtime/components/react/mpx-picker-view-column.tsx index b09fc3b7f..9ca2fdfcb 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/mpx-picker-view-column.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/mpx-picker-view-column.tsx @@ -1,8 +1,7 @@ import React, { forwardRef, useRef, useState, useMemo, useEffect, useCallback } from 'react' -import { LayoutChangeEvent, NativeScrollEvent, NativeSyntheticEvent, Platform, SafeAreaView, ScrollView, StyleSheet, View } from 'react-native' +import { LayoutChangeEvent, NativeScrollEvent, NativeSyntheticEvent, SafeAreaView, ScrollView, StyleSheet, View } from 'react-native' import Reanimated, { AnimatedRef, useAnimatedRef, useScrollViewOffset } from 'react-native-reanimated' -import { vibrateShort } from '@mpxjs/api-proxy' -import { useTransformStyle, splitStyle, splitProps, useLayout, usePrevious } from './utils' +import { useTransformStyle, splitStyle, splitProps, useLayout, usePrevious, isAndroid } from './utils' import useNodesRef, { HandlerRef } from './useNodesRef' import PickerOverlay from './pickerViewOverlay' import PickerMask from './pickerViewMask' @@ -114,6 +113,7 @@ const _PickerViewColumn = forwardRef, }, [itemRawH, maxIndex]) useEffect(() => { + // console.log('[mpx-picker-view-column], useEffect000 --->', 'columnIndex=', columnIndex, 'initialIndex=', initialIndex, 'prevIndex=', prevIndex, 'activeIndex=', activeIndex.current, 'maxIndex=', maxIndex, 'prevMaxIndex=', prevMaxIndex) if ( !scrollViewRef.current || !itemRawH || @@ -133,7 +133,7 @@ const _PickerViewColumn = forwardRef, y: itemRawH * initialIndex, animated: false }) - }, 0) + }, isAndroid ? 200 : 0) activeIndex.current = initialIndex }, [itemRawH, initialIndex]) @@ -148,9 +148,13 @@ const _PickerViewColumn = forwardRef, } const onScrollViewLayout = (e: LayoutChangeEvent) => { + if (isAndroid) { + return + } + // RN iOS bug: https://github.com/facebook/react-native/issues/36135 const { width } = e.nativeEvent.layout const widthInt = Math.ceil(width) - // console.log('[mpx-picker-view-column], onScrollViewLayout --->', 'columnIndex=', columnIndex, 'widthInt=', widthInt, 'scrollViewWidth=', scrollViewWidth) + // console.log('[mpx-picker-view-column], onScrollViewLayout --->', 'columnIndex=', columnIndex, 'width=', width, 'widthInt=', widthInt, 'scrollViewWidth=', scrollViewWidth) if (widthInt !== scrollViewWidth) { const maxW = maxScrollViewWidth.current if (maxW !== -1 && widthInt > maxW) { @@ -208,7 +212,12 @@ const _PickerViewColumn = forwardRef, } const onScroll = (e: NativeSyntheticEvent) => { - if (Platform.OS === 'android') { + if (isAndroid) { + return + } + // 全局注册的震动触感 hook + const pickerVibrate = global.__mpx.config.rnConfig.pickerVibrate + if (typeof pickerVibrate !== 'function') { return } const { y } = e.nativeEvent.contentOffset @@ -221,7 +230,8 @@ const _PickerViewColumn = forwardRef, index: currentId, y: currentId * itemRawH } - vibrateShort({ type: 'selection' }) + // vibrateShort({ type: 'selection' }) + pickerVibrate() } } } diff --git a/packages/webpack-plugin/lib/runtime/components/react/mpx-picker-view.tsx b/packages/webpack-plugin/lib/runtime/components/react/mpx-picker-view.tsx index dcc82b89e..30ec78b22 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/mpx-picker-view.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/mpx-picker-view.tsx @@ -122,7 +122,7 @@ const _PickerView = forwardRef, PickerViewProp const onInitialChange = (isInvalid: boolean, value: number[]) => { if (isInvalid || !snapActiveValueRef.current || hasDiff(snapActiveValueRef.current, value)) { - console.log('[mpx-picker-view], onInitialChange-1 ===> value=', value) + console.log('[mpx-picker-view], onInitialChange ===> value=', value) const eventData = getCustomEvent( 'change', {}, diff --git a/packages/webpack-plugin/lib/runtime/components/react/utils.tsx b/packages/webpack-plugin/lib/runtime/components/react/utils.tsx index 16ba1f621..46f7378f8 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/utils.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/utils.tsx @@ -1,5 +1,5 @@ import { useEffect, useCallback, useMemo, useRef, ReactNode, ReactElement, isValidElement, useContext, useState, Dispatch, SetStateAction, Children, cloneElement } from 'react' -import { LayoutChangeEvent, TextStyle, ImageProps, Image } from 'react-native' +import { LayoutChangeEvent, TextStyle, ImageProps, Image, Platform } from 'react-native' import { isObject, isFunction, isNumber, hasOwn, diffAndCloneA, error, warn, getFocusedNavigation } from '@mpxjs/utils' import { VarContext, ScrollViewContext } from './context' import { ExpressionParser, parseFunc, ReplaceSource } from './parser' @@ -20,6 +20,9 @@ export const HIDDEN_STYLE = { opacity: 0 } +export const isIOS = Platform.OS === 'ios' +export const isAndroid = Platform.OS === 'android' + const varDecRegExp = /^--.*/ const varUseRegExp = /var\(/ const calcUseRegExp = /calc\(/ From 06dfc2f17238195c214b29abc9630d13298338d8 Mon Sep 17 00:00:00 2001 From: lareinayanyu Date: Mon, 23 Dec 2024 19:30:34 +0800 Subject: [PATCH 5/7] =?UTF-8?q?chore:=20=E4=B8=8B=E7=BA=BFdisableTouch?= =?UTF-8?q?=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/runtime/components/react/getInnerListeners.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/webpack-plugin/lib/runtime/components/react/getInnerListeners.ts b/packages/webpack-plugin/lib/runtime/components/react/getInnerListeners.ts index 2bd4da644..10f0ae130 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/getInnerListeners.ts +++ b/packages/webpack-plugin/lib/runtime/components/react/getInnerListeners.ts @@ -289,7 +289,6 @@ const useInnerProps = ( const eventConfig: { [key: string]: string[] } = {} const config = rawConfig || { layoutRef: { current: {} }, - disableTouch: false, disableTap: false } const removeProps = [ @@ -318,7 +317,7 @@ const useInnerProps = ( } const events = useMemo(() => { - if (!rawEventKeys.length || config.disableTouch) { + if (!rawEventKeys.length) { return {} } const transformedEventKeys = rawEventKeys.reduce((acc: string[], key) => { @@ -338,7 +337,7 @@ const useInnerProps = ( }) return events - }, [hashEventKey, config.disableTouch]) + }, [hashEventKey]) return extendObject( {}, From 48b0ca79f71d909df37758bcbecd52097bd9df6a Mon Sep 17 00:00:00 2001 From: wangshunnn Date: Mon, 23 Dec 2024 19:41:06 +0800 Subject: [PATCH 6/7] fix(picker-view): padding height --- .../components/react/mpx-picker-view-column.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/webpack-plugin/lib/runtime/components/react/mpx-picker-view-column.tsx b/packages/webpack-plugin/lib/runtime/components/react/mpx-picker-view-column.tsx index 9ca2fdfcb..388763139 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/mpx-picker-view-column.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/mpx-picker-view-column.tsx @@ -86,23 +86,23 @@ const _PickerViewColumn = forwardRef, nodeRef: scrollViewRef }) - // console.log('[mpx-picker-view-column], render ---> columnIndex=', columnIndex, 'initialIndex=', initialIndex, 'columnData=', columnData.length) + // console.log('[mpx-picker-view-column], render ---> columnIndex=', columnIndex, 'initialIndex=', initialIndex, 'columnData=', columnData.length, 'pickerH=', pickerH, 'itemRawH=', itemRawH, 'itemHeight=', itemHeight) // const initialOffset = useMemo(() => ({ // x: 0, // y: itemRawH * initialIndex // }), [itemRawH]) + const paddingHeight = useMemo( + () => Math.round((pickerH - itemHeight) / 2), + [pickerH, itemHeight] + ) + const snapToOffsets = useMemo( () => columnData.map((_, i) => i * itemRawH), [columnData, itemRawH] ) - const paddingHeight = useMemo( - () => Math.round((pickerH - itemRawH) / 2), - [pickerH, itemRawH] - ) - const contentContainerStyle = useMemo(() => { return [{ paddingVertical: paddingHeight }] }, [paddingHeight]) @@ -139,7 +139,7 @@ const _PickerViewColumn = forwardRef, const onContentSizeChange = (_w: number, h: number) => { const y = itemRawH * initialIndex - // console.log('[mpx-picker-view-column], onContentSizeChange --->', 'columnIndex=', columnIndex, '_w=', _w, 'h=', h, 'y=', y) + // console.log('[mpx-picker-view-column], onContentSizeChange --->', 'columnIndex=', columnIndex, '_w=', _w, 'h=', h, 'y=', y, 'itemRawH=', itemRawH) if (y <= h) { setTimeout(() => { scrollViewRef.current?.scrollTo({ x: 0, y, animated: false }) From 5858bf782048afd018e1eac0f92078dee81cb2ed Mon Sep 17 00:00:00 2001 From: zhuzhh Date: Mon, 23 Dec 2024 20:11:49 +0800 Subject: [PATCH 7/7] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8DAndroid=E6=9F=90?= =?UTF-8?q?=E4=BA=9B=E6=9C=BA=E5=9E=8Bstatusbar=E7=8A=B6=E6=80=81=E8=A2=AB?= =?UTF-8?q?=E5=85=B6=E4=BB=96=E9=A1=B5=E9=9D=A2=E5=BD=B1=E5=93=8D=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../patch/react/getDefaultOptions.ios.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/core/src/platform/patch/react/getDefaultOptions.ios.js b/packages/core/src/platform/patch/react/getDefaultOptions.ios.js index 02e42f597..89c2e070d 100644 --- a/packages/core/src/platform/patch/react/getDefaultOptions.ios.js +++ b/packages/core/src/platform/patch/react/getDefaultOptions.ios.js @@ -343,6 +343,7 @@ function usePageStatus (navigation, pageId) { }, [navigation]) } +const pageConfigStack = [] export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) { rawOptions = mergeOptions(rawOptions, type, false) const components = Object.assign({}, rawOptions.components, currentInject.getComponents()) @@ -455,12 +456,24 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) { }, headerTintColor: pageConfig.navigationBarTextStyle || 'white' }) - if (__mpx_mode__ === 'android') { - ReactNative.StatusBar.setBarStyle(pageConfig.barStyle || 'dark-content') + + const setStatusBar = (config) => { + ReactNative.StatusBar.setBarStyle(config.barStyle || 'dark-content') ReactNative.StatusBar.setTranslucent(isCustom) // 控制statusbar是否占位 - const color = isCustom ? 'transparent' : pageConfig.statusBarColor + const color = isCustom ? 'transparent' : config.statusBarColor color && ReactNative.StatusBar.setBackgroundColor(color) } + if (__mpx_mode__ === 'android') { + pageConfigStack.push(pageConfig) + setStatusBar(pageConfig) + } + return () => { + if (__mpx_mode__ === 'android') { + pageConfigStack.pop() + const config = pageConfigStack[pageConfigStack.length - 1] || {} + setStatusBar(config) + } + }; }, []) const rootRef = useRef(null)