1 /* 2 * Copyright (c) 2021 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_NAVIGATION_BAR_NAVIGATION_BAR_ELEMENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NAVIGATION_BAR_NAVIGATION_BAR_ELEMENT_H 18 19 #include "core/components/navigation_bar/navigation_bar_component.h" 20 #include "core/focus/focus_node.h" 21 #include "core/pipeline/base/composed_element.h" 22 23 namespace OHOS::Ace { 24 25 class NavigationBarElement : public ComposedElement, public FocusGroup { 26 DECLARE_ACE_TYPE(NavigationBarElement, ComposedElement, FocusGroup); 27 28 public: NavigationBarElement(const ComposeId & id)29 explicit NavigationBarElement(const ComposeId& id) : ComposedElement(id) {} 30 ~NavigationBarElement() override = default; 31 32 void PerformBuild() override; 33 34 protected: RequestNextFocus(bool vertical,bool reverse,const Rect & rect)35 bool RequestNextFocus(bool vertical, bool reverse, const Rect& rect) override 36 { 37 return false; 38 }; 39 OnFocus()40 void OnFocus() override 41 { 42 auto context = GetContext().Upgrade(); 43 if (context) { 44 context->SetUseRootAnimation(true); 45 } 46 FocusGroup::OnFocus(); 47 } 48 OnBlur()49 void OnBlur() override 50 { 51 auto context = GetContext().Upgrade(); 52 if (context) { 53 context->SetUseRootAnimation(false); 54 } 55 FocusGroup::OnBlur(); 56 } 57 58 private: 59 #ifndef WEARABLE_PRODUCT 60 EventMarker moreClickMarker_; 61 void BindMoreButtonClickEvent(const RefPtr<NavigationBarComponent>& navigationBar); 62 void BindClickEventToOptions(const RefPtr<NavigationBarComponent>& navigationBar); 63 #endif 64 65 std::function<void(const std::string&)> menuSelectedEvent_; 66 }; 67 68 } // namespace OHOS::Ace 69 70 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NAVIGATION_BAR_NAVIGATION_BAR_ELEMENT_H 71