@mpxjs/api-proxy 2.9.62 → 2.9.65

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 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
- // @ts-ignore
15
+
16
16
  type PickApiValue<T extends keyof WechatMiniprogram.Wx> = Pick<WechatMiniprogram.Wx, T>[T]
17
- // @ts-ignore
17
+
18
18
  interface GetLocationInterface extends WechatMiniprogram.GetLocationOption {
19
19
  aliType?: number
20
20
  }
21
- // @ts-ignore
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.62",
3
+ "version": "2.9.65",
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.59",
40
+ "@mpxjs/utils": "^2.9.65",
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": "c31a343e7ef2c1c1585002752d8c50f016a858ae"
83
+ "gitHead": "24efa90e90b4d42c285ca61739cb9e4d0696976c"
80
84
  }
@@ -1,4 +1,4 @@
1
- import { hasOwn, noop, getEnvObj } from '@mpxjs/utils'
1
+ import { hasOwn, noop, getEnvObj, getFocusedNavigation } from '@mpxjs/utils'
2
2
 
3
3
  /**
4
4
  *
@@ -87,14 +87,6 @@ function failHandle (result, fail, complete) {
87
87
  typeof complete === 'function' && complete(result)
88
88
  }
89
89
 
90
- function getFocusedNavigation () {
91
- for (const key in global.__mpxPagesMap) {
92
- const navigation = global.__mpxPagesMap[key]?.[1]
93
- if (navigation && navigation.isFocused()) {
94
- return navigation
95
- }
96
- }
97
- }
98
90
  const ENV_OBJ = getEnvObj()
99
91
 
100
92
  export {
@@ -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((nodeRef, resolve) => {
65
- props = nodeRef.props.current
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((nodeRef, resolve) => {
72
+ return wrapFn((nodeInstance, resolve) => {
74
73
  const res = {}
75
- const props = nodeRef.props.current
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((nodeRef, resolve) => {
84
+ return wrapFn((nodeInstance, resolve) => {
86
85
  config = new Set(config)
87
86
  const res = {}
88
- const styles = nodeRef.props.current.style || []
89
- const defaultStyle = nodeRef.instance.defaultStyle || {}
90
- const computedStyle = StyleSheet.flatten([defaultStyle, ...styles])
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((nodeRef, resolve) => {
103
- const instance = nodeRef.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((nodeRef, resolve) => {
117
- const instance = nodeRef.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
- width,
24
- height,
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>)}
@@ -110,7 +110,8 @@ function reLaunch (options = {}) {
110
110
  routeCount: ++routeCount,
111
111
  replaced: false
112
112
  }
113
- const delta = router.stack.length - 1
113
+ // 宿主环境中没有办法统计到webview中的页面跳转,所有给用户开放个userDelta,由用户根据webview中的页面跳转的个数自行传递控制relaunch跳转正确
114
+ const delta = router.stack.length - 1 + (options.delta || 0)
114
115
  // 在需要操作后退时,先操作后退,在beforeEach中基于当前action通过next()进行replace操作,避免部分浏览器的表现不一致
115
116
  if (delta > 0) {
116
117
  router.go(-delta)
@@ -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
- navigation.setOptions({ headerTitle: title })
10
- successHandle({ errMsg: 'setNavigationBarTitle:ok' }, success, complete)
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
- navigation.setOptions({
21
- headerStyle: {
22
- backgroundColor: backgroundColor
23
- },
24
- headerTintColor: frontColor
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].split(')')[0]
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],
@@ -5,10 +5,10 @@ import { successHandle, failHandle, defineUnsupportedProps, getFocusedNavigation
5
5
 
6
6
  const getWindowInfo = function () {
7
7
  const dimensionsScreen = Dimensions.get('screen')
8
- const navigation = getFocusedNavigation() || {}
8
+ const navigation = getFocusedNavigation()
9
9
  const insets = {
10
- ...(initialWindowMetrics?.insets || {}),
11
- ...(navigation.insets || {})
10
+ ...initialWindowMetrics?.insets,
11
+ ...navigation?.insets
12
12
  }
13
13
  let safeArea = {}
14
14
  let { top = 0, bottom = 0, left = 0, right = 0 } = insets
@@ -17,7 +17,7 @@ const getWindowInfo = function () {
17
17
  }
18
18
  const screenHeight = dimensionsScreen.height
19
19
  const screenWidth = dimensionsScreen.width
20
- const layout = navigation.layout || {}
20
+ const layout = navigation?.layout || {}
21
21
  const layoutHeight = layout.height || 0
22
22
  const layoutWidth = layout.width || 0
23
23
  const windowHeight = layoutHeight || screenHeight
@@ -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
+ }
@@ -0,0 +1,10 @@
1
+ import { ENV_OBJ, envError } from '../../../common/js'
2
+
3
+ const vibrateShort = ENV_OBJ.vibrateShort || envError('vibrateShort')
4
+
5
+ const vibrateLong = ENV_OBJ.vibrateLong || envError('vibrateLong')
6
+
7
+ export {
8
+ vibrateShort,
9
+ vibrateLong
10
+ }
@@ -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'