1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_INTERFACES_OBSERVER_LISTENER_H 17 #define FOUNDATION_ACE_INTERFACES_OBSERVER_LISTENER_H 18 19 #include "napi/native_api.h" 20 #include "napi/native_common.h" 21 #include "napi/native_node_api.h" 22 23 #include "core/components_ng/base/observer_handler.h" 24 25 namespace OHOS::Ace::Napi { 26 class UIObserverListener { 27 public: UIObserverListener(napi_env env,napi_value callback)28 UIObserverListener(napi_env env, napi_value callback) : env_(env) 29 { 30 napi_create_reference(env_, callback, 1, &callback_); 31 } ~UIObserverListener()32 ~UIObserverListener() 33 { 34 if (callback_) { 35 napi_delete_reference(env_, callback_); 36 } 37 } 38 void OnNavigationStateChange(const NG::NavDestinationInfo& info); 39 void OnScrollEventStateChange( 40 const std::string& id, int32_t uniqueId, NG::ScrollEventType eventType, float offset); 41 void OnRouterPageStateChange(const NG::RouterPageInfoNG& pageInfo); 42 void OnDensityChange(double density); 43 void OnWillClick(const GestureEvent& gestureEventInfo, const ClickInfo& clickInfo, 44 const RefPtr<NG::FrameNode> frameNode); 45 void OnDidClick(const GestureEvent& gestureEventInfo, const ClickInfo& clickInfo, 46 const RefPtr<NG::FrameNode> frameNode); 47 void OnTabContentStateChange(const NG::TabContentInfo& tabContentInfo); 48 void OnNavDestinationSwitch(const NG::NavDestinationSwitchInfo& switchInfo); 49 bool NapiEqual(napi_value cb); 50 void OnDrawOrLayout(); 51 52 private: 53 napi_value CreateNavDestinationSwitchInfoObj(const NG::NavDestinationSwitchInfo& switchInfo); 54 napi_value CreateNavDestinationInfoObj(const NG::NavDestinationInfo& info); 55 napi_value GetNapiCallback(); 56 static napi_valuetype GetValueType(napi_env env, napi_value value); 57 static napi_value GetNamedProperty(napi_env env, napi_value object, const std::string& propertyName); 58 void AddBaseEventInfo(napi_value objValueClickEvent, const ClickInfo& clickInfo); 59 void AddGestureEventInfoOne(napi_value objValueClickEvent, const GestureEvent& gestureEventInfo); 60 void AddGestureEventInfoTwo(napi_value objValueClickEvent, const GestureEvent& gestureEventInfo); 61 void AddGestureEventInfoThree(napi_value objValueClickEvent, const GestureEvent& gestureEventInfo); 62 void AddFingerListInfo(napi_value objValueClickEvent, const GestureEvent& gestureEventInfo); 63 void AddClickEventInfoOne(napi_value objValueClickEvent, const ClickInfo& clickInfo); 64 void AddClickEventInfoTwo(napi_value objValueClickEvent, const ClickInfo& clickInfo); 65 void AddTargetObject(napi_value objValueClickEvent, const ClickInfo& clickInfo); 66 napi_env env_ = nullptr; 67 napi_ref callback_ = nullptr; 68 }; 69 } // namespace OHOS::Ace::Napi 70 71 #endif // FOUNDATION_ACE_INTERFACES_OBSERVER_LISTENER_H 72