Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the issue where the return value of getSafeArea in WeChat may be undefined. #17831

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion pal/minigame/wechat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
// update cached system info
_cachedSystemInfo = wx.getSystemInfoSync() as SystemInfo;
});
minigame.getSystemInfoSync = function (): SystemInfo {

Check warning on line 71 in pal/minigame/wechat.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
return _cachedSystemInfo;
};

Expand Down Expand Up @@ -107,7 +107,7 @@

// #region Accelerometer
let _accelerometerCb: AccelerometerChangeCallback | undefined;
minigame.onAccelerometerChange = function (cb: AccelerometerChangeCallback): void {

Check warning on line 110 in pal/minigame/wechat.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
minigame.offAccelerometerChange();
// onAccelerometerChange would start accelerometer
// so we won't call this method here
Expand All @@ -129,13 +129,13 @@
cb(resClone);
};
};
minigame.offAccelerometerChange = function (cb?: AccelerometerChangeCallback): void {

Check warning on line 132 in pal/minigame/wechat.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
if (_accelerometerCb) {
wx.offAccelerometerChange(_accelerometerCb);
_accelerometerCb = undefined;
}
};
minigame.startAccelerometer = function (res: any): void {

Check warning on line 138 in pal/minigame/wechat.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
if (_accelerometerCb) {
wx.onAccelerometerChange(_accelerometerCb);
}
Expand All @@ -152,9 +152,20 @@

// #region SafeArea
// FIX_ME: wrong safe area when orientation is landscape left
minigame.getSafeArea = function (): SafeArea {

Check warning on line 155 in pal/minigame/wechat.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
const locSystemInfo = wx.getSystemInfoSync() as SystemInfo;
return locSystemInfo.safeArea;
let safeArea = locSystemInfo.safeArea;
if (!safeArea) {
safeArea = {
left: 0,
top: 0,
bottom: systemInfo.screenHeight,
right: systemInfo.screenWidth,
width: systemInfo.screenWidth,
height: systemInfo.screenHeight,
};
}
return safeArea;
};
// #endregion SafeArea

Expand All @@ -166,7 +177,7 @@
if (locCanvas) {
const webglRC = locCanvas.getContext('webgl');
const originalUseProgram = webglRC.useProgram.bind(webglRC);
webglRC.useProgram = function (program): void {

Check warning on line 180 in pal/minigame/wechat.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
if (program) {
originalUseProgram(program);
}
Expand Down
13 changes: 12 additions & 1 deletion pal/minigame/wechat_mini_program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,18 @@ minigame.createInnerAudioContext = createInnerAudioContextPolyfill(wx, {
// FIX_ME: wrong safe area when orientation is landscape left
minigame.getSafeArea = (): SafeArea => {
const locSystemInfo = wx.getSystemInfoSync() as SystemInfo;
return locSystemInfo.safeArea;
let safeArea = locSystemInfo.safeArea;
if (!safeArea) {
safeArea = {
left: 0,
top: 0,
bottom: systemInfo.screenHeight,
right: systemInfo.screenWidth,
width: systemInfo.screenWidth,
height: systemInfo.screenHeight,
};
}
return safeArea;
};
// #endregion SafeArea

Expand Down
Loading