1 /* 2 * Copyright (c) 2025 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 NATIVE_XCOMPONENT_PLUGIN_MANAGER_H 17 #define NATIVE_XCOMPONENT_PLUGIN_MANAGER_H 18 19 #include <arkui/native_gesture.h> 20 #include <arkui/native_node.h> 21 #include <cstdint> 22 #include <string> 23 #include <unordered_map> 24 25 #include <ace/xcomponent/native_interface_xcomponent.h> 26 #include <js_native_api.h> 27 #include <js_native_api_types.h> 28 #include <napi/native_api.h> 29 30 #include "container.h" 31 namespace NativeXComponentSample { 32 const int MAX_SIZE = 11; 33 class Manager { 34 public: 35 ~Manager(); 36 GetInstance()37 static Manager *GetInstance() { return &Manager::manager_; } 38 39 static napi_value GetContext(napi_env env, napi_callback_info info); 40 static napi_value CreateNativeNode(napi_env env, napi_callback_info info); 41 static napi_value UpdateNativeNode(napi_env env, napi_callback_info info); 42 43 void SetNativeXComponent(std::string &id, OH_NativeXComponent *nativeXComponent); 44 OH_NativeXComponent *GetNativeXComponent(const std::string &id); 45 46 Container *GetContainer(std::string &id); 47 void Export(napi_env env, napi_value exports); 48 49 static void CreateNode(ArkUI_NodeHandle& button, ArkUI_NodeHandle& buttonText, ArkUI_NodeHandle& textShow, 50 ArkUI_NodeHandle& textShow2); 51 static void SetTapGesture(ArkUI_GestureRecognizer *tapGesture, ArkUI_NodeHandle &column); 52 static void SetPanGesture(ArkUI_GestureRecognizer *panGesture, ArkUI_NodeHandle &column); 53 static void SetLongPressGesture(ArkUI_GestureRecognizer *LongPressGesture, ArkUI_NodeHandle &column); 54 static void SetGestureBlocking(ArkUI_NodeHandle &stack, ArkUI_NodeHandle &column1, OH_NativeXComponent* component); 55 56 private: 57 static Manager manager_; 58 59 std::unordered_map<std::string, OH_NativeXComponent *> nativeXComponentMap_; 60 std::unordered_map<std::string, Container *> containerMap_; 61 ArkUI_NodeHandle button_; 62 ArkUI_NodeHandle textShow_; 63 ArkUI_NodeHandle textShow2_; 64 ArkUI_GestureRecognizerType list_[3] = {TAP_GESTURE, LONG_PRESS_GESTURE, PAN_GESTURE}; 65 int32_t index_ = 0; 66 }; 67 } // namespace NativeXComponentSample 68 #endif // NATIVE_XCOMPONENT_PLUGIN_MANAGER_H 69