From a54ae6fc5f4bc08ab4228dbe3d97ba87454b784c Mon Sep 17 00:00:00 2001 From: Omar Diab Date: Tue, 14 Aug 2018 23:49:28 +0900 Subject: [PATCH 1/6] react-native-vector-icons: fontawesome5, 5pro --- .../FontAwesome5.d.ts | 43 +++++++++++++++++++ .../FontAwesome5Pro.d.ts | 6 +++ 2 files changed, 49 insertions(+) create mode 100644 types/react-native-vector-icons/FontAwesome5.d.ts create mode 100644 types/react-native-vector-icons/FontAwesome5Pro.d.ts diff --git a/types/react-native-vector-icons/FontAwesome5.d.ts b/types/react-native-vector-icons/FontAwesome5.d.ts new file mode 100644 index 0000000000..7d40fe2c5d --- /dev/null +++ b/types/react-native-vector-icons/FontAwesome5.d.ts @@ -0,0 +1,43 @@ +import { Component } from "../../../../../Library/Caches/typescript/2.9/node_modules/@types/react"; +import { Icon, IconProps, ImageSource } from "./Icon"; + +export const FA5Style: { + regular: 0; + light: 1; + solid: 2; + brand: 3; +}; + +type ValueOf = T[keyof T]; + +// borrowed from +// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html +type Omit = Pick>; + +export type FontAwesome5IconVariants = keyof Omit; + +// borrowed from https://stackoverflow.com/a/49725198/1105281 +type RequireOnlyOne = Omit & + { + [K in Keys]-?: Required> & + Partial, undefined>> + }[Keys]; + +export type FontAwesome5IconProps = RequireOnlyOne< + { [K in FontAwesome5IconVariants]?: boolean } & IconProps, + FontAwesome5IconVariants +>; + +export default class FontAwesome5Icon extends Component< + FontAwesome5IconProps, + any +> { + static getImageSource( + name: string, + size?: number, + color?: string, + fa5Style?: ValueOf + ): Promise; + static loadFont(file?: string): Promise; + static hasIcon(name: string): boolean; +} diff --git a/types/react-native-vector-icons/FontAwesome5Pro.d.ts b/types/react-native-vector-icons/FontAwesome5Pro.d.ts new file mode 100644 index 0000000000..f8233abce5 --- /dev/null +++ b/types/react-native-vector-icons/FontAwesome5Pro.d.ts @@ -0,0 +1,6 @@ +import { Component } from "react"; +import FontAwesome5Icon, { FontAwesome5IconProps } from "./FontAwesome5"; + +export type FontAwesome5ProIconProps = FontAwesome5IconProps; +export { FA5Style } from "./FontAwesome5"; +export default FontAwesome5Icon; From 18f5c760696dbe4a3c13c9dc518210b0695275b0 Mon Sep 17 00:00:00 2001 From: Omar Diab Date: Tue, 14 Aug 2018 23:50:41 +0900 Subject: [PATCH 2/6] react-native-vector-icons: fontawesome5 test --- .../react-native-vector-icons-tests.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/types/react-native-vector-icons/react-native-vector-icons-tests.tsx b/types/react-native-vector-icons/react-native-vector-icons-tests.tsx index 51cb1eee81..e0dcaeb9b6 100644 --- a/types/react-native-vector-icons/react-native-vector-icons-tests.tsx +++ b/types/react-native-vector-icons/react-native-vector-icons-tests.tsx @@ -3,6 +3,8 @@ import { View, Text, TabBarIOS } from 'react-native'; import { createIconSet } from 'react-native-vector-icons'; import MaterialIcon from 'react-native-vector-icons/MaterialIcons'; import FontAwesomeIcon from 'react-native-vector-icons/FontAwesome'; +import FontAwesome5Icon from 'react-native-vector-icons/FontAwesome5'; +import FontAwesome5ProIcon from 'react-native-vector-icons/FontAwesome5Pro'; import Ionicon from 'react-native-vector-icons/Ionicons'; const glyphMap = { @@ -27,6 +29,8 @@ class Example extends React.Component { {/* Normal Icon */} + + {/* Icon button */} Date: Wed, 15 Aug 2018 00:02:12 +0900 Subject: [PATCH 3/6] react-native-vector-icons: allow omitting variant --- types/react-native-vector-icons/FontAwesome5.d.ts | 8 ++++---- .../react-native-vector-icons-tests.tsx | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/types/react-native-vector-icons/FontAwesome5.d.ts b/types/react-native-vector-icons/FontAwesome5.d.ts index 7d40fe2c5d..18df444e79 100644 --- a/types/react-native-vector-icons/FontAwesome5.d.ts +++ b/types/react-native-vector-icons/FontAwesome5.d.ts @@ -16,14 +16,14 @@ type Omit = Pick>; export type FontAwesome5IconVariants = keyof Omit; -// borrowed from https://stackoverflow.com/a/49725198/1105281 -type RequireOnlyOne = Omit & +// modified from https://stackoverflow.com/a/49725198/1105281 +type AllowOnlyOne = Omit & { - [K in Keys]-?: Required> & + [K in Keys]-?: Partial> & Partial, undefined>> }[Keys]; -export type FontAwesome5IconProps = RequireOnlyOne< +export type FontAwesome5IconProps = AllowOnlyOne< { [K in FontAwesome5IconVariants]?: boolean } & IconProps, FontAwesome5IconVariants >; diff --git a/types/react-native-vector-icons/react-native-vector-icons-tests.tsx b/types/react-native-vector-icons/react-native-vector-icons-tests.tsx index e0dcaeb9b6..18b03edcaa 100644 --- a/types/react-native-vector-icons/react-native-vector-icons-tests.tsx +++ b/types/react-native-vector-icons/react-native-vector-icons-tests.tsx @@ -29,6 +29,7 @@ class Example extends React.Component { {/* Normal Icon */} + From dd09c5bced412294d13432e4b736717fc38bdc45 Mon Sep 17 00:00:00 2001 From: Omar Diab Date: Wed, 15 Aug 2018 00:03:39 +0900 Subject: [PATCH 4/6] fix messed up react import --- types/react-native-vector-icons/FontAwesome5.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/react-native-vector-icons/FontAwesome5.d.ts b/types/react-native-vector-icons/FontAwesome5.d.ts index 18df444e79..44fca921cc 100644 --- a/types/react-native-vector-icons/FontAwesome5.d.ts +++ b/types/react-native-vector-icons/FontAwesome5.d.ts @@ -1,4 +1,4 @@ -import { Component } from "../../../../../Library/Caches/typescript/2.9/node_modules/@types/react"; +import { Component } from "react"; import { Icon, IconProps, ImageSource } from "./Icon"; export const FA5Style: { From 300ac3256322cc0280c6d3abfe129440f8d39c62 Mon Sep 17 00:00:00 2001 From: Omar Diab Date: Wed, 15 Aug 2018 00:05:41 +0900 Subject: [PATCH 5/6] react-native-vector-icons: FA5 definitions > tsconfig --- types/react-native-vector-icons/tsconfig.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/types/react-native-vector-icons/tsconfig.json b/types/react-native-vector-icons/tsconfig.json index f66f39ed95..993aae3195 100644 --- a/types/react-native-vector-icons/tsconfig.json +++ b/types/react-native-vector-icons/tsconfig.json @@ -25,6 +25,8 @@ "EvilIcons.d.ts", "Feather.d.ts", "FontAwesome.d.ts", + "FontAwesome5.d.ts", + "FontAwesome5Pro.d.ts", "Foundation.d.ts", "Ionicons.d.ts", "MaterialCommunityIcons.d.ts", From 39ad4eadfcdd6dddf07744a688064ff727824f3f Mon Sep 17 00:00:00 2001 From: Omar Diab Date: Wed, 15 Aug 2018 11:56:08 +0900 Subject: [PATCH 6/6] guess it wants me to export everything --- types/react-native-vector-icons/FontAwesome5.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/react-native-vector-icons/FontAwesome5.d.ts b/types/react-native-vector-icons/FontAwesome5.d.ts index 44fca921cc..79c77ff0e2 100644 --- a/types/react-native-vector-icons/FontAwesome5.d.ts +++ b/types/react-native-vector-icons/FontAwesome5.d.ts @@ -8,16 +8,16 @@ export const FA5Style: { brand: 3; }; -type ValueOf = T[keyof T]; +export type ValueOf = T[keyof T]; // borrowed from // https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html -type Omit = Pick>; +export type Omit = Pick>; export type FontAwesome5IconVariants = keyof Omit; // modified from https://stackoverflow.com/a/49725198/1105281 -type AllowOnlyOne = Omit & +export type AllowOnlyOne = Omit & { [K in Keys]-?: Partial> & Partial, undefined>>