Skip to content

Commit

Permalink
Merge branch 'master' into fix-forceupdate-data-change
Browse files Browse the repository at this point in the history
hiyuki authored Dec 12, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents a45b6ed + 640ec45 commit b9794d6
Showing 8 changed files with 159 additions and 141 deletions.
14 changes: 11 additions & 3 deletions packages/api-proxy/src/common/js/promisify.js
Original file line number Diff line number Diff line change
@@ -70,14 +70,22 @@ function promisify (listObj, whiteList, customBlackList) {
result[key] = function (...args) {
const obj = args[0] || {}
// 不需要转换 or 用户已定义回调,则不处理
if (!promisifyFilter(key) || obj.success || obj.fail) {
if (!promisifyFilter(key)) {
return listObj[key].apply(ENV_OBJ, args)
} else { // 其他情况进行转换
if (!args[0]) args.unshift(obj)
let returned
const promise = new Promise((resolve, reject) => {
obj.success = resolve
obj.fail = reject
const originSuccess = obj.success
const originFail = obj.fail
obj.success = function (res) {
originSuccess && originSuccess.call(this, res)
resolve(res)
}
obj.fail = function (e) {
originFail && originFail.call(this, e)
reject(e)
}
returned = listObj[key].apply(ENV_OBJ, args)
})
promise.__returned = returned
Original file line number Diff line number Diff line change
@@ -85,7 +85,7 @@ class RNIntersectionObserver {

_getWindowRect () {
if (this.windowRect) return this.windowRect
const navigation = getFocusedNavigation()
const navigation = getFocusedNavigation() || {}
const screen = Dimensions.get('screen')
const navigationLayout = navigation.layout || {
x: 0,
5 changes: 2 additions & 3 deletions packages/api-proxy/src/platform/api/request/index.web.js
Original file line number Diff line number Diff line change
@@ -107,10 +107,9 @@ function request (options = { url: '' }) {
errMsg: `request:fail ${err}`,
statusCode: response.status,
header: response.headers,
data: response.data,
stack: realError.stack,
...realError
data: response.data
}
Object.assign(res, realError)
failHandle(res, fail, complete)
})

Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ function setNavigationBarTitle (options = {}) {
failHandle({ errMsg: 'setNavigationBarTitle:fail' }, fail, complete)
} else {
nextTick(() => {
navigation.setOptions({ headerTitle: title })
navigation.setOptions({ title })
successHandle({ errMsg: 'setNavigationBarTitle:ok' }, success, complete)
})
}
85 changes: 84 additions & 1 deletion packages/api-proxy/src/platform/api/system/index.ios.js
Original file line number Diff line number Diff line change
@@ -1 +1,84 @@
export * from './rnSystem'
import DeviceInfo from 'react-native-device-info'
import { PixelRatio } from 'react-native'
import { successHandle, failHandle, defineUnsupportedProps } from '../../../common/js'
import { getWindowInfo, getLaunchOptionsSync, getEnterOptionsSync } from './rnSystem'

const getSystemInfoSync = function () {
const windowInfo = getWindowInfo()
const { screenWidth, screenHeight } = windowInfo

const result = {
brand: DeviceInfo.getBrand(),
model: DeviceInfo.getModel(),
system: `${DeviceInfo.getSystemName()} ${DeviceInfo.getSystemVersion()}`,
platform: DeviceInfo.isEmulatorSync() ? 'emulator' : DeviceInfo.getSystemName(),
deviceOrientation: screenWidth > screenHeight ? 'portrait' : 'landscape',
fontSizeSetting: PixelRatio.getFontScale()
}
Object.assign(result, windowInfo)
defineUnsupportedProps(result, [
'language',
'version',
'SDKVersion',
'benchmarkLevel',
'albumAuthorized',
'cameraAuthorized',
'locationAuthorized',
'microphoneAuthorized',
'notificationAuthorized',
'phoneCalendarAuthorized',
'host',
'enableDebug',
'notificationAlertAuthorized',
'notificationBadgeAuthorized',
'notificationSoundAuthorized',
'bluetoothEnabled',
'locationEnabled',
'wifiEnabled',
'locationReducedAccuracy',
'theme'
])
return result
}

const getSystemInfo = function (options = {}) {
const { success, fail, complete } = options
try {
const systemInfo = getSystemInfoSync()
Object.assign(systemInfo, {
errMsg: 'setStorage:ok'
})
successHandle(systemInfo, success, complete)
} catch (err) {
const result = {
errMsg: `getSystemInfo:fail ${err}`
}
failHandle(result, fail, complete)
}
}

const getDeviceInfo = function () {
const deviceInfo = {}
if (__mpx_mode__ === 'android') {
const deviceAbi = DeviceInfo.supported64BitAbisSync() || []
deviceInfo.deviceAbi = deviceAbi[0] || null
}
defineUnsupportedProps(deviceInfo, ['benchmarkLevel', 'abi', 'cpuType'])
Object.assign(deviceInfo, {
brand: DeviceInfo.getBrand(),
model: DeviceInfo.getModel(),
system: `${DeviceInfo.getSystemName()} ${DeviceInfo.getSystemVersion()}`,
platform: DeviceInfo.isEmulatorSync() ? 'emulator' : DeviceInfo.getSystemName(),
memorySize: DeviceInfo.getTotalMemorySync() / (1024 * 1024)
})
return deviceInfo
}

export {
getSystemInfo,
getSystemInfoSync,
getDeviceInfo,
getWindowInfo,
getLaunchOptionsSync,
getEnterOptionsSync
}
107 changes: 35 additions & 72 deletions packages/api-proxy/src/platform/api/system/rnSystem.js
Original file line number Diff line number Diff line change
@@ -1,77 +1,43 @@
import DeviceInfo from 'react-native-device-info'
import { PixelRatio } from 'react-native'
import { successHandle, failHandle, defineUnsupportedProps } from '../../../common/js'
import { getWindowInfo } from './rnWindowInfo'
import { PixelRatio, Dimensions } from 'react-native'
import { initialWindowMetrics } from 'react-native-safe-area-context'
import { getFocusedNavigation } from '../../../common/js'

const getSystemInfoSync = function () {
const windowInfo = getWindowInfo()
const { screenWidth, screenHeight } = windowInfo

const result = {
brand: DeviceInfo.getBrand(),
model: DeviceInfo.getModel(),
system: `${DeviceInfo.getSystemName()} ${DeviceInfo.getSystemVersion()}`,
platform: DeviceInfo.isEmulatorSync() ? 'emulator' : DeviceInfo.getSystemName(),
deviceOrientation: screenWidth > screenHeight ? 'portrait' : 'landscape',
fontSizeSetting: PixelRatio.getFontScale()
}
Object.assign(result, windowInfo)
defineUnsupportedProps(result, [
'language',
'version',
'SDKVersion',
'benchmarkLevel',
'albumAuthorized',
'cameraAuthorized',
'locationAuthorized',
'microphoneAuthorized',
'notificationAuthorized',
'phoneCalendarAuthorized',
'host',
'enableDebug',
'notificationAlertAuthorized',
'notificationBadgeAuthorized',
'notificationSoundAuthorized',
'bluetoothEnabled',
'locationEnabled',
'wifiEnabled',
'locationReducedAccuracy',
'theme'
])
return result
}

const getSystemInfo = function (options = {}) {
const { success, fail, complete } = options
const getWindowInfo = function () {
const dimensionsScreen = Dimensions.get('screen')
const navigation = getFocusedNavigation() || {}
const initialWindowMetricsInset = initialWindowMetrics?.insets || {}
const navigationInsets = navigation.insets || {}
const insets = Object.assign(initialWindowMetricsInset, navigationInsets)
let safeArea = {}
const { top = 0, bottom = 0, left = 0, right = 0 } = insets
const screenHeight = dimensionsScreen.height
const screenWidth = dimensionsScreen.width
const layout = navigation.layout || {}
const layoutHeight = layout.height || 0
const layoutWidth = layout.width || 0
const windowHeight = layoutHeight || screenHeight
try {
const systemInfo = getSystemInfoSync()
Object.assign(systemInfo, {
errMsg: 'setStorage:ok'
})
successHandle(systemInfo, success, complete)
} catch (err) {
const result = {
errMsg: `getSystemInfo:fail ${err}`
safeArea = {
left,
right: screenWidth - right,
top,
bottom: screenHeight - bottom,
height: screenHeight - top - bottom,
width: screenWidth - left - right
}
failHandle(result, fail, complete)
} catch (error) {
}
}

const getDeviceInfo = function () {
const deviceInfo = {}
if (__mpx_mode__ === 'android') {
const deviceAbi = DeviceInfo.supported64BitAbisSync() || []
deviceInfo.deviceAbi = deviceAbi[0] || null
const result = {
pixelRatio: PixelRatio.get(),
windowWidth: layoutWidth || screenWidth,
windowHeight, // 取不到layout的时候有个兜底
screenWidth: screenWidth,
screenHeight: screenHeight,
screenTop: screenHeight - windowHeight,
statusBarHeight: safeArea.top,
safeArea
}
defineUnsupportedProps(deviceInfo, ['benchmarkLevel', 'abi', 'cpuType'])
Object.assign(deviceInfo, {
brand: DeviceInfo.getBrand(),
model: DeviceInfo.getModel(),
system: `${DeviceInfo.getSystemName()} ${DeviceInfo.getSystemVersion()}`,
platform: DeviceInfo.isEmulatorSync() ? 'emulator' : DeviceInfo.getSystemName(),
memorySize: DeviceInfo.getTotalMemorySync() / (1024 * 1024)
})
return deviceInfo
return result
}

const getLaunchOptionsSync = function () {
@@ -90,9 +56,6 @@ const getEnterOptionsSync = function () {
}

export {
getSystemInfo,
getSystemInfoSync,
getDeviceInfo,
getWindowInfo,
getLaunchOptionsSync,
getEnterOptionsSync
42 changes: 0 additions & 42 deletions packages/api-proxy/src/platform/api/system/rnWindowInfo.js

This file was deleted.

43 changes: 25 additions & 18 deletions packages/api-proxy/src/platform/api/toast/rnToast.jsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import { View, Text, Image, StyleSheet, ActivityIndicator } from 'react-native'
import { View, Text, Image, StyleSheet, ActivityIndicator, Dimensions } from 'react-native'
import { successHandle, failHandle } from '../../../common/js'
import { Portal } from '@ant-design/react-native'

let toastKey
let isLoadingShow
const dimensionsScreen = Dimensions.get('screen')
const screenHeight = dimensionsScreen.height
const contentTop = parseInt(screenHeight * 0.35)
let tId // show duration 计时id
const styles = StyleSheet.create({
toastContent: {
minWdth: 150,
maxWidth: '60%',
backgroundColor: 'rgba(20, 20, 20, 0.7)',
paddingTop: 15,
paddingBottom: 15,
paddingLeft: 20,
paddingRight: 20,
paddingLeft: 10,
paddingRight: 10,
borderRadius: 5,
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center'
alignItems: 'center',
marginTop: contentTop // 小程序里面展示偏上一点
},
toastWrap: {
left: 0,
@@ -28,25 +31,29 @@ const styles = StyleSheet.create({
zIndex: 10000,
position: "absolute",
display: 'flex',
justifyContent: 'center',
alignItems: 'center'
},
toastHasIcon: {
height: 110,
width: 120
},
toastImg: {
width: 40,
height: 40,
marginLeft: 'auto',
marginRight: 'auto',
marginBottom: 10
marginRight: 'auto'
},
toastText: {
textAlign: 'center',
color: '#ffffff',
fontSize: 14,
fontSize: 12,
lineHeight: 18,
height: 18,
overflow: 'hidden'
overflow: 'hidden',
marginTop: 10
}
})

function showToast (options = {}) {
const { title, icon = 'success', image, duration = 1500, mask = false, success, fail, complete, isLoading } = options
let ToastView
@@ -64,29 +71,29 @@ function showToast (options = {}) {
tId = null
if (image || icon === 'success' || icon === 'error') {
ToastView = <View style={styles.toastWrap} pointerEvents={pointerEvents}>
<View style={styles.toastContent}>
<View style={[styles.toastContent, styles.toastHasIcon]}>
<Image style={ styles.toastImg } source={{uri: image || iconImg[icon]}}></Image>
<Text style={styles.toastText}>{title}</Text>
{ title ? <Text style={styles.toastText}>{title}</Text> : null }
</View>
</View>
} else if (icon === 'loading') {
ToastView = <View style={styles.toastWrap} pointerEvents={pointerEvents}>
<View style={styles.toastContent}>
<View style={[styles.toastContent, styles.toastHasIcon]}>
<ActivityIndicator
animating
style={{ marginBottom: 10 }}
size='small'
color='#eee'
/>
<Text style={styles.toastText}>{title}</Text>
{ title ? <Text style={styles.toastText}>{title}</Text> : null }
</View>
</View>
} else {
ToastView = <View style={styles.toastWrap} pointerEvents={pointerEvents}>
<View style={styles.toastContent}>
<Text numberOfLines={2} style={{ ...styles.toastText, ...(icon === 'none' ? {
height: 36
} : {}) }}>{title}</Text>
{ title ? <Text numberOfLines={2} style={{ ...styles.toastText, ...(icon === 'none' ? {
height: 'auto',
marginTop: 0
} : {}) }}>{title}</Text> : null }
</View>
</View>
}

0 comments on commit b9794d6

Please sign in to comment.