@mpxjs/api-proxy 2.9.70-alpha.1 → 2.9.70-alpha.3

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
@@ -110,6 +110,19 @@ export const createVideoContext: WechatMiniprogram.Wx['createVideoContext']
110
110
  export const onWindowResize: WechatMiniprogram.Wx['onWindowResize']
111
111
  export const offWindowResize: WechatMiniprogram.Wx['offWindowResize']
112
112
  export const createAnimation: WechatMiniprogram.Wx['createAnimation']
113
+ export const hideHomeButton: WechatMiniprogram.Wx['hideHomeButton']
114
+ export const getSetting: WechatMiniprogram.Wx['getSetting']
115
+ export const openSetting: WechatMiniprogram.Wx['openSetting']
116
+ export const enableAlertBeforeUnload: WechatMiniprogram.Wx['enableAlertBeforeUnload']
117
+ export const disableAlertBeforeUnload: WechatMiniprogram.Wx['disableAlertBeforeUnload']
118
+ export const getMenuButtonBoundingClientRect: WechatMiniprogram.Wx['getMenuButtonBoundingClientRect']
119
+ export const getImageInfo: WechatMiniprogram.Wx['getImageInfo']
120
+ export const vibrateShort: WechatMiniprogram.Wx['vibrateShort']
121
+ export const vibrateLong: WechatMiniprogram.Wx['vibrateLong']
122
+ export const getExtConfig: WechatMiniprogram.Wx['getExtConfig']
123
+ export const getExtConfigSync: WechatMiniprogram.Wx['getExtConfigSync']
124
+ export const openLocation: WechatMiniprogram.Wx['openLocation']
125
+ export const chooseLocation: WechatMiniprogram.Wx['chooseLocation']
113
126
 
114
127
  declare const install: (...args: any) => any
115
128
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/api-proxy",
3
- "version": "2.9.70-alpha.1",
3
+ "version": "2.9.70-alpha.3",
4
4
  "description": "convert miniprogram API at each end",
5
5
  "module": "src/index.js",
6
6
  "types": "@types/index.d.ts",
@@ -1,3 +1,3 @@
1
1
  export * from './web'
2
2
  export * from './utils'
3
- export * from './toPromise'
3
+ export * from './ToPromise'
@@ -70,14 +70,22 @@ function promisify (listObj, whiteList, customBlackList) {
70
70
  result[key] = function (...args) {
71
71
  const obj = args[0] || {}
72
72
  // 不需要转换 or 用户已定义回调,则不处理
73
- if (!promisifyFilter(key) || obj.success || obj.fail) {
73
+ if (!promisifyFilter(key)) {
74
74
  return listObj[key].apply(ENV_OBJ, args)
75
75
  } else { // 其他情况进行转换
76
76
  if (!args[0]) args.unshift(obj)
77
77
  let returned
78
78
  const promise = new Promise((resolve, reject) => {
79
- obj.success = resolve
80
- obj.fail = reject
79
+ const originSuccess = obj.success
80
+ const originFail = obj.fail
81
+ obj.success = function (res) {
82
+ originSuccess && originSuccess.call(this, res)
83
+ resolve(res)
84
+ }
85
+ obj.fail = function (e) {
86
+ originFail && originFail.call(this, e)
87
+ reject(e)
88
+ }
81
89
  returned = listObj[key].apply(ENV_OBJ, args)
82
90
  })
83
91
  promise.__returned = returned
@@ -1,38 +1,17 @@
1
- import { View, TouchableHighlight, Text, StyleSheet, Button, Animated } from 'react-native'
1
+ import { View, TouchableHighlight, Text, StyleSheet, TouchableOpacity } from 'react-native'
2
2
  import { successHandle, failHandle } from '../../../common/js'
3
3
  import { Portal } from '@ant-design/react-native'
4
+ import { getWindowInfo } from '../system/rnSystem'
5
+ import Animated, {
6
+ useSharedValue,
7
+ useAnimatedStyle,
8
+ withTiming
9
+ } from 'react-native-reanimated'
4
10
  function showActionSheet (options = {}) {
5
11
  const { alertText, itemList = [], itemColor = '#000000', success, fail, complete } = options
6
- let actionSheetKey
7
- const slideAnim = new Animated.Value(500)
8
- const slideIn = () => {
9
- // Will change fadeAnim value to 1 in 5 seconds
10
- Animated.timing(slideAnim, {
11
- toValue: 0,
12
- duration: 200,
13
- useNativeDriver: true,
14
- }).start()
15
- }
16
- const slideOut = () => {
17
- // Will change fadeAnim value to 1 in 5 seconds
18
- Animated.timing(slideAnim, {
19
- toValue: 500,
20
- duration: 200,
21
- useNativeDriver: true,
22
- }).start(() => {
23
- })
24
- }
25
- if (itemList.length === 0 || itemList.length > 6) {
26
- const result = {
27
- errMsg: 'showActionSheet:fail parameter error: itemList should not be large than 6'
28
- }
29
- if (itemList.length === 0) {
30
- result.errno = 1001
31
- result.errMsg = 'showActionSheet:fail parameter error: parameter.itemList should have at least 1 item;'
32
- }
33
- failHandle(result, fail, complete)
34
- return
35
- }
12
+ const windowInfo = getWindowInfo()
13
+ const bottom = windowInfo.screenHeight - windowInfo.safeArea.bottom
14
+ let actionSheetKey = null
36
15
  const styles = StyleSheet.create({
37
16
  actionActionMask: {
38
17
  left: 0,
@@ -44,16 +23,14 @@ function showActionSheet (options = {}) {
44
23
  zIndex: 1000
45
24
  },
46
25
  actionSheetContent: {
47
- left: 0,
48
- right: 0,
49
- position: 'absolute',
50
- bottom: 0,
51
26
  backgroundColor: '#ffffff',
52
27
  borderTopLeftRadius: 10,
53
28
  borderTopRightRadius: 10,
54
- transform: [{
55
- translateY: -500
56
- }]
29
+ position: 'absolute',
30
+ bottom: 0,
31
+ left: 0,
32
+ right: 0,
33
+ paddingBottom: bottom
57
34
  },
58
35
  itemStyle: {
59
36
  paddingTop: 15,
@@ -73,53 +50,62 @@ function showActionSheet (options = {}) {
73
50
  paddingBottom: 10
74
51
  }
75
52
  })
76
- const remove = function () {
77
- if (actionSheetKey) {
78
- slideOut()
79
- setTimeout(() => {
80
- Portal.remove(actionSheetKey)
81
- actionSheetKey = null
82
- }, 200)
53
+ function ActionSheet () {
54
+ const offset = useSharedValue(1000);
55
+
56
+ const animatedStyles = useAnimatedStyle(() => ({
57
+ transform: [{ translateY: offset.value }],
58
+ }))
59
+
60
+ const slideOut = () => {
61
+ // Will change fadeAnim value to 1 in 5 seconds
62
+ offset.value = withTiming(1000)
83
63
  }
84
- }
85
- const selectAction = function (index) {
86
- const result = {
87
- errMsg: 'showActionSheet:ok',
88
- tapIndex: index
64
+
65
+ offset.value = withTiming(0)
66
+
67
+ const selectAction = function (index) {
68
+ const result = {
69
+ errMsg: 'showActionSheet:ok',
70
+ tapIndex: index
71
+ }
72
+ successHandle(result, success, complete)
73
+ remove()
89
74
  }
90
- successHandle(result, success, complete)
91
- remove()
92
- }
93
- const cancelAction = function () {
94
- const result = {
95
- errMsg: 'showActionSheet:fail cancel'
75
+
76
+ const remove = function () {
77
+ if (actionSheetKey) {
78
+ slideOut()
79
+ setTimeout(() => {
80
+ Portal.remove(actionSheetKey)
81
+ actionSheetKey = null
82
+ }, 200)
83
+ }
96
84
  }
97
- failHandle(result, fail, complete)
98
- remove()
99
- }
100
- let alertTextList = []
101
- if (alertText) {
102
- alertTextList = [alertText]
85
+
86
+ const cancelAction = function () {
87
+ const result = {
88
+ errMsg: 'showActionSheet:fail cancel'
89
+ }
90
+ failHandle(result, fail, complete)
91
+ remove()
92
+ }
93
+ return (
94
+ <TouchableHighlight underlayColor="rgba(0,0,0,0.6)" activeOpacity={1} onPress={cancelAction} style={styles.actionActionMask}>
95
+ <Animated.View style={[styles.actionSheetContent, animatedStyles]} >
96
+ { alertText ? <View style={ styles.itemStyle }><Text style={[styles.itemTextStyle, { color: '#666666' }]}>{alertText}</Text></View> : null }
97
+ { itemList.map((item, index) => <TouchableHighlight key={index} underlayColor="#ececec" onPress={() => selectAction(index)} style={ [styles.itemStyle, itemList.length -1 === index ? {
98
+ borderBottomWidth: 6,
99
+ borderBottomStyle: 'solid',
100
+ borderBottomColor: '#f7f7f7'
101
+ } : {}] }><Text style={[styles.itemTextStyle, { color: itemColor }]}>{item}</Text></TouchableHighlight>) }
102
+ <View style={styles.buttonStyle}><TouchableOpacity onPress={cancelAction}><Text style={{ color: "#000000", width: "100%", textAlign: "center" }}>取消</Text></TouchableOpacity></View>
103
+ </Animated.View>
104
+ </TouchableHighlight>
105
+ )
103
106
  }
104
- const ActionSheetView = <TouchableHighlight underlayColor="rgba(0,0,0,0.6)" onPress={cancelAction} style={styles.actionActionMask}>
105
- <Animated.View
106
- style={[
107
- styles.actionSheetContent,
108
- {
109
- transform: [{translateY: slideAnim}]
110
- }
111
- ]}>
112
- { alertTextList.map((item, index) => <View key={index} style={ styles.itemStyle }><Text style={[styles.itemTextStyle, { color: '#666666' }]}>{item}</Text></View>) }
113
- { itemList.map((item, index) => <TouchableHighlight key={index} underlayColor="#ececec" onPress={() => selectAction(index)} style={ [styles.itemStyle, itemList.length -1 === index ? {
114
- borderBottomWidth: 6,
115
- borderBottomStyle: 'solid',
116
- borderBottomColor: '#f7f7f7'
117
- } : {}] }><Text style={[styles.itemTextStyle, { color: itemColor }]}>{item}</Text></TouchableHighlight>) }
118
- <View style={styles.buttonStyle}><Button color={'#000000'} title={'取消'} onPress={cancelAction}></Button></View>
119
- </Animated.View>
120
- </TouchableHighlight>
121
- actionSheetKey = Portal.add(ActionSheetView)
122
- slideIn()
107
+
108
+ actionSheetKey = Portal.add(<ActionSheet/>)
123
109
  }
124
110
 
125
111
  export {
@@ -3,8 +3,27 @@ import { isBrowser, isReact } from '@mpxjs/utils'
3
3
  global.__mpxAppCbs = global.__mpxAppCbs || {
4
4
  show: [],
5
5
  hide: [],
6
- error: []
6
+ error: [],
7
+ rejection: []
8
+ }
9
+
10
+ function off (cbs, cb) {
11
+ if (cb) {
12
+ const idx = cbs.indexOf(cb)
13
+ if (idx > -1) cbs.splice(idx, 1)
14
+ } else {
15
+ cbs.length = 0
16
+ }
17
+ }
18
+
19
+ function onUnhandledRejection (callback) {
20
+ if (isBrowser || isReact) {
21
+ global.__mpxAppCbs.rejection.push(callback)
22
+ }
23
+ }
7
24
 
25
+ function offUnhandledRejection (callback) {
26
+ off(global.__mpxAppCbs.rejection, callback)
8
27
  }
9
28
 
10
29
  function onError (callback) {
@@ -14,9 +33,7 @@ function onError (callback) {
14
33
  }
15
34
 
16
35
  function offError (callback) {
17
- const cbs = global.__mpxAppCbs.error
18
- const index = cbs.indexOf(callback)
19
- if (index > -1) cbs.splice(index, 1)
36
+ off(global.__mpxAppCbs.error, callback)
20
37
  }
21
38
 
22
39
  function onAppShow (callback) {
@@ -26,9 +43,7 @@ function onAppShow (callback) {
26
43
  }
27
44
 
28
45
  function offAppShow (callback) {
29
- const cbs = global.__mpxAppCbs.show
30
- const index = cbs.indexOf(callback)
31
- if (index > -1) cbs.splice(index, 1)
46
+ off(global.__mpxAppCbs.show, callback)
32
47
  }
33
48
 
34
49
  function onAppHide (callback) {
@@ -38,9 +53,7 @@ function onAppHide (callback) {
38
53
  }
39
54
 
40
55
  function offAppHide (callback) {
41
- const cbs = global.__mpxAppCbs.hide
42
- const index = cbs.indexOf(callback)
43
- if (index > -1) cbs.splice(index, 1)
56
+ off(global.__mpxAppCbs.hide, callback)
44
57
  }
45
58
 
46
59
  export {
@@ -49,5 +62,7 @@ export {
49
62
  offAppShow,
50
63
  offAppHide,
51
64
  onError,
52
- offError
65
+ offError,
66
+ onUnhandledRejection,
67
+ offUnhandledRejection
53
68
  }
@@ -1,8 +1,7 @@
1
- import { isArray, isObject, isString, noop } from '@mpxjs/utils'
1
+ import { isArray, isObject, isString, noop, warn } from '@mpxjs/utils'
2
2
  import throttle from 'lodash/throttle'
3
3
  import { Dimensions } from 'react-native'
4
4
  import { getFocusedNavigation } from '../../../common/js'
5
-
6
5
  const WindowRefStr = 'window'
7
6
  const IgnoreTarget = 'ignore'
8
7
  const DefaultMargin = { top: 0, bottom: 0, left: 0, right: 0 }
@@ -12,13 +11,19 @@ class RNIntersectionObserver {
12
11
  constructor (component, options, intersectionCtx) {
13
12
  this.id = idCount++
14
13
  this.component = component
15
- this.options = options
16
- this.thresholds = options.thresholds.sort((a, b) => a - b) || [0]
17
- this.initialRatio = options.initialRatio || 0
18
- this.observeAll = options.observeAll || false
14
+ this.mpxFileResource = component.__mpxProxy?.options?.mpxFileResource || ''
15
+ this.options = Object.assign({
16
+ thresholds: [0],
17
+ initialRatio: 0,
18
+ observeAll: false,
19
+ throttleTime: 100
20
+ }, options || {})
21
+ this.thresholds = this.options.thresholds.sort((a, b) => a - b)
22
+ this.initialRatio = this.options.initialRatio
23
+ this.observeAll = this.options.observeAll
19
24
 
20
25
  // 组件上挂载对应的observers,用于在组件销毁的时候进行批量disconnect
21
- this.component._intersectionObservers = this.component.__intersectionObservers || []
26
+ this.component._intersectionObservers = this.component._intersectionObservers || []
22
27
  this.component._intersectionObservers.push(this)
23
28
 
24
29
  this.observerRefs = null
@@ -26,7 +31,7 @@ class RNIntersectionObserver {
26
31
  this.margins = DefaultMargin
27
32
  this.callback = noop
28
33
 
29
- this.throttleMeasure = this.getThrottleMeasure(options.throttleTime || 100)
34
+ this.throttleMeasure = this.getThrottleMeasure(this.options.throttleTime)
30
35
 
31
36
  // 记录上一次相交的比例
32
37
  this.previousIntersectionRatio = []
@@ -52,7 +57,7 @@ class RNIntersectionObserver {
52
57
  this.relativeRef = relativeRef
53
58
  this.margins = Object.assign({}, DefaultMargin, margins)
54
59
  } else {
55
- console.warn(`node ${selector}is not found. The relative node for intersection observer will be ignored`)
60
+ warn(`node ${selector}is not found. The relative node for intersection observer will be ignored`, this.mpxFileResource)
56
61
  }
57
62
  return this
58
63
  }
@@ -65,7 +70,7 @@ class RNIntersectionObserver {
65
70
 
66
71
  observe (selector, callback) {
67
72
  if (this.observerRefs) {
68
- console.error('"observe" call can be only called once in IntersectionObserver')
73
+ warn('"observe" call can be only called once in IntersectionObserver', this.mpxFileResource)
69
74
  return
70
75
  }
71
76
  let targetRef = null
@@ -75,7 +80,7 @@ class RNIntersectionObserver {
75
80
  targetRef = this.component.__selectRef(selector, 'node')
76
81
  }
77
82
  if (!targetRef || targetRef.length === 0) {
78
- console.error('intersection observer target not found')
83
+ warn('intersection observer target not found', this.mpxFileResource)
79
84
  return
80
85
  }
81
86
  this.observerRefs = isArray(targetRef) ? targetRef : [targetRef]
@@ -85,7 +90,7 @@ class RNIntersectionObserver {
85
90
 
86
91
  _getWindowRect () {
87
92
  if (this.windowRect) return this.windowRect
88
- const navigation = getFocusedNavigation()
93
+ const navigation = getFocusedNavigation() || {}
89
94
  const screen = Dimensions.get('screen')
90
95
  const navigationLayout = navigation.layout || {
91
96
  x: 0,
@@ -95,10 +100,10 @@ class RNIntersectionObserver {
95
100
  }
96
101
 
97
102
  const windowRect = {
98
- top: navigationLayout.y + this.margins.top,
99
- left: navigationLayout.x + this.margins.left,
100
- right: navigationLayout.width - this.margins.right,
101
- bottom: navigationLayout.y + navigationLayout.height - this.margins.bottom
103
+ top: navigationLayout.y - this.margins.top,
104
+ left: 0 - this.margins.left,
105
+ right: navigationLayout.width + this.margins.right,
106
+ bottom: navigationLayout.y + navigationLayout.height + this.margins.bottom
102
107
  }
103
108
 
104
109
  this.windowRect = windowRect
@@ -227,7 +232,7 @@ class RNIntersectionObserver {
227
232
  }
228
233
  })
229
234
  }).catch((e) => {
230
- console.log('_measureTarget fail', e)
235
+ warn('_measureTarget fail', this.mpxFileResource, e)
231
236
  })
232
237
  }
233
238
 
@@ -30,7 +30,10 @@ function compressImage (options = {}) {
30
30
  return ENV_OBJ.compressImage(opts)
31
31
  }
32
32
 
33
+ const getImageInfo = ENV_OBJ.getImageInfo
34
+
33
35
  export {
34
36
  previewImage,
35
- compressImage
37
+ compressImage,
38
+ getImageInfo
36
39
  }
@@ -0,0 +1,45 @@
1
+ import { envError, defineUnsupportedProps, successHandle, failHandle } from '../../../common/js'
2
+ import { Image } from 'react-native'
3
+
4
+ const previewImage = envError('previewImage')
5
+
6
+ const compressImage = envError('compressImage')
7
+
8
+ const getImageInfo = function (options = {}) {
9
+ const { src, success, fail, complete } = options
10
+ if (src === undefined) {
11
+ const result = {
12
+ errMsg: 'getImageInfo:fail parameter error: parameter.src should be String instead of Undefined;',
13
+ errno: 1001
14
+ }
15
+ failHandle(result, fail, complete)
16
+ return
17
+ }
18
+ if (src === '') {
19
+ const result = {
20
+ errMsg: 'getImageInfo:fail image not found'
21
+ }
22
+ failHandle(result, fail, complete)
23
+ return
24
+ }
25
+ Image.getSize(src, (width, height) => {
26
+ const result = {
27
+ errMsg: 'getImageInfo:ok',
28
+ width,
29
+ height
30
+ }
31
+ defineUnsupportedProps(result, ['path', 'orientation', 'type'])
32
+ successHandle(result, success, complete)
33
+ }, (err) => {
34
+ const result = {
35
+ errMsg: 'getImageInfo:fail download image fail. reason: ' + err
36
+ }
37
+ failHandle(result, fail, complete)
38
+ })
39
+ }
40
+
41
+ export {
42
+ previewImage,
43
+ compressImage,
44
+ getImageInfo
45
+ }
@@ -4,7 +4,10 @@ const previewImage = ENV_OBJ.previewImage || envError('previewImage')
4
4
 
5
5
  const compressImage = ENV_OBJ.compressImage || envError('compressImage')
6
6
 
7
+ const getImageInfo = ENV_OBJ.getImageInfo || envError('getImageInfo')
8
+
7
9
  export {
8
10
  previewImage,
9
- compressImage
11
+ compressImage,
12
+ getImageInfo
10
13
  }
@@ -1,5 +1,5 @@
1
1
  import Preview from './Preview'
2
- import { isBrowser, throwSSRWarning, envError } from '../../../common/js'
2
+ import { isBrowser, throwSSRWarning, envError, defineUnsupportedProps, successHandle, failHandle } from '../../../common/js'
3
3
 
4
4
  let preview = null
5
5
 
@@ -15,9 +15,53 @@ const previewImage = (options) => {
15
15
  if (!preview) preview = new Preview()
16
16
  preview.show(options)
17
17
  }
18
+
18
19
  const compressImage = envError('compressImage')
19
20
 
21
+ const getImageInfo = function (options = {}) {
22
+ const { src, success, fail, complete } = options
23
+
24
+ if (src === undefined) {
25
+ const result = {
26
+ errMsg: 'getImageInfo:fail parameter error: parameter.src should be String instead of Undefined;',
27
+ errno: 1001
28
+ }
29
+ failHandle(result, fail, complete)
30
+ return
31
+ }
32
+ if (src === '') {
33
+ const result = {
34
+ errMsg: 'getImageInfo:fail image not found'
35
+ }
36
+ failHandle(result, fail, complete)
37
+ return
38
+ }
39
+
40
+ const img = new Image()
41
+ img.src = src
42
+
43
+ img.onload = function () {
44
+ const width = img.width
45
+ const height = img.height
46
+ const result = {
47
+ errMsg: 'getImageInfo:ok',
48
+ width,
49
+ height
50
+ }
51
+ defineUnsupportedProps(result, ['path', 'orientation', 'type'])
52
+ successHandle(result, success, complete)
53
+ }
54
+
55
+ img.onerror = function () {
56
+ const result = {
57
+ errMsg: 'getImageInfo:fail download image fail. '
58
+ }
59
+ failHandle(result, fail, complete)
60
+ }
61
+ }
62
+
20
63
  export {
21
64
  previewImage,
22
- compressImage
65
+ compressImage,
66
+ getImageInfo
23
67
  }
@@ -17,7 +17,7 @@ const showModal = function (options = {}) {
17
17
  fail,
18
18
  complete
19
19
  } = options
20
- const modalWidth = width - 60
20
+ const modalWidth = width * 0.8
21
21
  const styles = StyleSheet.create({
22
22
  modalTask: {
23
23
  left: 0,
@@ -53,7 +53,8 @@ const showModal = function (options = {}) {
53
53
  lineHeight: 26,
54
54
  color: '#808080',
55
55
  paddingLeft: 20,
56
- paddingRight: 20
56
+ paddingRight: 20,
57
+ textAlign: 'center'
57
58
  },
58
59
  modalBtnBox: {
59
60
  borderTopWidth: StyleSheet.hairlineWidth,
@@ -67,8 +68,8 @@ const showModal = function (options = {}) {
67
68
  modalBtn: {
68
69
  flex: 1,
69
70
  textAlign: 'center',
70
- paddingTop: 10,
71
- paddingBottom: 10,
71
+ paddingTop: width * 0.04,
72
+ paddingBottom: width * 0.04,
72
73
  },
73
74
  modalButton: {
74
75
  width: '100%',
@@ -88,9 +89,8 @@ const showModal = function (options = {}) {
88
89
  let editableContent = []
89
90
  let modalButton = [{
90
91
  text: confirmText,
91
- confirmColor,
92
92
  type: 'confirm',
93
- color: 'rgb(87, 107, 149)'
93
+ color: confirmColor
94
94
  }]
95
95
  let contentText = content
96
96
  const onChangeText = function (text) {
@@ -128,10 +128,9 @@ const showModal = function (options = {}) {
128
128
  if (showCancel) {
129
129
  modalButton.unshift({
130
130
  text: cancelText,
131
- cancelColor,
132
131
  type: 'cancel',
133
132
  style: styles.cancelStyle,
134
- color: '#000000'
133
+ color: cancelColor
135
134
  })
136
135
  }
137
136
  ModalView = <View style={styles.modalTask}>
@@ -107,10 +107,9 @@ function request (options = { url: '' }) {
107
107
  errMsg: `request:fail ${err}`,
108
108
  statusCode: response.status,
109
109
  header: response.headers,
110
- data: response.data,
111
- stack: realError.stack,
112
- ...realError
110
+ data: response.data
113
111
  }
112
+ Object.assign(res, realError)
114
113
  failHandle(res, fail, complete)
115
114
  })
116
115
 
@@ -17,7 +17,12 @@ function setNavigationBarColor (options = {}) {
17
17
  return ENV_OBJ.setNavigationBar(options)
18
18
  }
19
19
 
20
+ function hideHomeButton (options = {}) {
21
+ return ENV_OBJ.hideBackHome(options)
22
+ }
23
+
20
24
  export {
21
25
  setNavigationBarTitle,
22
- setNavigationBarColor
26
+ setNavigationBarColor,
27
+ hideHomeButton
23
28
  }
@@ -1,4 +1,4 @@
1
- import { successHandle, failHandle, getFocusedNavigation } from '../../../common/js'
1
+ import { successHandle, failHandle, getFocusedNavigation, envError } from '../../../common/js'
2
2
  import { nextTick } from '../next-tick'
3
3
  function setNavigationBarTitle (options = {}) {
4
4
  const { title = '', success, fail, complete } = options
@@ -7,7 +7,7 @@ function setNavigationBarTitle (options = {}) {
7
7
  failHandle({ errMsg: 'setNavigationBarTitle:fail' }, fail, complete)
8
8
  } else {
9
9
  nextTick(() => {
10
- navigation.setOptions({ headerTitle: title })
10
+ navigation.setOptions({ title })
11
11
  successHandle({ errMsg: 'setNavigationBarTitle:ok' }, success, complete)
12
12
  })
13
13
  }
@@ -31,7 +31,10 @@ function setNavigationBarColor (options = {}) {
31
31
  }
32
32
  }
33
33
 
34
+ const hideHomeButton = envError('hideHomeButton')
35
+
34
36
  export {
35
37
  setNavigationBarTitle,
36
- setNavigationBarColor
38
+ setNavigationBarColor,
39
+ hideHomeButton
37
40
  }
@@ -4,7 +4,10 @@ const setNavigationBarTitle = ENV_OBJ.setNavigationBarTitle || envError('setNavi
4
4
 
5
5
  const setNavigationBarColor = ENV_OBJ.setNavigationBarColor || envError('setNavigationBarColor')
6
6
 
7
+ const hideHomeButton = ENV_OBJ.hideHomeButton || envError('hideHomeButton')
8
+
7
9
  export {
8
10
  setNavigationBarTitle,
9
- setNavigationBarColor
11
+ setNavigationBarColor,
12
+ hideHomeButton
10
13
  }
@@ -1,4 +1,4 @@
1
- import { isBrowser, throwSSRWarning, successHandle } from '../../../common/js'
1
+ import { isBrowser, envError, throwSSRWarning, successHandle } from '../../../common/js'
2
2
 
3
3
  function setNavigationBarTitle (options = {}) {
4
4
  if (!isBrowser) {
@@ -26,7 +26,10 @@ function setNavigationBarColor (options = {}) {
26
26
  successHandle({ errMsg: 'setNavigationBarColor:ok' }, success, complete)
27
27
  }
28
28
 
29
+ const hideHomeButton = envError('hideHomeButton')
30
+
29
31
  export {
30
32
  setNavigationBarTitle,
31
- setNavigationBarColor
33
+ setNavigationBarColor,
34
+ hideHomeButton
32
35
  }
@@ -0,0 +1,19 @@
1
+ import { ENV_OBJ, envError } from '../../../common/js'
2
+
3
+ const getSetting = ENV_OBJ.getSetting || envError('getSetting')
4
+
5
+ const openSetting = ENV_OBJ.openSetting || envError('openSetting')
6
+
7
+ const enableAlertBeforeUnload = ENV_OBJ.enableAlertBeforeUnload || envError('enableAlertBeforeUnload')
8
+
9
+ const disableAlertBeforeUnload = ENV_OBJ.disableAlertBeforeUnload || envError('disableAlertBeforeUnload')
10
+
11
+ const getMenuButtonBoundingClientRect = ENV_OBJ.getMenuButtonBoundingClientRect || envError('getMenuButtonBoundingClientRect')
12
+
13
+ export {
14
+ getSetting,
15
+ openSetting,
16
+ enableAlertBeforeUnload,
17
+ disableAlertBeforeUnload,
18
+ getMenuButtonBoundingClientRect
19
+ }
@@ -1 +1,84 @@
1
- export * from './rnSystem'
1
+ import DeviceInfo from 'react-native-device-info'
2
+ import { PixelRatio } from 'react-native'
3
+ import { successHandle, failHandle, defineUnsupportedProps } from '../../../common/js'
4
+ import { getWindowInfo, getLaunchOptionsSync, getEnterOptionsSync } from './rnSystem'
5
+
6
+ const getSystemInfoSync = function () {
7
+ const windowInfo = getWindowInfo()
8
+ const { screenWidth, screenHeight } = windowInfo
9
+
10
+ const result = {
11
+ brand: DeviceInfo.getBrand(),
12
+ model: DeviceInfo.getModel(),
13
+ system: `${DeviceInfo.getSystemName()} ${DeviceInfo.getSystemVersion()}`,
14
+ platform: DeviceInfo.isEmulatorSync() ? 'emulator' : DeviceInfo.getSystemName(),
15
+ deviceOrientation: screenWidth > screenHeight ? 'portrait' : 'landscape',
16
+ fontSizeSetting: PixelRatio.getFontScale()
17
+ }
18
+ Object.assign(result, windowInfo)
19
+ defineUnsupportedProps(result, [
20
+ 'language',
21
+ 'version',
22
+ 'SDKVersion',
23
+ 'benchmarkLevel',
24
+ 'albumAuthorized',
25
+ 'cameraAuthorized',
26
+ 'locationAuthorized',
27
+ 'microphoneAuthorized',
28
+ 'notificationAuthorized',
29
+ 'phoneCalendarAuthorized',
30
+ 'host',
31
+ 'enableDebug',
32
+ 'notificationAlertAuthorized',
33
+ 'notificationBadgeAuthorized',
34
+ 'notificationSoundAuthorized',
35
+ 'bluetoothEnabled',
36
+ 'locationEnabled',
37
+ 'wifiEnabled',
38
+ 'locationReducedAccuracy',
39
+ 'theme'
40
+ ])
41
+ return result
42
+ }
43
+
44
+ const getSystemInfo = function (options = {}) {
45
+ const { success, fail, complete } = options
46
+ try {
47
+ const systemInfo = getSystemInfoSync()
48
+ Object.assign(systemInfo, {
49
+ errMsg: 'setStorage:ok'
50
+ })
51
+ successHandle(systemInfo, success, complete)
52
+ } catch (err) {
53
+ const result = {
54
+ errMsg: `getSystemInfo:fail ${err}`
55
+ }
56
+ failHandle(result, fail, complete)
57
+ }
58
+ }
59
+
60
+ const getDeviceInfo = function () {
61
+ const deviceInfo = {}
62
+ if (__mpx_mode__ === 'android') {
63
+ const deviceAbi = DeviceInfo.supported64BitAbisSync() || []
64
+ deviceInfo.deviceAbi = deviceAbi[0] || null
65
+ }
66
+ defineUnsupportedProps(deviceInfo, ['benchmarkLevel', 'abi', 'cpuType'])
67
+ Object.assign(deviceInfo, {
68
+ brand: DeviceInfo.getBrand(),
69
+ model: DeviceInfo.getModel(),
70
+ system: `${DeviceInfo.getSystemName()} ${DeviceInfo.getSystemVersion()}`,
71
+ platform: DeviceInfo.isEmulatorSync() ? 'emulator' : DeviceInfo.getSystemName(),
72
+ memorySize: DeviceInfo.getTotalMemorySync() / (1024 * 1024)
73
+ })
74
+ return deviceInfo
75
+ }
76
+
77
+ export {
78
+ getSystemInfo,
79
+ getSystemInfoSync,
80
+ getDeviceInfo,
81
+ getWindowInfo,
82
+ getLaunchOptionsSync,
83
+ getEnterOptionsSync
84
+ }
@@ -139,7 +139,7 @@ const getLaunchOptionsSync = function () {
139
139
  throwSSRWarning('getLaunchOptionsSync API is running in non browser environments')
140
140
  return
141
141
  }
142
- return global.__mpxEnterOptions || {}
142
+ return global.__mpxLaunchOptions || {}
143
143
  }
144
144
 
145
145
  export {
@@ -1,98 +1,54 @@
1
- import DeviceInfo from 'react-native-device-info'
2
- import { PixelRatio } from 'react-native'
3
- import { successHandle, failHandle, defineUnsupportedProps } from '../../../common/js'
4
- import { getWindowInfo } from './rnWindowInfo'
1
+ import { PixelRatio, Dimensions } from 'react-native'
2
+ import { initialWindowMetrics } from 'react-native-safe-area-context'
3
+ import { getFocusedNavigation } from '../../../common/js'
5
4
 
6
- const getSystemInfoSync = function () {
7
- const windowInfo = getWindowInfo()
8
- const { screenWidth, screenHeight } = windowInfo
9
-
10
- const result = {
11
- brand: DeviceInfo.getBrand(),
12
- model: DeviceInfo.getModel(),
13
- system: `${DeviceInfo.getSystemName()} ${DeviceInfo.getSystemVersion()}`,
14
- platform: DeviceInfo.isEmulatorSync() ? 'emulator' : DeviceInfo.getSystemName(),
15
- deviceOrientation: screenWidth > screenHeight ? 'portrait' : 'landscape',
16
- fontSizeSetting: PixelRatio.getFontScale()
17
- }
18
- Object.assign(result, windowInfo)
19
- defineUnsupportedProps(result, [
20
- 'language',
21
- 'version',
22
- 'SDKVersion',
23
- 'benchmarkLevel',
24
- 'albumAuthorized',
25
- 'cameraAuthorized',
26
- 'locationAuthorized',
27
- 'microphoneAuthorized',
28
- 'notificationAuthorized',
29
- 'phoneCalendarAuthorized',
30
- 'host',
31
- 'enableDebug',
32
- 'notificationAlertAuthorized',
33
- 'notificationBadgeAuthorized',
34
- 'notificationSoundAuthorized',
35
- 'bluetoothEnabled',
36
- 'locationEnabled',
37
- 'wifiEnabled',
38
- 'locationReducedAccuracy',
39
- 'theme'
40
- ])
41
- return result
42
- }
43
-
44
- const getSystemInfo = function (options = {}) {
45
- const { success, fail, complete } = options
5
+ const getWindowInfo = function () {
6
+ const dimensionsScreen = Dimensions.get('screen')
7
+ const navigation = getFocusedNavigation() || {}
8
+ const initialWindowMetricsInset = initialWindowMetrics?.insets || {}
9
+ const navigationInsets = navigation.insets || {}
10
+ const insets = Object.assign(initialWindowMetricsInset, navigationInsets)
11
+ let safeArea = {}
12
+ const { top = 0, bottom = 0, left = 0, right = 0 } = insets
13
+ const screenHeight = __mpx_mode__ === 'ios' ? dimensionsScreen.height : dimensionsScreen.height - bottom // 解决安卓开启屏幕内三建导航安卓把安全区计算进去后产生的影响
14
+ const screenWidth = __mpx_mode__ === 'ios' ? dimensionsScreen.width : dimensionsScreen.width - right
15
+ const layout = navigation.layout || {}
16
+ const layoutHeight = layout.height || 0
17
+ const layoutWidth = layout.width || 0
18
+ const windowHeight = layoutHeight || screenHeight
46
19
  try {
47
- const systemInfo = getSystemInfoSync()
48
- Object.assign(systemInfo, {
49
- errMsg: 'setStorage:ok'
50
- })
51
- successHandle(systemInfo, success, complete)
52
- } catch (err) {
53
- const result = {
54
- errMsg: `getSystemInfo:fail ${err}`
20
+ safeArea = {
21
+ left,
22
+ right: screenWidth - right,
23
+ top,
24
+ bottom: screenHeight - bottom,
25
+ height: screenHeight - top - bottom,
26
+ width: screenWidth - left - right
55
27
  }
56
- failHandle(result, fail, complete)
28
+ } catch (error) {
57
29
  }
58
- }
59
-
60
- const getDeviceInfo = function () {
61
- const deviceInfo = {}
62
- if (__mpx_mode__ === 'android') {
63
- const deviceAbi = DeviceInfo.supported64BitAbisSync() || []
64
- deviceInfo.deviceAbi = deviceAbi[0] || null
30
+ const result = {
31
+ pixelRatio: PixelRatio.get(),
32
+ windowWidth: layoutWidth || screenWidth,
33
+ windowHeight, // 取不到layout的时候有个兜底
34
+ screenWidth: screenWidth,
35
+ screenHeight: screenHeight,
36
+ screenTop: screenHeight - windowHeight,
37
+ statusBarHeight: safeArea.top,
38
+ safeArea
65
39
  }
66
- defineUnsupportedProps(deviceInfo, ['benchmarkLevel', 'abi', 'cpuType'])
67
- Object.assign(deviceInfo, {
68
- brand: DeviceInfo.getBrand(),
69
- model: DeviceInfo.getModel(),
70
- system: `${DeviceInfo.getSystemName()} ${DeviceInfo.getSystemVersion()}`,
71
- platform: DeviceInfo.isEmulatorSync() ? 'emulator' : DeviceInfo.getSystemName(),
72
- memorySize: DeviceInfo.getTotalMemorySync() / (1024 * 1024)
73
- })
74
- return deviceInfo
40
+ return result
75
41
  }
76
42
 
77
43
  const getLaunchOptionsSync = function () {
78
- const options = global.__mpxEnterOptions || {}
79
- const { path, scene, query } = options
80
- return {
81
- path,
82
- scene,
83
- query
84
- }
44
+ return global.__mpxLaunchOptions || {}
85
45
  }
86
46
 
87
47
  const getEnterOptionsSync = function () {
88
- const result = getLaunchOptionsSync()
89
- return result
48
+ return global.__mpxEnterOptions || {}
90
49
  }
91
50
 
92
51
  export {
93
- getSystemInfo,
94
- getSystemInfoSync,
95
- getDeviceInfo,
96
52
  getWindowInfo,
97
53
  getLaunchOptionsSync,
98
54
  getEnterOptionsSync
@@ -1,13 +1,15 @@
1
- import { View, Text, Image, StyleSheet, ActivityIndicator } from 'react-native'
1
+ import { View, Text, Image, StyleSheet, ActivityIndicator, Dimensions } from 'react-native'
2
2
  import { successHandle, failHandle } from '../../../common/js'
3
3
  import { Portal } from '@ant-design/react-native'
4
4
 
5
5
  let toastKey
6
6
  let isLoadingShow
7
+ const dimensionsScreen = Dimensions.get('screen')
8
+ const screenHeight = dimensionsScreen.height
9
+ const contentTop = parseInt(screenHeight * 0.35)
7
10
  let tId // show duration 计时id
8
11
  const styles = StyleSheet.create({
9
12
  toastContent: {
10
- minWdth: 150,
11
13
  maxWidth: '60%',
12
14
  backgroundColor: 'rgba(20, 20, 20, 0.7)',
13
15
  paddingTop: 15,
@@ -18,7 +20,8 @@ const styles = StyleSheet.create({
18
20
  display: 'flex',
19
21
  flexDirection: 'column',
20
22
  justifyContent: 'center',
21
- alignItems: 'center'
23
+ alignItems: 'center',
24
+ marginTop: contentTop // 小程序里面展示偏上一点
22
25
  },
23
26
  toastWrap: {
24
27
  left: 0,
@@ -28,25 +31,29 @@ const styles = StyleSheet.create({
28
31
  zIndex: 10000,
29
32
  position: "absolute",
30
33
  display: 'flex',
31
- justifyContent: 'center',
32
34
  alignItems: 'center'
33
35
  },
36
+ toastHasIcon: {
37
+ height: 110,
38
+ width: 120
39
+ },
34
40
  toastImg: {
35
41
  width: 40,
36
42
  height: 40,
37
43
  marginLeft: 'auto',
38
- marginRight: 'auto',
39
- marginBottom: 10
44
+ marginRight: 'auto'
40
45
  },
41
46
  toastText: {
42
47
  textAlign: 'center',
43
48
  color: '#ffffff',
44
- fontSize: 14,
49
+ fontSize: 12,
45
50
  lineHeight: 18,
46
51
  height: 18,
47
- overflow: 'hidden'
52
+ overflow: 'hidden',
53
+ marginTop: 10
48
54
  }
49
55
  })
56
+
50
57
  function showToast (options = {}) {
51
58
  const { title, icon = 'success', image, duration = 1500, mask = false, success, fail, complete, isLoading } = options
52
59
  let ToastView
@@ -64,29 +71,29 @@ function showToast (options = {}) {
64
71
  tId = null
65
72
  if (image || icon === 'success' || icon === 'error') {
66
73
  ToastView = <View style={styles.toastWrap} pointerEvents={pointerEvents}>
67
- <View style={styles.toastContent}>
74
+ <View style={[styles.toastContent, styles.toastHasIcon]}>
68
75
  <Image style={ styles.toastImg } source={{uri: image || iconImg[icon]}}></Image>
69
- <Text style={styles.toastText}>{title}</Text>
76
+ { title ? <Text style={styles.toastText}>{title}</Text> : null }
70
77
  </View>
71
78
  </View>
72
79
  } else if (icon === 'loading') {
73
80
  ToastView = <View style={styles.toastWrap} pointerEvents={pointerEvents}>
74
- <View style={styles.toastContent}>
81
+ <View style={[styles.toastContent, styles.toastHasIcon]}>
75
82
  <ActivityIndicator
76
83
  animating
77
- style={{ marginBottom: 10 }}
78
84
  size='small'
79
85
  color='#eee'
80
86
  />
81
- <Text style={styles.toastText}>{title}</Text>
87
+ { title ? <Text style={styles.toastText}>{title}</Text> : null }
82
88
  </View>
83
89
  </View>
84
90
  } else {
85
91
  ToastView = <View style={styles.toastWrap} pointerEvents={pointerEvents}>
86
92
  <View style={styles.toastContent}>
87
- <Text numberOfLines={2} style={{ ...styles.toastText, ...(icon === 'none' ? {
88
- height: 36
89
- } : {}) }}>{title}</Text>
93
+ { title ? <Text numberOfLines={2} style={{ ...styles.toastText, ...(icon === 'none' ? {
94
+ height: 'auto',
95
+ marginTop: 0
96
+ } : {}) }}>{title}</Text> : null }
90
97
  </View>
91
98
  </View>
92
99
  }
@@ -43,7 +43,7 @@ export * from './api/file'
43
43
  // getUserInfo
44
44
  export * from './api/get-user-info'
45
45
 
46
- // previewImage, compressImage
46
+ // previewImage, compressImage, getImageInfo
47
47
  export * from './api/image'
48
48
 
49
49
  // login
@@ -116,3 +116,6 @@ export * from './api/vibrate'
116
116
 
117
117
  // onKeyboardHeightChange, offKeyboardHeightChange, hideKeyboard
118
118
  export * from './api/keyboard'
119
+
120
+ // getSetting, openSetting, enableAlertBeforeUnload, disableAlertBeforeUnload, getMenuButtonBoundingClientRect
121
+ export * from './api/setting'
@@ -1,42 +0,0 @@
1
- import { PixelRatio, Dimensions } from 'react-native'
2
- import { initialWindowMetrics } from 'react-native-safe-area-context'
3
- import { getFocusedNavigation } from '../../../common/js'
4
-
5
- const getWindowInfo = function () {
6
- const dimensionsScreen = Dimensions.get('screen')
7
- const navigation = getFocusedNavigation()
8
- const insets = Object.assign(initialWindowMetrics?.insets, navigation?.insets)
9
- let safeArea = {}
10
- const { top = 0, bottom = 0, left = 0, right = 0 } = insets
11
- const screenHeight = dimensionsScreen.height
12
- const screenWidth = dimensionsScreen.width
13
- const layout = navigation?.layout || {}
14
- const layoutHeight = layout.height || 0
15
- const layoutWidth = layout.width || 0
16
- const windowHeight = layoutHeight || screenHeight
17
- try {
18
- safeArea = {
19
- left,
20
- right: screenWidth - right,
21
- top,
22
- bottom: screenHeight - bottom,
23
- height: screenHeight - top - bottom,
24
- width: screenWidth - left - right
25
- }
26
- } catch (error) {
27
- }
28
- const result = {
29
- pixelRatio: PixelRatio.get(),
30
- windowWidth: layoutWidth || screenWidth,
31
- windowHeight, // 取不到layout的时候有个兜底
32
- screenWidth: screenWidth,
33
- screenHeight: screenHeight,
34
- screenTop: screenHeight - windowHeight,
35
- safeArea
36
- }
37
- return result
38
- }
39
-
40
- export {
41
- getWindowInfo
42
- }