diff --git a/frameworks/src/core/base/lazy_load_manager.cpp b/frameworks/src/core/base/lazy_load_manager.cpp index 00001f230d775860b85abc2131ec87bef1a97be3..fd6da94174eee79f0fd91567e4275d11b1b53202 100755 --- a/frameworks/src/core/base/lazy_load_manager.cpp +++ b/frameworks/src/core/base/lazy_load_manager.cpp @@ -47,14 +47,15 @@ void LazyLoadManager::RenderLazyLoadWatcher() { LazyLoadWatcher *next = nullptr; while (firstWatcher_ != nullptr) { - Component *componet = ComponentUtils::GetComponentFromBindingObject(firstWatcher_->GetNativeElement()); - if (componet != nullptr) { - componet->AddWatcherItem(firstWatcher_->GetAttrName(), firstWatcher_->GetAttrGetter()); + Component *component = ComponentUtils::GetComponentFromBindingObject(firstWatcher_->GetNativeElement()); + if (component != nullptr) { + component->AddWatcherItem(firstWatcher_->GetAttrName(), firstWatcher_->GetAttrGetter(), true); } next = const_cast(firstWatcher_->GetNext()); delete firstWatcher_; firstWatcher_ = next; } + lastWatcher_ = nullptr; state_ = LazyLoadState::DONE; } @@ -77,6 +78,9 @@ void LazyLoadManager::AddLazyLoadWatcher(jerry_value_t nativeElement, jerry_valu lastWatcher_->SetNext(*watcher); lastWatcher_ = watcher; } + // The state must be ready if any watcher lazy loading request was added, otherwise, in some cases, + // the js_ability may not be able to know there are watchers need to be loaded. + state_ = LazyLoadState::READY; } } // namespace ACELite } // namespace OHOS diff --git a/frameworks/src/core/components/component.cpp b/frameworks/src/core/components/component.cpp index cdf4c1136ef1120a5395e9140e3ecdd7ee0bf114..777b82ab113fbca005a06cab0f004618e2fee9e1 100755 --- a/frameworks/src/core/components/component.cpp +++ b/frameworks/src/core/components/component.cpp @@ -1020,24 +1020,27 @@ int32_t Component::GetAnimatorValue(char *animatorValue, const int8_t index, boo jerry_value_t Component::AddWatcherItem(const jerry_value_t attrKey, const jerry_value_t attrValue, bool isLazyLoading) { -#ifdef FEATURE_LAZY_LOADING_MODULE - isLazyLoading = true; -#endif jerry_value_t options = jerry_create_object(); JerrySetNamedProperty(options, ARG_WATCH_EL, nativeElement_); JerrySetNamedProperty(options, ARG_WATCH_ATTR, attrKey); jerry_value_t watcher = CallJSWatcher(attrValue, WatcherCallbackFunc, options); - jerry_value_t propValue = UNDEFINED; + jerry_release_value(options); if (IS_UNDEFINED(watcher) || jerry_value_is_error(watcher)) { HILOG_ERROR(HILOG_MODULE_ACE, "Failed to create Watcher instance."); - } else { - InsertWatcherCommon(watchersHead_, watcher); - if (!isLazyLoading) { - propValue = jerryx_get_property_str(watcher, "_lastValue"); - } + jerry_release_value(watcher); // release error case, note: release undefined is harmless + return UNDEFINED; } - jerry_release_value(options); - return propValue; + // watcher is valide, insert it to the list + InsertWatcherCommon(watchersHead_, watcher); + if (isLazyLoading) { + // If the watcher creating is lazy loading, need to call watcher's update function to make sure the view + // is updated with latest value properly, because it's the lazy case, the value might be changed already. + JSRelease(JSObject::Call(watcher, "update", nullptr, 0)); + return UNDEFINED; + } + + // is the direct watcher creating, return the lastValue and need to be released out of this function + return jerryx_get_property_str(watcher, "_lastValue"); } void Component::ParseAttrs() diff --git a/frameworks/src/core/context/js_ability.cpp b/frameworks/src/core/context/js_ability.cpp index eef173eb32b85739866fe3daa488b5084454ae11..19edf626b00a9b6bdb56993a0db64623bbd480f9 100644 --- a/frameworks/src/core/context/js_ability.cpp +++ b/frameworks/src/core/context/js_ability.cpp @@ -213,10 +213,6 @@ void JSAbility::HandleRenderTick() // reset error tick tracing count errorTickCount_ = 0; -#if defined(TARGET_SIMULATOR) && defined(FEATURE_LAZY_LOADING_MODULE) - LazyLoadHandleRenderTick(nullptr); -#endif - if ((ProductAdapter::IsTEHandlersRegisted()) && !(FatalHandler::GetInstance().IsAppExiting())) { FatalHandler::GetInstance().SetTEHandlingFlag(true); ProductAdapter::ProcessOneTE(); diff --git a/frameworks/src/core/router/js_page_state_machine.cpp b/frameworks/src/core/router/js_page_state_machine.cpp index 119a8f60d6e79a91e45b29ac8ae914680fae724a..976859647c5300db6f44b13ab5f32bc9f764c926 100755 --- a/frameworks/src/core/router/js_page_state_machine.cpp +++ b/frameworks/src/core/router/js_page_state_machine.cpp @@ -307,16 +307,12 @@ void StateMachine::RenderPage() START_TRACING(RENDER); // if not in init state, reset all watchers of previous page at first LazyLoadManager* lazy = const_cast(appContext_->GetLazyLoadManager()); - if (lazy->GetState() != LazyLoadState::INIT) { + if (lazy != nullptr) { lazy->ResetWatchers(); } // Note: do not release the returned value by Render function, it will be released by component jerry_value_t element = appContext_->Render(viewModel_); - // mark lazy load te task - if (lazy->GetLazyWatcher() != nullptr) { - lazy->SetState(LazyLoadState::READY); - } rootComponent_ = ComponentUtils::GetComponentFromBindingObject(element); // append scroll layer to the outermost view scrollLayer_ = new ScrollLayer(); diff --git a/frameworks/tools/qt/simulator/jsfwk/targets/simulator/acelite_config.h b/frameworks/tools/qt/simulator/jsfwk/targets/simulator/acelite_config.h index fabc7612c34a2007d35c191a5d82cde983e9b9ce..e6c025dcb0a08eaf8fe990e5fb10435f930b6e06 100644 --- a/frameworks/tools/qt/simulator/jsfwk/targets/simulator/acelite_config.h +++ b/frameworks/tools/qt/simulator/jsfwk/targets/simulator/acelite_config.h @@ -93,6 +93,8 @@ #define FEATURE_LOCALIZATION_MODULE #endif // QT_SIMULATOR +#define FEATURE_LAZY_LOADING_MODULE + /** * timer module */