Skip to content

Commit

Permalink
fix(rn): typescript type error
Browse files Browse the repository at this point in the history
  • Loading branch information
Pines-Cheng committed Jul 12, 2019
1 parent 34136df commit 710ece1
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/taro-rn/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@tarojs/taro": "1.3.8",
"base64-js": "^1.3.0",
"expo-av": "^5.0.2",
"expo-brightness": "^5.0.1",
"expo-file-system": "^5.0.1",
"expo-image-picker": "^5.0.2",
"expo-location": "^5.0.1",
Expand Down
24 changes: 24 additions & 0 deletions packages/taro-rn/src/api/device/screen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as Brightness from 'expo-brightness'
import { Permissions } from 'react-native-unimodules'

/**
* 设置屏幕亮度
* @param opts
* @param {number} opts.value - 屏幕亮度值,范围 0 ~ 1。0 最暗,1 最亮
*/
export async function setScreenBrightness (opts) {
const {value} = opts
await Permissions.askAsync(Permissions.SYSTEM_BRIGHTNESS)
const {status} = await Permissions.getAsync(Permissions.SYSTEM_BRIGHTNESS)
if (status === 'granted') {
(Brightness as any).setSystemBrightness(value)
}
}

/**
*
* @param opts
*/
export function getScreenBrightness (opts) {

}
90 changes: 90 additions & 0 deletions packages/taro-rn/src/api/file/file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import * as FileSystem from 'expo-file-system'
import { Platform } from 'react-native'
import { func } from 'prop-types'
import { shouleBeObject } from '../utils'

/**
* 保存文件到本地。注意:saveFile 会把临时文件移动,因此调用成功后传入的 tempFilePath 将不可用
* @param opts
* @param {string} opts.tempFilePath 需要保存的文件的临时路径
*/
export function saveFile (opts) {

}

/**
* 删除本地缓存文件
* @param opts
* @param {string} opts.filePath 需要删除的文件路径
*/
export function removeSavedFile (opts) {

}

/**
* 新开页面打开文档
* @param opts
* @param opts.filePath 文件路径,可通过 downloadFile 获得
* @param opts.fileType 文件类型,指定文件类型打开文件
*/
export function openDocument (opts) {

}

/**
* 获取该小程序下已保存的本地缓存文件列表
* @param opts
* @param {string} opts.filePath 文件路径
*/
export function getSavedFileList (opts) {

}

/**
* 获取本地文件的文件信息。此接口只能用于获取已保存到本地的文件,若需要获取临时文件信息,请使用 wx.getFileInfo() 接口。
* @param opts
*/
export function getSavedFileInfo (opts) {

}

/**
* 获取文件信息
* @param opts
* @param {string} opts.filePath - 本地文件路径
* @param {string} [opts.digestAlgorithm] - 计算文件摘要的算法
*/
export function getFileInfo (opts) {
const res = <any>{errMsg: 'openUrl:ok'}
const isObject = shouleBeObject(opts)
if (!isObject.res) {
res.errMsg = `getFileInfo${isObject.msg}`
console.error(res)
return Promise.reject(res)
}

let {filePath, digestAlgorithm = 'md5', success, fail, complete} = opts

return FileSystem.getInfoAsync(filePath, {md5: true})
.then((obj) => {
res.size = obj.size
res.md5 = obj.md5
success && success(res)
complete && complete(res)
return {
size: res.size,
digest: res.md5
}
}).catch(e => {
res.errMsg = `openUrl:fail. ${e.message}`
fail && fail(res)
complete && complete(res)
})
}

/**
* 获取全局唯一的文件管理器
*/
export function getFileSystemManager () {

}
2 changes: 1 addition & 1 deletion packages/taro-rn/src/api/media/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class InnerAudioContext {

const soundStatus = await this.soundObject.getStatusAsync()
try {
if (soundStatus.isLoaded === false && soundStatus.isPlaying === undefined) {
if (soundStatus.isLoaded === false && (soundStatus as any).isPlaying === undefined) {
// First load
await this._firstPlay()

Expand Down
6 changes: 4 additions & 2 deletions packages/taro-rn/src/api/media/map.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
global._taroMapMap = {}
const globalAny:any = global;

globalAny._taroMapMap = {}

class MapContext {
private mapRef
Expand Down Expand Up @@ -58,7 +60,7 @@ class MapContext {
* {object} @param t - 在自定义组件下,当前组件实例的this,以操作组件内 map 组件
*/
export function createMapContext (id: string, t: object) {
const ref = global._taroMapMap[id]
const ref = globalAny._taroMapMap[id]
if (ref) {
return new MapContext(ref)
} else {
Expand Down
6 changes: 4 additions & 2 deletions packages/taro-rn/src/api/media/video.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Video } from 'expo-av'

global._taroVideoMap = {}
const globalAny:any = global;

globalAny._taroVideoMap = {}

interface FullScreenObject {
direction?: number
Expand Down Expand Up @@ -136,7 +138,7 @@ class VideoContext {
* {object} @param t - 在自定义组件下,当前组件实例的this,以操作组件内 video 组件
*/
export function createVideoContext (id: string, t: object) {
const ref = global._taroVideoMap[id]
const ref = globalAny._taroVideoMap[id]
if (ref) {
return new VideoContext(ref)
} else {
Expand Down
6 changes: 5 additions & 1 deletion packages/taro-rn/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
"jsx": "react",
"moduleResolution": "node",
"target": "es2015",
"lib": ["es2015"],
"skipLibCheck": true,
"lib": [
"es2015",
"dom"
],
"typeRoots": [
"./node_modules/@types",
"./src/types"
Expand Down
10 changes: 7 additions & 3 deletions packages/taro-rn/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1153,9 +1153,9 @@
"@types/istanbul-lib-coverage" "^2.0.0"
"@types/yargs" "^12.0.9"

"@tarojs/taro@1.3.0":
version "1.3.0"
resolved "https://registry.npm.taobao.org/@tarojs/taro/download/@tarojs/taro-1.3.0.tgz#fdd29762251891302b18893c6defd505d9ae9570"
"@tarojs/taro@1.3.8":
version "1.3.8"
resolved "https://registry.npm.taobao.org/@tarojs/taro/download/@tarojs/taro-1.3.8.tgz#53c10f3dccb4de7fee05e107ab5b48b7496a7513"

"@types/babel-types@^7.0.7":
version "7.0.7"
Expand Down Expand Up @@ -3359,6 +3359,10 @@ expo-av@^5.0.2:
dependencies:
lodash "^4.17.11"

expo-brightness@^5.0.1:
version "5.0.1"
resolved "https://registry.npm.taobao.org/expo-brightness/download/expo-brightness-5.0.1.tgz#90e0445a34c7ef92c4511211c888bbc50eae0441"

expo-constants@~5.0.0:
version "5.0.1"
resolved "https://registry.npm.taobao.org/expo-constants/download/expo-constants-5.0.1.tgz#597263397f269d7fe37d9cd6b30e305c16635a00"
Expand Down

0 comments on commit 710ece1

Please sign in to comment.