/
githubmr
/
facebook-react-native
Обзор
Документация
Войти
/
githubmr
/
facebook-react-native
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
main
packages/react-native/ReactCommon/react/renderer/graphics/ValueUnit.h
56 строк
1 KB
Nick Lefever
Disable inlining of ColorStop and ValueUnit toDynamic conversion (#54125)
14 окт 2025, 20:46
14 окт 2025, 20:46
fc74d8c
Код
Авторство
О чём код?
/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ #pragma once #ifdef RN_SERIALIZABLE_STATE #include <folly/dynamic.h> #endif namespace facebook::react { enum class UnitType { Undefined, Point, Percent, }; struct ValueUnit { float value{0.0f}; UnitType unit{UnitType::Undefined}; ValueUnit() = default; ValueUnit(float v, UnitType u) : value(v), unit(u) {} bool operator==(const ValueUnit& other) const { return value == other.value && unit == other.unit; } bool operator!=(const ValueUnit& other) const { return !(*this == other); } constexpr float resolve(float referenceLength) const { switch (unit) { case UnitType::Point: return value; case UnitType::Percent: return value * referenceLength * 0.01f; case UnitType::Undefined: default: return 0.0f; } } constexpr operator bool() const { return unit != UnitType::Undefined; } #ifdef RN_SERIALIZABLE_STATE folly::dynamic toDynamic() const; #endif }; } // namespace facebook::react