Skip to content

Commit

Permalink
Merge branch 'feat/react-native-oh' of https://github.com/wuba/taro-r…
Browse files Browse the repository at this point in the history
…eact-native into feat/react-native-oh
  • Loading branch information
jumiao committed Mar 22, 2024
2 parents f37a2f3 + 8804a69 commit a48c141
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 39 deletions.
49 changes: 49 additions & 0 deletions packages/taro-components-rn/dep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const { parseDependencyTree } = require('dpdm')
const { peerDependencies } = require('./package.json')

const hiddenDependenciesMap = {
'@ant-design/react-native/lib/picker': ['@react-native-picker/picker']
}

const componentReg = /^src\/components\/(\w+)\/index.tsx$/

function parseDependencyCircular(dep = [], tree = {}) {
dep.forEach(d => {
const item = tree[d.id]
if (item) {
dep = dep.concat(parseDependencyCircular(item, tree))
}
})
return dep
}

parseDependencyTree('./src/index.ts', {}).then((tree) => {
const result = {}
Object.keys(tree).map(key => {
const match = key.match(componentReg)
if (match) {
const name = match[1]
parseDependencyCircular(tree[key], tree).map(dependency => {
const dep = dependency.id
if (dep) {
[...Object.keys(peerDependencies), ...Object.keys(hiddenDependenciesMap)].forEach(value => {
if (dep.match(`node_modules/${value}`)) {
result[name] = result[name] || new Set()
if (hiddenDependenciesMap[value]) {
hiddenDependenciesMap[value].forEach(value => {
const showName = peerDependencies[value] ? `${value}@${peerDependencies[value]}` : value
result[name].add(showName)
})
} else {
const showName = peerDependencies[value] ? `${value}@${peerDependencies[value]}` : value
result[name].add(showName)
}
}
})
}
})
}
})
console.log(result)
})
3 changes: 2 additions & 1 deletion packages/taro-components-rn/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@
"devDependencies": {
"@babel/core": "^7.14.5",
"@babel/preset-env": "^7.14.5",
"@react-native/babel-preset": "^0.73.18",
"@react-native-camera-roll/camera-roll": "~7.2.0",
"@react-native-community/segmented-control": "^2.2.2",
"@react-native/babel-preset": "^0.73.18",
"@testing-library/jest-native": "^5.4.2",
"@testing-library/react-native": "^12.4.1",
"dpdm": "^3.14.0",
"expo": "~50.0.2",
"jest": "^29.3.1",
"jest-cli": "^29.3.1",
Expand Down
49 changes: 49 additions & 0 deletions packages/taro-rn/dep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const { parseDependencyTree } = require('dpdm')
const { peerDependencies } = require('./package.json')

const hiddenDependenciesMap = {
'@ant-design/react-native/lib/picker': ['@react-native-picker/picker']
}

const componentReg = /^src\/lib\/(\w+)\/index.tsx?$/

function parseDependencyCircular(dep = [], tree = {}) {
dep.forEach(d => {
const item = tree[d.id]
if (item) {
dep = dep.concat(parseDependencyCircular(item, tree))
}
})
return dep
}

parseDependencyTree('./src/lib/index.ts', {}).then((tree) => {
const result = {}
Object.keys(tree).map(key => {
const match = key.match(componentReg)
if (match) {
const name = match[1]
parseDependencyCircular(tree[key], tree).map(dependency => {
const dep = dependency.id
if (dep) {
[...Object.keys(peerDependencies), ...Object.keys(hiddenDependenciesMap)].forEach(value => {
if (dep.match(`node_modules/${value}`)) {
result[name] = result[name] || new Set()
if (hiddenDependenciesMap[value]) {
hiddenDependenciesMap[value].forEach(value => {
const showName = peerDependencies[value] ? `${value}@${peerDependencies[value]}` : value
result[name].add(showName)
})
} else {
const showName = peerDependencies[value] ? `${value}@${peerDependencies[value]}` : value
result[name].add(showName)
}
}
})
}
})
}
})
console.log(result)
})
1 change: 1 addition & 0 deletions packages/taro-rn/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"@testing-library/jest-native": "^5.4.2",
"@testing-library/react-native": "^12.4.1",
"@types/jest": "^27.4.1",
"dpdm": "^3.14.0",
"expo": "~50.0.2",
"fbjs-scripts": "^3.0.1",
"jest": "^29.3.1",
Expand Down
10 changes: 7 additions & 3 deletions packages/taro-rn/src/lib/getLocation/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import Geolocation from '@react-native-community/geolocation'
import { requestForegroundPermissionsAsync } from 'expo-location'
import { errorHandler } from '../../utils'

export async function getLocation(opts: Taro.getLocation.Option = {}): Promise<Taro.getLocation.SuccessCallbackResult> {
const { isHighAccuracy = false, highAccuracyExpireTime = 3000, success, fail, complete } = opts

const requestAuthorization = () => {
return new Promise((resolve, reject) => {
Geolocation.requestAuthorization(()=>resolve({granted: true}), (err)=>reject(err))
})
}

try {
// @ts-ignore
// todo: fix types
const { granted } = await requestForegroundPermissionsAsync()
const {granted} = await requestAuthorization()
if (!granted) {
const res = { errMsg: 'Permissions denied!' }
return errorHandler(fail, complete)(res)
Expand Down
2 changes: 0 additions & 2 deletions packages/taro-router-rn/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"author": "yechunxi",
"license": "MIT",
"dependencies": {
"@react-native-masked-view/masked-view": "~0.3.1",
"@react-navigation/bottom-tabs": "^6.5.5",
"@react-navigation/native": "^6.1.4",
"@react-navigation/native-stack": "^6.9.10",
Expand All @@ -44,7 +43,6 @@
"react-native": "^0.73.1"
},
"peerDependencies": {
"@react-native-masked-view/masked-view": "~0.3.1",
"react-native-gesture-handler": "~2.14.0",
"react-native-safe-area-context": "~4.8.0",
"react-native-screens": "^3.29.0"
Expand Down
48 changes: 15 additions & 33 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 a48c141

Please sign in to comment.