mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-06 11:31:59 +08:00
fix orientation-change can not work normally (#16774)
* fix orientation-change can not work normally
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user