From 1b3581e245d1ae5f965f80c59dc57aece0a854e7 Mon Sep 17 00:00:00 2001 From: Genki Kondo Date: Fri, 11 Feb 2022 09:54:32 -0800 Subject: [PATCH] Export isSupportedProp checks in NativeAnimatedHelper Summary: More convenient to call these Changelog: [Internal] - Export isSupportedProp checks in NativeAnimatedHelper Reviewed By: javache Differential Revision: D34163370 fbshipit-source-id: 9e3b5e5e4a9272f9b807863dfde2c3b0fb13acd8 --- Libraries/Animated/NativeAnimatedHelper.js | 30 +++++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/Libraries/Animated/NativeAnimatedHelper.js b/Libraries/Animated/NativeAnimatedHelper.js index 204f35900ef1a7..e303128751b6e1 100644 --- a/Libraries/Animated/NativeAnimatedHelper.js +++ b/Libraries/Animated/NativeAnimatedHelper.js @@ -308,6 +308,22 @@ function addWhitelistedInterpolationParam(param: string): void { SUPPORTED_INTERPOLATION_PARAMS[param] = true; } +function isSupportedColorStyleProp(prop: string): boolean { + return SUPPORTED_COLOR_STYLES.hasOwnProperty(prop); +} + +function isSupportedStyleProp(prop: string): boolean { + return SUPPORTED_STYLES.hasOwnProperty(prop); +} + +function isSupportedTransformProp(prop: string): boolean { + return SUPPORTED_TRANSFORMS.hasOwnProperty(prop); +} + +function isSupportedInterpolationParam(param: string): boolean { + return SUPPORTED_INTERPOLATION_PARAMS.hasOwnProperty(param); +} + function validateTransform( configs: Array< | { @@ -325,7 +341,7 @@ function validateTransform( >, ): void { configs.forEach(config => { - if (!SUPPORTED_TRANSFORMS.hasOwnProperty(config.property)) { + if (!isSupportedTransformProp(config.property)) { throw new Error( `Property '${config.property}' is not supported by native animated module`, ); @@ -335,7 +351,7 @@ function validateTransform( function validateStyles(styles: {[key: string]: ?number, ...}): void { for (const key in styles) { - if (!SUPPORTED_STYLES.hasOwnProperty(key)) { + if (!isSupportedStyleProp(key)) { throw new Error( `Style property '${key}' is not supported by native animated module`, ); @@ -345,7 +361,7 @@ function validateStyles(styles: {[key: string]: ?number, ...}): void { function validateInterpolation(config: InterpolationConfigType): void { for (const key in config) { - if (!SUPPORTED_INTERPOLATION_PARAMS.hasOwnProperty(key)) { + if (!isSupportedInterpolationParam(key)) { throw new Error( `Interpolation property '${key}' is not supported by native animated module`, ); @@ -411,10 +427,10 @@ function transformDataType(value: number | string): number | string { module.exports = { API, - SUPPORTED_STYLES, - SUPPORTED_COLOR_STYLES, - SUPPORTED_TRANSFORMS, - SUPPORTED_INTERPOLATION_PARAMS, + isSupportedColorStyleProp, + isSupportedStyleProp, + isSupportedTransformProp, + isSupportedInterpolationParam, addWhitelistedStyleProp, addWhitelistedTransformProp, addWhitelistedInterpolationParam,