Skip to content

Commit

Permalink
feat: getLocation's Authorization changeto @react-native-community/ge…
Browse files Browse the repository at this point in the history
…olocation (#266)
  • Loading branch information
flyrui316 authored and zhiqingchen committed Apr 2, 2024
1 parent b1c5764 commit 65b479a
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 4 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

0 comments on commit 65b479a

Please sign in to comment.