@mpxjs/api-proxy 2.9.62 → 2.9.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@types/index.d.ts +3 -4
- package/package.json +7 -3
- package/src/platform/api/create-selector-query/rnNodesRef.js +15 -13
- package/src/platform/api/keyboard/index.android.js +1 -0
- package/src/platform/api/keyboard/index.ios.js +62 -0
- package/src/platform/api/keyboard/index.js +13 -0
- package/src/platform/api/modal/rnModal.jsx +6 -2
- package/src/platform/api/set-navigation-bar/index.ios.js +13 -9
- package/src/platform/api/system/index.web.js +1 -1
- package/src/platform/api/vibrate/index.android.js +1 -0
- package/src/platform/api/vibrate/index.ios.js +39 -0
- package/src/platform/api/vibrate/index.js +10 -0
- package/src/platform/index.js +6 -0
package/@types/index.d.ts
CHANGED
|
@@ -12,19 +12,18 @@ type AddParam<O, V extends (...args: any) => any> =
|
|
|
12
12
|
Parameters<V> extends [{ success?: (res: infer R) => any }, ...any[]]
|
|
13
13
|
? (options: O) => ReturnType<V> & Promise<R>
|
|
14
14
|
: (options: O) => ReturnType<V>
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
type PickApiValue<T extends keyof WechatMiniprogram.Wx> = Pick<WechatMiniprogram.Wx, T>[T]
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
interface GetLocationInterface extends WechatMiniprogram.GetLocationOption {
|
|
19
19
|
aliType?: number
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
interface RequestPaymentInterface extends WechatMiniprogram.RequestPaymentOption {
|
|
23
23
|
tradeNO?: string
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
declare module '@mpxjs/core' {
|
|
27
|
-
// @ts-ignore
|
|
28
27
|
interface Mpx extends AddPromise<WechatMiniprogram.Wx> {
|
|
29
28
|
getLocation: AddParam<GetLocationInterface, PickApiValue<'getLocation'>>
|
|
30
29
|
requestPayment: AddParam<RequestPaymentInterface, PickApiValue<'requestPayment'>>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/api-proxy",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.64",
|
|
4
4
|
"description": "convert miniprogram API at each end",
|
|
5
5
|
"module": "src/index.js",
|
|
6
6
|
"types": "@types/index.d.ts",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"homepage": "https://github.com/didi/mpx#readme",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@mpxjs/utils": "^2.9.
|
|
40
|
+
"@mpxjs/utils": "^2.9.64",
|
|
41
41
|
"axios": "^1.7.3"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"expo-clipboard": "~6.0.3",
|
|
49
49
|
"react-native-device-info": "^10.13.2",
|
|
50
50
|
"react-native-get-location": "^4.0.1",
|
|
51
|
+
"react-native-haptic-feedback": "^2.3.3",
|
|
51
52
|
"react-native-safe-area-context": "^4.10.1"
|
|
52
53
|
},
|
|
53
54
|
"peerDependenciesMeta": {
|
|
@@ -74,7 +75,10 @@
|
|
|
74
75
|
},
|
|
75
76
|
"expo-brightness": {
|
|
76
77
|
"optional": true
|
|
78
|
+
},
|
|
79
|
+
"react-native-haptic-feedback": {
|
|
80
|
+
"optional": true
|
|
77
81
|
}
|
|
78
82
|
},
|
|
79
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "803334dc0e600f219d514c27461aa7663b7a6653"
|
|
80
84
|
}
|
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
hump2dash,
|
|
7
7
|
isArray
|
|
8
8
|
} from '@mpxjs/utils'
|
|
9
|
-
import { StyleSheet } from 'react-native'
|
|
10
9
|
|
|
11
10
|
const flushRefFns = (nodeInstances, fns, single) => {
|
|
12
11
|
// wx的数据格式:对于具体方法接受到的回调传参,如果获取的 nodeRef 只有一个,那么只需要返回一条数据而不是数组,但是 exec 里面统一都是数组
|
|
@@ -61,8 +60,8 @@ const getMeasureProps = (measureProps = []) => {
|
|
|
61
60
|
}
|
|
62
61
|
|
|
63
62
|
const getDataset = (props) => {
|
|
64
|
-
return wrapFn((
|
|
65
|
-
props =
|
|
63
|
+
return wrapFn((nodeInstance, resolve) => {
|
|
64
|
+
props = nodeInstance.props.current
|
|
66
65
|
resolve({
|
|
67
66
|
dataset: collectDataset(props)
|
|
68
67
|
})
|
|
@@ -70,9 +69,9 @@ const getDataset = (props) => {
|
|
|
70
69
|
}
|
|
71
70
|
|
|
72
71
|
const getPlainProps = (config) => {
|
|
73
|
-
return wrapFn((
|
|
72
|
+
return wrapFn((nodeInstance, resolve) => {
|
|
74
73
|
const res = {}
|
|
75
|
-
const props =
|
|
74
|
+
const props = nodeInstance.props.current
|
|
76
75
|
config.forEach((key) => {
|
|
77
76
|
// props 属性默认不转驼峰,用户写什么格式不会变化,取值做兼容
|
|
78
77
|
res[key] = props[key] || props[hump2dash(key)] || ''
|
|
@@ -82,12 +81,15 @@ const getPlainProps = (config) => {
|
|
|
82
81
|
}
|
|
83
82
|
|
|
84
83
|
const getComputedStyle = (config = []) => {
|
|
85
|
-
return wrapFn((
|
|
84
|
+
return wrapFn((nodeInstance, resolve) => {
|
|
86
85
|
config = new Set(config)
|
|
87
86
|
const res = {}
|
|
88
|
-
const styles =
|
|
89
|
-
const defaultStyle =
|
|
90
|
-
const computedStyle =
|
|
87
|
+
const styles = nodeInstance.props.current.style || {}
|
|
88
|
+
const defaultStyle = nodeInstance.instance.defaultStyle || {}
|
|
89
|
+
const computedStyle = {
|
|
90
|
+
...defaultStyle,
|
|
91
|
+
...styles
|
|
92
|
+
}
|
|
91
93
|
config.forEach((key) => {
|
|
92
94
|
const humpKey = dash2hump(key)
|
|
93
95
|
// 取 style 的 key 是根据传入的 key 来设置,传什么设置什么 key,只不过取值需要做兼容
|
|
@@ -99,8 +101,8 @@ const getComputedStyle = (config = []) => {
|
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
const getInstanceConfig = (config) => {
|
|
102
|
-
return wrapFn((
|
|
103
|
-
const instance =
|
|
104
|
+
return wrapFn((nodeInstance, resolve) => {
|
|
105
|
+
const instance = nodeInstance.instance
|
|
104
106
|
resolve({ [config]: instance[config] || {} })
|
|
105
107
|
})
|
|
106
108
|
}
|
|
@@ -113,8 +115,8 @@ const defaultScrollOffset = {
|
|
|
113
115
|
}
|
|
114
116
|
|
|
115
117
|
const getScrollOffset = () => {
|
|
116
|
-
return wrapFn((
|
|
117
|
-
const instance =
|
|
118
|
+
return wrapFn((nodeInstance, resolve) => {
|
|
119
|
+
const instance = nodeInstance.instance
|
|
118
120
|
resolve(
|
|
119
121
|
(instance.scrollOffset && instance.scrollOffset.current) ||
|
|
120
122
|
defaultScrollOffset
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './index'
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Keyboard } from 'react-native'
|
|
2
|
+
import { successHandle, failHandle } from '../../../common/js'
|
|
3
|
+
let hasListener = false
|
|
4
|
+
const callbacks = []
|
|
5
|
+
|
|
6
|
+
function keyboardShowListener (e) {
|
|
7
|
+
const endCoordinates = e.endCoordinates || {}
|
|
8
|
+
// eslint-disable-next-line node/no-callback-literal
|
|
9
|
+
callbacks.forEach(cb => cb({
|
|
10
|
+
height: endCoordinates.height
|
|
11
|
+
}))
|
|
12
|
+
}
|
|
13
|
+
function keyboardHideListener (e) {
|
|
14
|
+
const endCoordinates = e.endCoordinates || {}
|
|
15
|
+
let height
|
|
16
|
+
if (__mpx_mode__ === 'ios') {
|
|
17
|
+
height = 0
|
|
18
|
+
} else {
|
|
19
|
+
height = endCoordinates.height
|
|
20
|
+
}
|
|
21
|
+
// eslint-disable-next-line node/no-callback-literal
|
|
22
|
+
callbacks.forEach(cb => cb({
|
|
23
|
+
height
|
|
24
|
+
}))
|
|
25
|
+
}
|
|
26
|
+
const onKeyboardHeightChange = function (callback) {
|
|
27
|
+
if (!hasListener) {
|
|
28
|
+
Keyboard.addListener('keyboardDidShow', keyboardShowListener)
|
|
29
|
+
Keyboard.addListener('keyboardDidHide', keyboardHideListener)
|
|
30
|
+
hasListener = true
|
|
31
|
+
}
|
|
32
|
+
callbacks.push(callback)
|
|
33
|
+
}
|
|
34
|
+
const offKeyboardHeightChange = function (callback) {
|
|
35
|
+
const index = callbacks.indexOf(callback)
|
|
36
|
+
if (index > -1) {
|
|
37
|
+
callbacks.splice(index, 1)
|
|
38
|
+
}
|
|
39
|
+
if (callbacks.length === 0) {
|
|
40
|
+
Keyboard.removeAllListeners('keyboardDidShow')
|
|
41
|
+
Keyboard.removeAllListeners('keyboardDidHide')
|
|
42
|
+
hasListener = false
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const hideKeyboard = function (options = {}) {
|
|
47
|
+
const { success, fail, complete } = options
|
|
48
|
+
try {
|
|
49
|
+
Keyboard.dismiss()
|
|
50
|
+
const result = { errMsg: 'hideKeyboard:ok' }
|
|
51
|
+
successHandle(result, success, complete)
|
|
52
|
+
} catch (err) {
|
|
53
|
+
const result = { errMsg: err.message }
|
|
54
|
+
failHandle(result, fail, complete)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export {
|
|
59
|
+
onKeyboardHeightChange,
|
|
60
|
+
offKeyboardHeightChange,
|
|
61
|
+
hideKeyboard
|
|
62
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ENV_OBJ, envError } from '../../../common/js'
|
|
2
|
+
|
|
3
|
+
const onKeyboardHeightChange = ENV_OBJ.onKeyboardHeightChange || envError('onKeyboardHeightChange')
|
|
4
|
+
|
|
5
|
+
const offKeyboardHeightChange = ENV_OBJ.offKeyboardHeightChange || envError('offKeyboardHeightChange')
|
|
6
|
+
|
|
7
|
+
const hideKeyboard = ENV_OBJ.hideKeyboard || envError('hideKeyboard')
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
onKeyboardHeightChange,
|
|
11
|
+
offKeyboardHeightChange,
|
|
12
|
+
hideKeyboard
|
|
13
|
+
}
|
|
@@ -20,10 +20,13 @@ const showModal = function (options = {}) {
|
|
|
20
20
|
const modalWidth = width - 60
|
|
21
21
|
const styles = StyleSheet.create({
|
|
22
22
|
modalTask: {
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
left: 0,
|
|
24
|
+
right: 0,
|
|
25
|
+
top: 0,
|
|
26
|
+
bottom: 0,
|
|
25
27
|
justifyContent: 'center',
|
|
26
28
|
alignItems: 'center',
|
|
29
|
+
display: 'flex',
|
|
27
30
|
backgroundColor: 'rgba(0,0,0,0.6)',
|
|
28
31
|
position: 'absolute'
|
|
29
32
|
},
|
|
@@ -144,6 +147,7 @@ const showModal = function (options = {}) {
|
|
|
144
147
|
height: 40,
|
|
145
148
|
backgroundColor: '#eeeeee',
|
|
146
149
|
width: '100%',
|
|
150
|
+
keyboardType: 'default',
|
|
147
151
|
paddingLeft: 10,
|
|
148
152
|
paddingRight: 10
|
|
149
153
|
}} onChangeText={text => onChangeText(text)} defaultValue={content}></TextInput></View>)}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { successHandle, failHandle, getFocusedNavigation } from '../../../common/js'
|
|
2
|
-
|
|
2
|
+
import { nextTick } from '../next-tick'
|
|
3
3
|
function setNavigationBarTitle (options = {}) {
|
|
4
4
|
const { title = '', success, fail, complete } = options
|
|
5
5
|
const navigation = getFocusedNavigation()
|
|
6
6
|
if (!(navigation && navigation.setOptions)) {
|
|
7
7
|
failHandle({ errMsg: 'setNavigationBarTitle:fail' }, fail, complete)
|
|
8
8
|
} else {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
nextTick(() => {
|
|
10
|
+
navigation.setOptions({ headerTitle: title })
|
|
11
|
+
successHandle({ errMsg: 'setNavigationBarTitle:ok' }, success, complete)
|
|
12
|
+
})
|
|
11
13
|
}
|
|
12
14
|
}
|
|
13
15
|
|
|
@@ -17,13 +19,15 @@ function setNavigationBarColor (options = {}) {
|
|
|
17
19
|
if (!(navigation && navigation.setOptions)) {
|
|
18
20
|
failHandle({ errMsg: 'setNavigationBarColor:fail' }, fail, complete)
|
|
19
21
|
} else {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
nextTick(() => {
|
|
23
|
+
navigation.setOptions({
|
|
24
|
+
headerStyle: {
|
|
25
|
+
backgroundColor: backgroundColor
|
|
26
|
+
},
|
|
27
|
+
headerTintColor: frontColor
|
|
28
|
+
})
|
|
29
|
+
successHandle({ errMsg: 'setNavigationBarColor:ok' }, success, complete)
|
|
25
30
|
})
|
|
26
|
-
successHandle({ errMsg: 'setNavigationBarColor:ok' }, success, complete)
|
|
27
31
|
}
|
|
28
32
|
}
|
|
29
33
|
|
|
@@ -5,7 +5,7 @@ function getSystemInfoSync () {
|
|
|
5
5
|
throwSSRWarning('getSystemInfoSync API is running in non browser environments')
|
|
6
6
|
return
|
|
7
7
|
}
|
|
8
|
-
const ua = navigator.userAgent.split('(')[1]
|
|
8
|
+
const ua = navigator.userAgent.split('(')[1]?.split(')')[0] || ''
|
|
9
9
|
const phones = new Map([
|
|
10
10
|
['iPhone', /iPhone|iPad|iPod|iOS/i],
|
|
11
11
|
['Huawei', /huawei/i],
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './index.ios'
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import ReactNativeHapticFeedback from 'react-native-haptic-feedback'
|
|
2
|
+
import { Vibration } from 'react-native'
|
|
3
|
+
import { successHandle, failHandle } from '../../../common/js'
|
|
4
|
+
|
|
5
|
+
const getType = function (type = 'light') {
|
|
6
|
+
return 'impact' + type[0].toUpperCase() + type.substr(1)
|
|
7
|
+
}
|
|
8
|
+
const vibrateShort = function (options = {}) {
|
|
9
|
+
const { type = 'light', success, fail, complete } = options
|
|
10
|
+
try {
|
|
11
|
+
ReactNativeHapticFeedback.trigger(getType(type), {
|
|
12
|
+
ignoreAndroidSystemSettings: true,
|
|
13
|
+
enableVibrateFallback: true
|
|
14
|
+
})
|
|
15
|
+
const result = {
|
|
16
|
+
errMsg: 'vibrateShort:ok'
|
|
17
|
+
}
|
|
18
|
+
successHandle(result, success, complete)
|
|
19
|
+
} catch (e) {
|
|
20
|
+
const result = {
|
|
21
|
+
errMsg: 'vibrateShort:fail'
|
|
22
|
+
}
|
|
23
|
+
failHandle(result, fail, complete)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const vibrateLong = function (options = {}) {
|
|
28
|
+
const { success, complete } = options
|
|
29
|
+
Vibration.vibrate(400)
|
|
30
|
+
const result = {
|
|
31
|
+
errMsg: 'vibrateLong:ok'
|
|
32
|
+
}
|
|
33
|
+
successHandle(result, success, complete)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export {
|
|
37
|
+
vibrateShort,
|
|
38
|
+
vibrateLong
|
|
39
|
+
}
|
package/src/platform/index.js
CHANGED
|
@@ -113,3 +113,9 @@ export * from './api/location'
|
|
|
113
113
|
|
|
114
114
|
// getExtConfig, getExtConfigSync
|
|
115
115
|
export * from './api/ext'
|
|
116
|
+
|
|
117
|
+
// vibrateShort, vibrateLong
|
|
118
|
+
export * from './api/vibrate'
|
|
119
|
+
|
|
120
|
+
// onKeyboardHeightChange, offKeyboardHeightChange, hideKeyboard
|
|
121
|
+
export * from './api/keyboard'
|