Skip to content

Commit

Permalink
fix: build & test error
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiqingchen committed Nov 1, 2024
1 parent 90492cb commit 5dab794
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 70 deletions.
2 changes: 1 addition & 1 deletion packages/taro-components-rn/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
32 changes: 16 additions & 16 deletions packages/taro-components-rn/src/components/Camera/index.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -15,12 +14,12 @@ export class _Camera extends Component<CameraProps, CameraState> {
}
}

expoCameraRef = React.createRef<CameraView>()
expoCameraRef = React.createRef<Camera>()

async componentDidMount(): Promise<void> {
const permission = await Camera.requestCameraPermissionsAsync()
this.setState({
hasPermission: permission?.status === PermissionStatus.GRANTED
hasPermission: permission?.status === PermissionStatus.GRANTED,
})
}

Expand All @@ -34,14 +33,15 @@ export class _Camera extends Component<CameraProps, CameraState> {
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 {
Expand All @@ -59,16 +59,16 @@ export class _Camera extends Component<CameraProps, CameraState> {
mode === 'scanCode'
? {
barCodeScannerSettings: {
barCodeTypes: ['qr'] as BarcodeType[]
barCodeTypes: ['qr'],
},
onBarCodeScanned: this.onScanCode
onBarCodeScanned: this.onScanCode,
}
: {}
return (
<CameraView
<Camera
ref={this.expoCameraRef}
facing={type}
flash={flash}
type={type}
flashMode={flash}
onMountError={this.onError}
onCameraReady={this.onInitDone}
{...barCodeScannerSettings}
Expand Down
18 changes: 7 additions & 11 deletions packages/taro-rn/__tests__/__snapshots__/scanCode.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,17 @@ exports[`scanCode should render scanCode success 1`] = `
}
>
<ViewManagerAdapter_ExpoCamera
autoFocus="off"
barcodeScannerEnabled={true}
barcodeScannerSettings={
barCodeScannerEnabled={true}
barCodeScannerSettings={
{
"barcodeTypes": [],
"barCodeTypes": [],
}
}
enableTorch={false}
facing="back"
flash="off"
flashMode="off"
mode="picture"
mute={false}
onBarcodeScanned={[Function]}
faceDetectorSettings={{}}
focusDepth={0}
onBarCodeScanned={[Function]}
onCameraReady={[Function]}
onFacesDetected={[Function]}
onMountError={[Function]}
onPictureSaved={[Function]}
onResponsiveOrientationChanged={[Function]}
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-rn/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"expo-keep-awake": "~12.8.2",
"expo-location": "~16.5.5",
"expo-sensors": "~12.9.1",
"jest-expo": "^51.0.1",
"jest-expo": "~50.0.3",
"mock-socket": "^7.1.0",
"react": "^18.2.0",
"react-native": "^0.73.1",
Expand Down
25 changes: 0 additions & 25 deletions packages/taro-rn/src/lib/openUrl/index.d.ts

This file was deleted.

17 changes: 14 additions & 3 deletions packages/taro-rn/src/lib/openUrl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,19 @@ import { Linking } from 'react-native'

import { errorHandler, successHandler } from '../../utils'

export async function openUrl <T>(opts: Taro.OpenUrl.Option): Promise<T> {
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<T>(opts: Option): Promise<T> {
const { url, success, fail, complete } = opts || {}
const res: any = { errMsg: 'openUrl:ok' }

const isSupport = await Linking.canOpenURL(url)
Expand All @@ -17,5 +28,5 @@ export async function openUrl <T>(opts: Taro.OpenUrl.Option): Promise<T> {
}

export default {
openUrl
openUrl,
}
16 changes: 8 additions & 8 deletions packages/taro-rn/src/lib/scanCode/index.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -158,13 +158,13 @@ export async function scanCode(option: Taro.scanCode.Option = {}): Promise<Taro.
complete?.(res)
return Promise.reject(res)
}
const barcodeTypes = getBarCodeTypes(scanType)
const barCodeTypes = getBarCodeTypes(scanType)
return new Promise((resolve, reject) => {
scannerView = new RootSiblings(
(<View style={[styles.container]}>
<StatusBar backgroundColor="rgba(0, 0, 0, 0)" translucent hidden={Platform.OS === 'ios'} />
<CameraView
onBarcodeScanned={({ type, data }: {type: string, data: string}) => {
<Camera
onBarCodeScanned={({ type, data }: {type: string, data: string}) => {
const res = {
charSet: 'UTF-8', // todo
path: '', // todo
Expand All @@ -178,8 +178,8 @@ export async function scanCode(option: Taro.scanCode.Option = {}): Promise<Taro.
hide(scannerView)
resolve(res)
}}
barcodeScannerSettings={{
barcodeTypes,
barCodeScannerSettings={{
barCodeTypes,
}}
style={{ width, height }}
/>
Expand Down
1 change: 0 additions & 1 deletion packages/taro-rn/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
*/

/// <reference types='@tarojs/taro' />
/// <reference path='../src/lib/openUrl/index.d.ts' />

export = Taro
35 changes: 31 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5dab794

Please sign in to comment.