fix orientation-change can not work normally (#16774)

* fix orientation-change can not work normally
This commit is contained in:
bofeng-song
2024-03-22 09:27:54 +08:00
committed by GitHub
parent 559bfc9467
commit 5da2f9b63a
9 changed files with 167 additions and 30 deletions
@@ -40,6 +40,7 @@ se::Object *jsKeyboardEventObj = nullptr;
se::Object *jsControllerEventArray = nullptr;
se::Object *jsControllerChangeEventArray = nullptr;
se::Object *jsResizeEventObj = nullptr;
se::Object *jsOrientationChangeObj = nullptr;
bool inited = false;
bool busListenerInited = false;
@@ -145,6 +146,12 @@ void EventDispatcher::destroy() {
jsResizeEventObj = nullptr;
}
if (jsOrientationChangeObj != nullptr) {
jsOrientationChangeObj->unroot();
jsOrientationChangeObj->decRef();
jsOrientationChangeObj = nullptr;
}
inited = false;
tickVal.setUndefined();
}
@@ -412,7 +419,17 @@ void EventDispatcher::dispatchResizeEvent(int width, int height, uint32_t window
}
void EventDispatcher::dispatchOrientationChangeEvent(int orientation) {
// Ts's logic is same as the 'onResize', so remove code here temporary.
se::AutoHandleScope scope;
if (!jsOrientationChangeObj) {
jsOrientationChangeObj = se::Object::createPlainObject();
jsOrientationChangeObj->root();
}
jsOrientationChangeObj->setProperty("orientation", se::Value(orientation));
se::ValueArray args;
args.emplace_back(se::Value(jsOrientationChangeObj));
EventDispatcher::doDispatchJsEvent("onOrientationChanged", args);
}
void EventDispatcher::dispatchEnterBackgroundEvent() {