-
Notifications
You must be signed in to change notification settings - Fork 24k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Pull Request resolved: #44455 Title says it all. Right now this ignores drop-shadow as that will be implemented later. Some of this code will need to be adjusted as it is the one filter that takes multiple amounts. But I feel that can be amended later when we get there - after all the `amount` parsing code is just casting to a float at the moment, so we are not locking ourselves into anything. Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D54640629 fbshipit-source-id: c8e1206ab46accab3c99614241b8bd9aa252e12c
- Loading branch information
1 parent
00f3867
commit f340e6e
Showing
4 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
packages/react-native/ReactCommon/react/renderer/graphics/Filter.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* 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 | ||
|
||
#include <react/renderer/graphics/Float.h> | ||
|
||
#include <string> | ||
#include <string_view> | ||
#include <vector> | ||
|
||
namespace facebook::react { | ||
|
||
enum class FilterType { | ||
Blur, | ||
Brightness, | ||
Contrast, | ||
Grayscale, | ||
HueRotate, | ||
Invert, | ||
Opacity, | ||
Saturate, | ||
Sepia | ||
}; | ||
|
||
struct FilterPrimitive { | ||
bool operator==(const FilterPrimitive& other) const = default; | ||
|
||
FilterType type; | ||
Float amount; | ||
}; | ||
|
||
inline FilterType filterTypeFromString(std::string_view filterName) { | ||
if (filterName == "blur") { | ||
return FilterType::Blur; | ||
} else if (filterName == "brightness") { | ||
return FilterType::Brightness; | ||
} else if (filterName == "contrast") { | ||
return FilterType::Contrast; | ||
} else if (filterName == "grayscale") { | ||
return FilterType::Grayscale; | ||
} else if (filterName == "hueRotate") { | ||
return FilterType::HueRotate; | ||
} else if (filterName == "invert") { | ||
return FilterType::Invert; | ||
} else if (filterName == "opacity") { | ||
return FilterType::Opacity; | ||
} else if (filterName == "saturate") { | ||
return FilterType::Saturate; | ||
} else if (filterName == "sepia") { | ||
return FilterType::Sepia; | ||
} else { | ||
throw std::invalid_argument(std::string(filterName)); | ||
} | ||
} | ||
|
||
} // namespace facebook::react |