1/* 2 * Copyright (c) 2024 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 COMPONENT_EXT_MOVING_PHOTO_MOVING_PHOTO_NODE_H 17#define COMPONENT_EXT_MOVING_PHOTO_MOVING_PHOTO_NODE_H 18 19#include "movingphoto_pattern.h" 20#include "core/components_ng/base/frame_node.h" 21 22namespace OHOS::Ace::NG { 23 24constexpr int32_t VIDEO_NODE_INDEX = 0; 25constexpr int32_t IMAGE_NODE_INDEX = 1; 26 27class ACE_EXPORT MovingPhotoNode : public FrameNode { 28 DECLARE_ACE_TYPE(MovingPhotoNode, FrameNode); 29 30public: 31 MovingPhotoNode(const std::string& tag, int32_t nodeId, const RefPtr<Pattern>& pattern, bool isRoot = false) 32 : FrameNode(tag, nodeId, pattern, isRoot) 33 {} 34 ~MovingPhotoNode() override = default; 35 36 static RefPtr<MovingPhotoNode> GetOrCreateMovingPhotoNode( 37 const std::string& tag, int32_t nodeId, const std::function<RefPtr<Pattern>(void)>& patternCreator); 38 39 int32_t GetImageId() 40 { 41 if (!imageId_.has_value()) { 42 imageId_ = ElementRegister::GetInstance()->MakeUniqueId(); 43 } 44 return imageId_.value(); 45 } 46 47 RefPtr<UINode> GetImage() 48 { 49 return GetChildAtIndex(IMAGE_NODE_INDEX); 50 } 51 52 bool HasImageNode() 53 { 54 return imageId_.has_value(); 55 } 56 57 int32_t GetVideoId() 58 { 59 if (!videoId_.has_value()) { 60 videoId_ = ElementRegister::GetInstance()->MakeUniqueId(); 61 } 62 return videoId_.value(); 63 } 64 65 RefPtr<UINode> GetVideo() 66 { 67 return GetChildAtIndex(VIDEO_NODE_INDEX); 68 } 69 70 bool HasVideoNode() 71 { 72 return videoId_.has_value(); 73 } 74 75private: 76 std::optional<int32_t> imageId_; 77 std::optional<int32_t> videoId_; 78}; 79} // namespace OHOS::Ace::NG 80#endif // COMPONENT_EXT_MOVING_PHOTO_MOVING_PHOTO_NODE_H