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_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_KEYBOARD_VIEW_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_KEYBOARD_VIEW_H 18 19 #include <functional> 20 21 #include "base/memory/ace_type.h" 22 #include "base/memory/referenced.h" 23 #include "base/utils/utils.h" 24 #include "core/components/common/layout/constants.h" 25 #include "core/components/common/properties/alignment.h" 26 #include "core/components_ng/base/frame_node.h" 27 #include "core/components_ng/base/view_stack_processor.h" 28 #include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h" 29 #include "core/components_ng/pattern/linear_layout/linear_layout_property.h" 30 #include "core/components_ng/pattern/overlay/keyboard_base_pattern.h" 31 32 namespace OHOS::Ace::NG { 33 class ACE_EXPORT KeyboardView { 34 public: CreateKeyboard(int32_t targetId,std::function<void ()> builder)35 static RefPtr<FrameNode> CreateKeyboard(int32_t targetId, std::function<void()> builder) 36 { 37 CHECK_NULL_RETURN(builder, nullptr); 38 // build keyboard node 39 NG::ScopedViewStackProcessor builderViewStackProcessor; 40 builder(); 41 auto customNode = NG::ViewStackProcessor::GetInstance()->Finish(); 42 auto keyboardNode = AceType::DynamicCast<UINode>(customNode); 43 44 return CreateKeyboardWithNode(targetId, keyboardNode); 45 }; 46 CreateKeyboardWithNode(int32_t targetId,const RefPtr<UINode> & keyboardNode)47 static RefPtr<FrameNode> CreateKeyboardWithNode(int32_t targetId, const RefPtr<UINode>& keyboardNode) 48 { 49 CHECK_NULL_RETURN(keyboardNode, nullptr); 50 auto nodeId = ElementRegister::GetInstance()->MakeUniqueId(); 51 ACE_LAYOUT_SCOPED_TRACE("Create[%s][self:%d]", V2::KEYBOARD_ETS_TAG, targetId); 52 // create wrapper node 53 auto wrapperNode = FrameNode::CreateFrameNode(V2::KEYBOARD_ETS_TAG, 54 nodeId, AceType::MakeRefPtr<KeyboardPattern>(targetId)); 55 auto wrapperLayoutProperty = wrapperNode->GetLayoutProperty<LinearLayoutProperty>(); 56 CHECK_NULL_RETURN(wrapperLayoutProperty, nullptr); 57 wrapperLayoutProperty->UpdateMeasureType(MeasureType::MATCH_PARENT_CROSS_AXIS); 58 59 wrapperNode->AddChild(keyboardNode); 60 wrapperNode->MarkModifyDone(); 61 62 // disable focus 63 auto focusHub = wrapperNode->GetOrCreateFocusHub(); 64 focusHub->SetFocusable(false); 65 66 // transparent touch event 67 auto gestureHub = wrapperNode->GetOrCreateGestureEventHub(); 68 gestureHub->SetHitTestMode(HitTestMode::HTMTRANSPARENT_SELF); 69 return wrapperNode; 70 }; 71 }; 72 } // namespace OHOS::Ace::NG 73 74 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_KEYBOARD_VIEW_H 75