diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 077c0a146a..00ec6a133c 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -8,7 +8,7 @@ jobs: deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: technote-space/get-diff-action@v4 with: PATTERNS: | diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 899278bbd3..f627cf9be5 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -11,12 +11,12 @@ jobs: # lint: # runs-on: ubuntu-latest # steps: -# - uses: actions/checkout@v2 +# - uses: actions/checkout@v4 # - run: npm run lint publish: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - run: | npm i echo "//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}" >> $HOME/.npmrc 2> /dev/null diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 178205991f..ec2bbdae7c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,22 +6,22 @@ jobs: tsc: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - run: npm i && npm run tsc:build lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - run: npm i && npm run lint unit: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Cache node modules id: cache - uses: actions/cache@v2 + uses: actions/cache@v4 env: cache-name: cache-node-modules with: diff --git a/docs-vitepress/guide/platform/rn.md b/docs-vitepress/guide/platform/rn.md index e76a030b4f..af1993169e 100644 --- a/docs-vitepress/guide/platform/rn.md +++ b/docs-vitepress/guide/platform/rn.md @@ -1,5 +1,17 @@ # 跨端输出RN +## 快速使用 RN + +``` bash +# ios +npx mpx-cli-service build --targets=ios +# android +npx mpx-cli-service build --targets=android +# harmony +npx mpx-cli-service build --targets=harmony +``` +> 构建其他平台参考 [快速开始](../basic/start.html) + ## 跨端样式定义 RN 样式属性和 Web/小程序中 CSS 样式属性是相交关系,RN 有一小部分样式属性(比如 tintColor、writingDirection 等等) CSS 不支持,CSS 也有少部分样式属性 RN 不支持(比如 clip-path、animation、transition 等等)。 diff --git a/lerna.json b/lerna.json index 29924965d8..a7745837a2 100644 --- a/lerna.json +++ b/lerna.json @@ -1,3 +1,3 @@ { - "version": "2.10.0" + "version": "2.10.1" } \ No newline at end of file diff --git a/packages/api-proxy/package.json b/packages/api-proxy/package.json index 24e298865e..f31a0b46be 100644 --- a/packages/api-proxy/package.json +++ b/packages/api-proxy/package.json @@ -1,6 +1,6 @@ { "name": "@mpxjs/api-proxy", - "version": "2.10.0", + "version": "2.10.1", "description": "convert miniprogram API at each end", "module": "src/index.js", "types": "@types/index.d.ts", @@ -41,12 +41,12 @@ "axios": "^1.7.3" }, "peerDependencies": { - "@react-native-async-storage/async-storage": "^1.23.1", - "@react-native-community/netinfo": "^11.2.1", - "react-native-device-info": "^10.13.2", - "react-native-get-location": "^4.0.1", - "react-native-haptic-feedback": "^2.3.3", - "react-native-safe-area-context": "^4.10.1" + "@react-native-async-storage/async-storage": "*", + "@react-native-community/netinfo": "*", + "react-native-device-info": "*", + "react-native-get-location": "*", + "react-native-haptic-feedback": "*", + "react-native-safe-area-context": "*" }, "peerDependenciesMeta": { "@react-native-async-storage/async-storage": { diff --git a/packages/api-proxy/src/platform/api/next-tick/index.web.js b/packages/api-proxy/src/platform/api/next-tick/index.web.js index bddf3b5c5e..715ad9ae82 100644 --- a/packages/api-proxy/src/platform/api/next-tick/index.web.js +++ b/packages/api-proxy/src/platform/api/next-tick/index.web.js @@ -16,7 +16,7 @@ function nextTick (cb) { channel.port1.onmessage = cb port.postMessage(1) } else { - setTimeout(cb, 0) + setTimeout(cb) } } diff --git a/packages/core/package.json b/packages/core/package.json index 5b4632524b..773e6b0777 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@mpxjs/core", - "version": "2.10.0", + "version": "2.10.1", "description": "mpx runtime core", "keywords": [ "miniprogram", @@ -24,20 +24,20 @@ "miniprogram-api-typings": "^3.10.0" }, "peerDependencies": { - "@d11/react-native-fast-image": "^8.6.12", + "@d11/react-native-fast-image": "*", "@mpxjs/api-proxy": "^2.9.0", "@mpxjs/store": "^2.9.0", - "@react-navigation/native": "^7.0.14", - "@react-navigation/native-stack": "^7.2.0", + "@react-navigation/native": "*", + "@react-navigation/native-stack": "*", "react": "*", "react-native": "*", - "react-native-gesture-handler": "^2.19.0", - "react-native-linear-gradient": "^2.8.3", - "react-native-reanimated": "^3.15.2", - "react-native-safe-area-context": "^4.14.0", - "react-native-screens": "^4.1.0", - "react-native-video": "^6.9.0", - "react-native-webview": "^13.10.5", + "react-native-gesture-handler": "*", + "react-native-linear-gradient": "*", + "react-native-reanimated": "*", + "react-native-safe-area-context": "*", + "react-native-screens": "*", + "react-native-video": "*", + "react-native-webview": "*", "vue": "^2.7.10", "vue-demi": "^0.14.6", "vue-i18n": "^8.27.2", diff --git a/packages/core/src/observer/scheduler.js b/packages/core/src/observer/scheduler.js index 900083c3d0..ff6f034e41 100644 --- a/packages/core/src/observer/scheduler.js +++ b/packages/core/src/observer/scheduler.js @@ -1,4 +1,4 @@ -import { warn, isArray, callWithErrorHandling, isDev } from '@mpxjs/utils' +import { warn, isArray, callWithErrorHandling, isDev, isReact } from '@mpxjs/utils' import Mpx from '../index' let isFlushing = false @@ -47,6 +47,14 @@ function findInsertionIndex (id) { } export function nextTick (fn) { + if (isReact) { + const p = new Promise((resolve) => { + setTimeout(() => { + resolve(fn && fn.call(this)) + }) + }) + return p + } const p = currentFlushPromise || resolvedPromise return fn ? p.then(this ? fn.bind(this) : fn) : p } diff --git a/packages/fetch/package.json b/packages/fetch/package.json index b0360709a7..f179ec7e87 100644 --- a/packages/fetch/package.json +++ b/packages/fetch/package.json @@ -1,6 +1,6 @@ { "name": "@mpxjs/fetch", - "version": "2.10.0", + "version": "2.10.1", "description": "mpx fetch lib", "author": "donghongping", "license": "Apache-2.0", @@ -29,7 +29,7 @@ "test": "echo \"Error: run tests from root\" && exit 1" }, "dependencies": { - "@mpxjs/api-proxy": "^2.10.0", + "@mpxjs/api-proxy": "^2.10.1", "@mpxjs/utils": "^2.10.0", "path-to-regexp": "^6.2.0" }, diff --git a/packages/webpack-plugin/lib/runtime/components/react/event.config.ts b/packages/webpack-plugin/lib/runtime/components/react/event.config.ts index b1356b7ed9..0cd9bf550b 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/event.config.ts +++ b/packages/webpack-plugin/lib/runtime/components/react/event.config.ts @@ -2,6 +2,8 @@ interface EventConfig { [key: string]: string[]; } +export const TAP_EVENTS = ['bindtap', 'catchtap', 'capture-bindtap', 'capture-catchtap'] + const eventConfigMap: { [key: string]: { bitFlag: string; events: string[] } } = { bindtap: { bitFlag: '0', events: ['onTouchStart', 'onTouchMove', 'onTouchEnd'] }, bindlongpress: { bitFlag: '1', events: ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'] }, diff --git a/packages/webpack-plugin/lib/runtime/components/react/getInnerListeners.ts b/packages/webpack-plugin/lib/runtime/components/react/getInnerListeners.ts index e8800b215e..47d8e030cf 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/getInnerListeners.ts +++ b/packages/webpack-plugin/lib/runtime/components/react/getInnerListeners.ts @@ -1,7 +1,7 @@ import { useRef, useMemo, RefObject } from 'react' import { hasOwn, collectDataset } from '@mpxjs/utils' import { omit, extendObject, useNavigation } from './utils' -import eventConfigMap from './event.config' +import eventConfigMap, { TAP_EVENTS } from './event.config' import { Props, AdditionalProps, @@ -197,12 +197,16 @@ function handleTouchmove (e: NativeTouchEvent, type: 'bubble' | 'capture', ref: const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent handleEmitEvent(currentTouchEvent, 'touchmove', e, propsRef, config, navigation) - checkIsNeedPress(e, type, ref) + if (TAP_EVENTS.some(eventName => propsRef.current[eventName])) { + checkIsNeedPress(e, type, ref) + } } function handleTouchend (e: NativeTouchEvent, type: 'bubble' | 'capture', ref: RefObject, propsRef: Record, config: UseInnerPropsConfig, navigation: Navigation) { // move event may not be triggered - checkIsNeedPress(e, type, ref) + if (TAP_EVENTS.some(eventName => propsRef.current[eventName])) { + checkIsNeedPress(e, type, ref) + } const bubbleTouchEvent = ['catchtouchend', 'bindtouchend'] const bubbleTapEvent = ['catchtap', 'bindtap'] const captureTouchEvent = [ diff --git a/packages/webpack-plugin/lib/template-compiler/compiler.js b/packages/webpack-plugin/lib/template-compiler/compiler.js index c6723292d6..b20ce884de 100644 --- a/packages/webpack-plugin/lib/template-compiler/compiler.js +++ b/packages/webpack-plugin/lib/template-compiler/compiler.js @@ -1832,9 +1832,13 @@ function processRefReact (el, meta) { selectors.push({ prefix: '', selector: `"${refConf.key}"` }) } const selectorsConf = selectors.map(item => `["${item.prefix}", ${item.selector}]`) + const refFnId = forScopes.reduce((preV, curV) => { + return `${preV} + "_" + ${curV.index}` + }, `"ref_fn_${++refId}"`) + addAttrs(el, [{ name: 'ref', - value: `{{ this.__getRefVal('${type}', [${selectorsConf}], 'ref_fn_${++refId}') }}` + value: `{{ this.__getRefVal('${type}', [${selectorsConf}], ${refFnId}) }}` }]) } diff --git a/packages/webpack-plugin/package.json b/packages/webpack-plugin/package.json index 5462585cb9..d4dab6e1cb 100644 --- a/packages/webpack-plugin/package.json +++ b/packages/webpack-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@mpxjs/webpack-plugin", - "version": "2.10.0", + "version": "2.10.1", "description": "mpx compile core", "keywords": [ "mpx" @@ -84,7 +84,7 @@ "devDependencies": { "@ant-design/react-native": "^5.2.2", "@d11/react-native-fast-image": "^8.6.12", - "@mpxjs/api-proxy": "^2.10.0", + "@mpxjs/api-proxy": "^2.10.1", "@types/babel-traverse": "^6.25.4", "@types/babel-types": "^7.0.4", "@types/react": "^18.2.79",