• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
39         auto nodeId = ElementRegister::GetInstance()->MakeUniqueId();
40         ACE_LAYOUT_SCOPED_TRACE("Create[%s][self:%d]", V2::KEYBOARD_ETS_TAG, targetId);
41         // create wrapper node
42         auto wrapperNode = FrameNode::CreateFrameNode(V2::KEYBOARD_ETS_TAG,
43             nodeId, AceType::MakeRefPtr<KeyboardPattern>(targetId));
44         auto wrapperLayoutProperty = wrapperNode->GetLayoutProperty<LinearLayoutProperty>();
45         CHECK_NULL_RETURN(wrapperLayoutProperty, nullptr);
46         wrapperLayoutProperty->UpdateMeasureType(MeasureType::MATCH_PARENT_CROSS_AXIS);
47 
48         // build keyboard node
49         NG::ScopedViewStackProcessor builderViewStackProcessor;
50         builder();
51         auto customNode = NG::ViewStackProcessor::GetInstance()->Finish();
52         auto keyboardNode = AceType::DynamicCast<UINode>(customNode);
53         CHECK_NULL_RETURN(keyboardNode, nullptr);
54 
55         wrapperNode->AddChild(keyboardNode);
56         wrapperNode->MarkModifyDone();
57 
58         // disable focus
59         auto focusHub = wrapperNode->GetOrCreateFocusHub();
60         focusHub->SetFocusable(false);
61 
62         // transparent touch event
63         auto gestureHub = wrapperNode->GetOrCreateGestureEventHub();
64         gestureHub->SetHitTestMode(HitTestMode::HTMTRANSPARENT_SELF);
65         return wrapperNode;
66     };
67 };
68 } // namespace OHOS::Ace::NG
69 
70 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_KEYBOARD_VIEW_H
71