• 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         // create wrapper node
40         auto wrapperNode = FrameNode::CreateFrameNode(V2::KEYBOARD_ETS_TAG,
41             ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<KeyboardPattern>(targetId));
42         auto wrapperLayoutProperty = wrapperNode->GetLayoutProperty<LinearLayoutProperty>();
43         CHECK_NULL_RETURN(wrapperLayoutProperty, nullptr);
44 
45         // build keyboard node
46         NG::ScopedViewStackProcessor builderViewStackProcessor;
47         builder();
48         auto customNode = NG::ViewStackProcessor::GetInstance()->Finish();
49         auto keyboardNode = AceType::DynamicCast<FrameNode>(customNode);
50         CHECK_NULL_RETURN(keyboardNode, nullptr);
51 
52         // put builder node to the bottom, and set the wrapper size match parent page
53         wrapperLayoutProperty->UpdateMainAxisAlign(FlexAlign::FLEX_END);
54         wrapperLayoutProperty->UpdateMeasureType(MeasureType::MATCH_PARENT);
55 
56         wrapperNode->AddChild(keyboardNode);
57         wrapperNode->MarkModifyDone();
58 
59         // disable focus
60         auto focusHub = wrapperNode->GetOrCreateFocusHub();
61         focusHub->SetFocusable(false);
62 
63         // transparent touch event
64         auto gestureHub = wrapperNode->GetOrCreateGestureEventHub();
65         gestureHub->SetHitTestMode(HitTestMode::HTMTRANSPARENT_SELF);
66         return wrapperNode;
67     };
68 };
69 } // namespace OHOS::Ace::NG
70 
71 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_KEYBOARD_VIEW_H
72