From 2543f375d8d32857ea93616c8e12e87e2f4d920b Mon Sep 17 00:00:00 2001 From: James Ide Date: Thu, 13 Sep 2018 17:44:53 -0700 Subject: [PATCH] [react-native] Declare StyleSheet.setStyleAttributePreprocessor Added the type declaration and copied the documentation for this static function. The type of the `process` parameter should be `(nextProp: unknown) => unknown` but I stuck with `any` to preserve 2.x compatibility. --- types/react-native/index.d.ts | 14 ++++++++++++++ types/react-native/test/index.tsx | 2 ++ 2 files changed, 16 insertions(+) diff --git a/types/react-native/index.d.ts b/types/react-native/index.d.ts index ad8abe57fd..1a91e55c90 100644 --- a/types/react-native/index.d.ts +++ b/types/react-native/index.d.ts @@ -5216,6 +5216,20 @@ export namespace StyleSheet { export function flatten(style?: StyleProp): ImageStyle; export function flatten(style?: StyleProp): ViewStyle; + /** + * WARNING: EXPERIMENTAL. Breaking changes will probably happen a lot and will + * not be reliably announced. The whole thing might be deleted, who knows? Use + * at your own risk. + * + * Sets a function to use to pre-process a style property value. This is used + * internally to process color and transform values. You should not use this + * unless you really know what you are doing and have exhausted other options. + */ + export function setStyleAttributePreprocessor( + property: string, + process: (nextProp: any) => any + ): void; + /** * This is defined as the width of a thin line on the platform. It can be * used as the thickness of a border or division between two elements. diff --git a/types/react-native/test/index.tsx b/types/react-native/test/index.tsx index 8bc6757c48..21d859d771 100644 --- a/types/react-native/test/index.tsx +++ b/types/react-native/test/index.tsx @@ -151,6 +151,8 @@ const stylesAlt = StyleSheet.create({ }, }); +StyleSheet.setStyleAttributePreprocessor('fontFamily', (family: string) => family); + const welcomeFontSize = StyleSheet.flatten(styles.welcome).fontSize; const viewStyle: StyleProp = {