Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/didi/mpx
Browse files Browse the repository at this point in the history
  • Loading branch information
hiyuki committed Sep 10, 2024
2 parents 9899723 + f08e326 commit 7d791f6
Show file tree
Hide file tree
Showing 27 changed files with 773 additions and 454 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "2.9.60"
"version": "2.9.61"
}
8 changes: 4 additions & 4 deletions packages/api-proxy/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mpxjs/api-proxy",
"version": "2.9.60",
"version": "2.9.61",
"description": "convert miniprogram API at each end",
"module": "src/index.js",
"types": "@types/index.d.ts",
Expand Down Expand Up @@ -41,21 +41,21 @@
"axios": "^1.7.3"
},
"peerDependencies": {
"@ant-design/react-native": "^5.1.3",
"@react-native-async-storage/async-storage": "^1.23.1",
"@react-native-clipboard/clipboard": "^1.14.0",
"@react-native-community/netinfo": "^11.2.1",
"expo-brightness": "~11.8.0",
"expo-clipboard": "~6.0.3",
"react-native-device-info": "^10.13.2",
"react-native-get-location": "^4.0.1",
"react-native-safe-area-context": "^4.10.1",
"@ant-design/react-native": "^5.1.3",
"react-native-webview": "^13.10.5"
},
"peerDependenciesMeta": {
"@react-native-async-storage/async-storage": {
"optional": true
},
"@react-native-clipboard/clipboard": {
"expo-clipboard": {
"optional": true
},
"@react-native-community/netinfo": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { View, TouchableHighlight, Text, StyleSheet, Button, Animated } from 'react-native'
import { successHandle, failHandle } from '../../../common/js'
import { Portal } from '@ant-design/react-native'
function showActionSheet (options) {
function showActionSheet (options = {}) {
const { alertText, itemList = [], itemColor = '#000000', success, fail, complete } = options
let actionSheetKey
const slideAnim = new Animated.Value(500)
Expand Down
29 changes: 18 additions & 11 deletions packages/api-proxy/src/platform/api/clipboard-data/rnClipboard.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Clipboard from '@react-native-clipboard/clipboard'
import { successHandle, failHandle } from '../../../common/js'
import { type } from '@mpxjs/utils'
const setClipboardData = function (options) {
import { getStringAsync, setStringAsync } from 'expo-clipboard'

const setClipboardData = function (options = {}) {
const { data, success, fail, complete } = options
if (!data || type(data) !== 'String') {
const errStr = !data ? 'parameter.data should be String instead of Undefined;' : `parameter.data should be String instead of ${type(data)};`
Expand All @@ -12,24 +13,30 @@ const setClipboardData = function (options) {
failHandle(result, fail, complete)
return
}
Clipboard.setString(data)
const result = {
errMsg: 'setClipboardData:ok'
}
successHandle(result, success, complete)
setStringAsync(data).then(() => {
const result = {
errMsg: 'setClipboardData:ok'
}
successHandle(result, success, complete)
}).catch((e) => {
const result = {
errMsg: `setClipboardData:fail ${e}`
}
failHandle(result, fail, complete)
})
}

const getClipboardData = function (options) {
const getClipboardData = function (options = {}) {
const { success, fail, complete } = options
Clipboard.getString().then((data) => {
getStringAsync().then((data) => {
const result = {
data,
errMsg: 'getClipboardData:ok'
}
successHandle(result, success, complete)
}).catch(() => {
}).catch((e) => {
const result = {
errMsg: 'setClipboardData:fail'
errMsg: `getClipboardData:fail ${e}`
}
failHandle(result, fail, complete)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const getConnectionType = function (connectionInfo) {
return type
}

const getNetworkType = function (options) {
const getNetworkType = function (options = {}) {
const { success, fail, complete } = options
NetInfo.fetch().then((connectionInfo) => {
const result = {
Expand Down
2 changes: 1 addition & 1 deletion packages/api-proxy/src/platform/api/location/index.ios.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import GetLocation from 'react-native-get-location'
import { envError, successHandle, failHandle, defineUnsupportedProps } from '../../../common/js'

const getLocation = function (options) {
const getLocation = function (options = {}) {
const { isHighAccuracy = false, success, fail, complete } = options
GetLocation.getCurrentPosition({
enableHighAccuracy: isHighAccuracy
Expand Down
2 changes: 1 addition & 1 deletion packages/api-proxy/src/platform/api/location/index.web.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { envError, successHandle, failHandle, defineUnsupportedProps } from '../../../common/js'

const getLocation = function (options) {
const getLocation = function (options = {}) {
const { isHighAccuracy = false, success, fail, complete } = options
if (navigator.geolocation.getCurrentPosition) {
navigator.geolocation.getCurrentPosition((res = {}) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { successHandle, failHandle } from '../../../common/js'
import { Linking } from 'react-native'

const makePhoneCall = function (options) {
const makePhoneCall = function (options = {}) {
const {
phoneNumber = '',
success = null,
Expand Down
2 changes: 1 addition & 1 deletion packages/api-proxy/src/platform/api/modal/rnModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { View, Dimensions, Text, StyleSheet, TouchableOpacity, ScrollView } from
import { successHandle, failHandle } from '../../../common/js'
import { Portal } from '@ant-design/react-native'
const { width, height } = Dimensions.get('window')
const showModal = function (options) {
const showModal = function (options = {}) {
const {
title,
content,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { successHandle, failHandle, isBrowser, throwSSRWarning } from '../../../common/js'
import { nextTick } from '../next-tick'

export function pageScrollTo (options) {
export function pageScrollTo (options = {}) {
if (!isBrowser) {
throwSSRWarning('pageScrollTo API is running in non browser environments')
return
Expand Down
8 changes: 4 additions & 4 deletions packages/api-proxy/src/platform/api/request/index.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ function request (options = { url: '' }) {
} catch (e) {
}
}
const result = {

const result = Object.assign({}, res, {
errMsg: 'request:ok',
data,
statusCode: res.status,
header: res.headers,
...res
}
header: res.headers
})
defineUnsupportedProps(result, ['cookies', 'profile', 'exception'])
successHandle(result, success, complete)
return result
Expand Down
Original file line number Diff line number Diff line change
@@ -1,50 +1,35 @@
// import * as Brightness from 'expo-brightness'
import * as Brightness from 'expo-brightness'
import { successHandle, failHandle } from '../../../common/js'
//
// function getScreenBrightness (options) {
// const { success, fail, complete } = options
// Brightness.getBrightnessAsync().then(value => {
// const result = {
// errMsg: 'getScreenBrightness:ok',
// value
// }
// successHandle(result, success, complete)
// }).catch(() => {
// const result = {
// errMsg: 'getScreenBrightness:fail'
// }
// failHandle(result, fail, complete)
// })
// }
//
// function setScreenBrightness (options) {
// const { value, success, fail, complete } = options
// Brightness.setBrightnessAsync(value).then(() => {
// const result = {
// errMsg: 'setScreenBrightness:ok'
// }
// successHandle(result, success, complete)
// }).catch(() => {
// const result = {
// errMsg: 'setScreenBrightness:fail'
// }
// failHandle(result, fail, complete)
// })
// }

function getScreenBrightness (options) {
const { success, complete } = options
const result = {
errMsg: 'getScreenBrightness:ok'
}
successHandle(result, success, complete)
function getScreenBrightness (options = {}) {
const { success, fail, complete } = options
Brightness.getBrightnessAsync().then(value => {
const result = {
errMsg: 'getScreenBrightness:ok',
value
}
successHandle(result, success, complete)
}).catch(() => {
const result = {
errMsg: 'getScreenBrightness:fail'
}
failHandle(result, fail, complete)
})
}
function setScreenBrightness (options) {
const { fail, complete } = options
const result = {
errMsg: 'setScreenBrightness:fail'
}
failHandle(result, fail, complete)

function setScreenBrightness (options = {}) {
const { value, success, fail, complete } = options
Brightness.setBrightnessAsync(value).then(() => {
const result = {
errMsg: 'setScreenBrightness:ok'
}
successHandle(result, success, complete)
}).catch(() => {
const result = {
errMsg: 'setScreenBrightness:fail'
}
failHandle(result, fail, complete)
})
}

export {
Expand Down
2 changes: 1 addition & 1 deletion packages/api-proxy/src/platform/api/socket/SocketTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SocketTask {
return this._socket.readyState
}

send (options) {
send (options = {}) {
const { data = '', success, fail, complete } = options
if (typeof data !== 'string' || type(data) !== 'ArrayBuffer') {
const res = { errMsg: 'sendSocketMessage:fail Unsupported data type' }
Expand Down
10 changes: 5 additions & 5 deletions packages/api-proxy/src/platform/api/storage/rnStorage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import AsyncStorage from '@react-native-async-storage/async-storage'
import { envError, successHandle, failHandle, defineUnsupportedProps } from '../../../common/js'
import { hasOwn } from '@mpxjs/utils'
function setStorage (options) {
function setStorage (options = {}) {
const { key, data, success, fail, complete } = options
let obj = {}
if (typeof data === 'symbol') {
Expand All @@ -26,7 +26,7 @@ function setStorage (options) {

const setStorageSync = envError('setStorageSync')

function getStorage (options) {
function getStorage (options = {}) {
const { key, success, fail, complete } = options
if (!key) {
const result = {
Expand Down Expand Up @@ -62,7 +62,7 @@ function getStorage (options) {

const getStorageSync = envError('getStorageSync')

function getStorageInfo (options) {
function getStorageInfo (options = {}) {
const { success, fail, complete } = options
AsyncStorage.getAllKeys((err, keys) => {
if (err) {
Expand All @@ -83,7 +83,7 @@ function getStorageInfo (options) {

const getStorageInfoSync = envError('getStorageInfoSync')

function removeStorage (options) {
function removeStorage (options = {}) {
const { key, success, fail, complete } = options
AsyncStorage.removeItem(key, (err) => {
if (err) {
Expand All @@ -104,7 +104,7 @@ function removeStorageSync (key) {
AsyncStorage.removeItem(key)
}

function clearStorage (options) {
function clearStorage (options = {}) {
const { success, fail, complete } = options
AsyncStorage.clear((err) => {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion packages/api-proxy/src/platform/api/system/rnSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const getSystemInfoSync = function () {
return result
}

const getSystemInfo = function (options) {
const getSystemInfo = function (options = {}) {
const { success, fail, complete } = options
try {
const systemInfo = getSystemInfoSync()
Expand Down
8 changes: 4 additions & 4 deletions packages/api-proxy/src/platform/api/toast/rnToast.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const styles = StyleSheet.create({
overflow: 'hidden'
}
})
function showToast (options) {
function showToast (options = {}) {
const { title, icon = 'success', image, duration = 1500, mask = false, success, fail, complete, isLoading } = options
let ToastView
const iconImg = {
Expand Down Expand Up @@ -113,7 +113,7 @@ function showToast (options) {
}
}

function hideToast(options) {
function hideToast(options = {}) {
const { noConflict = false, success, fail, complete } = options

if (isLoadingShow && noConflict) {
Expand All @@ -136,7 +136,7 @@ function hideToast(options) {
}
}

function showLoading (options) {
function showLoading (options = {}) {
const { title, mask, success, fail, complete } = options
showToast({
title,
Expand All @@ -158,7 +158,7 @@ function showLoading (options) {
})
}

function hideLoading (options) {
function hideLoading (options = {}) {
const { noConflict = false, success, fail, complete } = options
if (!isLoadingShow && noConflict) {
return
Expand Down
Loading

0 comments on commit 7d791f6

Please sign in to comment.