Skip to content

Commit

Permalink
Merge branch 'master' into fix-forceupdate-data-change
Browse files Browse the repository at this point in the history
  • Loading branch information
hiyuki authored Dec 12, 2024
2 parents a45b6ed + 640ec45 commit b9794d6
Show file tree
Hide file tree
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
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
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
Expand Up @@ -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)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand Down
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 () {
Expand All @@ -90,9 +56,6 @@ const getEnterOptionsSync = function () {
}

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

This file was deleted.

Loading

0 comments on commit b9794d6

Please sign in to comment.