From 5dab794407a0ac0249fca572a5fd34283de159d6 Mon Sep 17 00:00:00 2001 From: tony chen Date: Fri, 1 Nov 2024 15:23:22 +0800 Subject: [PATCH] fix: build & test error --- packages/taro-components-rn/package.json | 2 +- .../src/components/Camera/index.tsx | 32 ++++++++--------- .../__snapshots__/scanCode.test.tsx.snap | 18 ++++------ packages/taro-rn/package.json | 2 +- packages/taro-rn/src/lib/openUrl/index.d.ts | 25 ------------- packages/taro-rn/src/lib/openUrl/index.ts | 17 +++++++-- packages/taro-rn/src/lib/scanCode/index.tsx | 16 ++++----- packages/taro-rn/types/index.d.ts | 1 - pnpm-lock.yaml | 35 ++++++++++++++++--- 9 files changed, 78 insertions(+), 70 deletions(-) delete mode 100644 packages/taro-rn/src/lib/openUrl/index.d.ts diff --git a/packages/taro-components-rn/package.json b/packages/taro-components-rn/package.json index b43483a916b1..46b69baf9c2d 100644 --- a/packages/taro-components-rn/package.json +++ b/packages/taro-components-rn/package.json @@ -52,7 +52,7 @@ "expo-av": "~13.10.6", "expo-camera": "~14.1.3", "expo-module-scripts": "^3.5.1", - "jest-expo": "^51.0.1", + "jest-expo": "~50.0.3", "react": "^18.2.0", "react-native": "^0.73.1", "react-native-pager-view": "6.2.3", diff --git a/packages/taro-components-rn/src/components/Camera/index.tsx b/packages/taro-components-rn/src/components/Camera/index.tsx index eb8976f5eb51..5759d5afdad8 100644 --- a/packages/taro-components-rn/src/components/Camera/index.tsx +++ b/packages/taro-components-rn/src/components/Camera/index.tsx @@ -1,5 +1,4 @@ -import { BarcodeScanningResult, BarcodeType, Camera, CameraMountError, CameraView, PermissionStatus } from 'expo-camera' -import { CameraType } from 'expo-camera/build/legacy/Camera.types' +import { BarCodeScanningResult, Camera, CameraMountError, CameraType, PermissionStatus } from 'expo-camera' import React, { Component } from 'react' import Text from '../Text' @@ -15,12 +14,12 @@ export class _Camera extends Component { } } - expoCameraRef = React.createRef() + expoCameraRef = React.createRef() async componentDidMount(): Promise { const permission = await Camera.requestCameraPermissionsAsync() this.setState({ - hasPermission: permission?.status === PermissionStatus.GRANTED + hasPermission: permission?.status === PermissionStatus.GRANTED, }) } @@ -34,14 +33,15 @@ export class _Camera extends Component { this.props.onInitDone && this.props.onInitDone(event) } - onScanCode = (event: BarcodeScanningResult): void => { + onScanCode = (event: BarCodeScanningResult): void => { const { data } = event - this.props.onScanCode && this.props.onScanCode({ - detail: { - result: data - }, - ...event - } as any) + this.props.onScanCode && + this.props.onScanCode({ + detail: { + result: data, + }, + ...event, + } as any) } render(): JSX.Element { @@ -59,16 +59,16 @@ export class _Camera extends Component { mode === 'scanCode' ? { barCodeScannerSettings: { - barCodeTypes: ['qr'] as BarcodeType[] + barCodeTypes: ['qr'], }, - onBarCodeScanned: this.onScanCode + onBarCodeScanned: this.onScanCode, } : {} return ( - void - /** 接口调用失败的回调函数 */ - fail?: (res: TaroGeneral.CallbackResult) => void - /** 接口调用成功的回调函数 */ - success?: (res: TaroGeneral.CallbackResult) => void - } - } - - /** - * 由于 Expo 不支持原生的 SDK,所以无法通过集成原生的 SDK 的方式使用微信/支付宝支付。 - * 所以 RN 端提供了 `Taro.openUrl({url:''})`的 API 打开手机浏览器,然后走 [手机网站支付](https://docs.open.alipay.com/203/105288/) 的流程。 - * @param {Object} opts - * @param {string} [opts.url] 跳转链接 - * @param {function} [opts.success] 接口调用成功的回调函数 - * @param {function} [opts.fail] 接口调用失败的回调函数 - * @param {function} [opts.complete] 接口调用结束的回调函数(调用成功、失败都会执行) - */ - function openUrl(opts: Taro.OpenUrl.Option): Promise -} diff --git a/packages/taro-rn/src/lib/openUrl/index.ts b/packages/taro-rn/src/lib/openUrl/index.ts index cd37c9319f79..4f783002a98b 100644 --- a/packages/taro-rn/src/lib/openUrl/index.ts +++ b/packages/taro-rn/src/lib/openUrl/index.ts @@ -2,8 +2,19 @@ import { Linking } from 'react-native' import { errorHandler, successHandler } from '../../utils' -export async function openUrl (opts: Taro.OpenUrl.Option): Promise { - const { url, success, fail, complete } = opts || {} as Taro.OpenUrl.Option +interface Option { + /** 跳转链接 */ + url: string + /** 接口调用结束的回调函数(调用成功、失败都会执行) */ + complete?: (res: TaroGeneral.CallbackResult) => void + /** 接口调用失败的回调函数 */ + fail?: (res: TaroGeneral.CallbackResult) => void + /** 接口调用成功的回调函数 */ + success?: (res: TaroGeneral.CallbackResult) => void +} + +export async function openUrl(opts: Option): Promise { + const { url, success, fail, complete } = opts || {} const res: any = { errMsg: 'openUrl:ok' } const isSupport = await Linking.canOpenURL(url) @@ -17,5 +28,5 @@ export async function openUrl (opts: Taro.OpenUrl.Option): Promise { } export default { - openUrl + openUrl, } diff --git a/packages/taro-rn/src/lib/scanCode/index.tsx b/packages/taro-rn/src/lib/scanCode/index.tsx index e6d700652147..c846ff86394e 100644 --- a/packages/taro-rn/src/lib/scanCode/index.tsx +++ b/packages/taro-rn/src/lib/scanCode/index.tsx @@ -1,5 +1,5 @@ import { BarCodeScanner, requestPermissionsAsync } from 'expo-barcode-scanner' -import { BarcodeType, CameraView } from 'expo-camera' +import { Camera } from 'expo-camera' import React from 'react' import { BackHandler, Dimensions, Image, Platform, StatusBar, StyleSheet, TouchableOpacity, View } from 'react-native' import RootSiblings from 'react-native-root-siblings' @@ -48,8 +48,8 @@ function findKey (value:string, data, compare = (a, b) => a === b):string { const { width, height } = Dimensions.get('screen') -function getBarCodeTypes(types:string[]): BarcodeType[] { - const result: BarcodeType[] = [] +function getBarCodeTypes(types:string[]): string[] { + const result: string[] = [] for (const t of types) { result.push(...typeMap[t].map(type => { @@ -158,13 +158,13 @@ export async function scanCode(option: Taro.scanCode.Option = {}): Promise { scannerView = new RootSiblings( (