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 #include "node_transition.h" 17 18 #include "native_type.h" 19 20 #include "base/utils/utils.h" 21 22 namespace OHOS::Ace::TransitionModel { 23 CreateEffectOption()24ArkUITransitionEffectOption* CreateEffectOption() 25 { 26 ArkUITransitionEffectOption* effectOption = new ArkUITransitionEffectOption; 27 effectOption->appear = nullptr; 28 effectOption->disappear = nullptr; 29 effectOption->combine = nullptr; 30 return effectOption; 31 } 32 ConvertToEffectOption(ArkUI_TransitionEffect * effectOption)33ArkUITransitionEffectOption* ConvertToEffectOption(ArkUI_TransitionEffect* effectOption) 34 { 35 CHECK_NULL_RETURN(effectOption, nullptr); 36 auto* toEffectOption = CreateEffectOption(); 37 toEffectOption->type = effectOption->type; 38 switch (effectOption->type) { 39 case ARKUI_TRANSITION_EFFECT_OPACITY: { 40 toEffectOption->opacity = effectOption->opacity; 41 break; 42 } 43 case ARKUI_TRANSITION_EFFECT_TRANSLATE: { 44 if (!effectOption->translate) { 45 delete toEffectOption; 46 toEffectOption = nullptr; 47 return nullptr; 48 } 49 toEffectOption->translate.x = effectOption->translate->x; 50 toEffectOption->translate.y = effectOption->translate->y; 51 toEffectOption->translate.z = effectOption->translate->z; 52 break; 53 } 54 case ARKUI_TRANSITION_EFFECT_SCALE: { 55 if (!effectOption->scale) { 56 delete toEffectOption; 57 toEffectOption = nullptr; 58 return nullptr; 59 } 60 toEffectOption->scale.x = effectOption->scale->x; 61 toEffectOption->scale.y = effectOption->scale->y; 62 toEffectOption->scale.z = effectOption->scale->z; 63 toEffectOption->scale.centerX = effectOption->scale->centerX; 64 toEffectOption->scale.centerY = effectOption->scale->centerY; 65 break; 66 } 67 case ARKUI_TRANSITION_EFFECT_ROTATE: { 68 if (!effectOption->rotate) { 69 delete toEffectOption; 70 toEffectOption = nullptr; 71 return nullptr; 72 } 73 toEffectOption->rotate.x = effectOption->rotate->x; 74 toEffectOption->rotate.y = effectOption->rotate->y; 75 toEffectOption->rotate.z = effectOption->rotate->z; 76 toEffectOption->rotate.angle = effectOption->rotate->angle; 77 toEffectOption->rotate.centerX = effectOption->rotate->centerX; 78 toEffectOption->rotate.centerY = effectOption->rotate->centerY; 79 toEffectOption->rotate.centerZ = effectOption->rotate->centerZ; 80 toEffectOption->rotate.perspective = effectOption->rotate->perspective; 81 break; 82 } 83 case ARKUI_TRANSITION_EFFECT_MOVE: { 84 toEffectOption->move = effectOption->move; 85 break; 86 } 87 case ARKUI_TRANSITION_EFFECT_ASYMMETRIC: { 88 if (effectOption->appear) { 89 auto* appear = ConvertToEffectOption(effectOption->appear); 90 toEffectOption->appear = appear; 91 } 92 if (effectOption->disappear) { 93 auto* disappear = ConvertToEffectOption(effectOption->disappear); 94 toEffectOption->disappear = disappear; 95 } 96 break; 97 } 98 } 99 100 if (effectOption->animation) { 101 toEffectOption->hasAnimation = true; 102 toEffectOption->animation.duration = effectOption->animation->duration; 103 toEffectOption->animation.tempo = effectOption->animation->tempo; 104 toEffectOption->animation.curve = effectOption->animation->curve; 105 if (effectOption->animation->iCurve) { 106 toEffectOption->animation.iCurve = effectOption->animation->iCurve->curve; 107 toEffectOption->animation.curveType = effectOption->animation->iCurve->type; 108 } else { 109 toEffectOption->animation.iCurve = nullptr; 110 } 111 toEffectOption->animation.delay = effectOption->animation->delay; 112 toEffectOption->animation.iterations = effectOption->animation->iterations; 113 toEffectOption->animation.playMode = effectOption->animation->playMode; 114 if (effectOption->animation->expectedFrameRateRange) { 115 toEffectOption->animation.expectedFrameRateRange = 116 reinterpret_cast<ArkUIExpectedFrameRateRange*>(effectOption->animation->expectedFrameRateRange); 117 } else { 118 toEffectOption->animation.expectedFrameRateRange = nullptr; 119 } 120 } else { 121 toEffectOption->hasAnimation = false; 122 } 123 124 if (effectOption->combine) { 125 toEffectOption->combine = ConvertToEffectOption(effectOption->combine); 126 } 127 effectOption->toEffectOption = toEffectOption; 128 return toEffectOption; 129 } 130 } // namespace OHOS::Ace::TransitionModel 131