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SAAS,CAAC,MAAM,CAAC;IAC9C,KAAK,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IACnF,GAAG,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;CAClF,CAAC;AAyBJ,SAAS,eAAe,CAAC,KAA+B;IACtD,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,SAAS,CAAC;KAClB;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;QAC9C,OAAO,CAAC,IAAI,CAAC,8EAA8E,CAAC,CAAC;QAC7F,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;AAC3D,CAAC","sourcesContent":["import PropTypes from 'prop-types';\nimport React from 'react';\nimport { ColorPropType, Platform, View, ViewPropTypes, processColor } from 'react-native';\n\nimport NativeLinearGradient from './NativeLinearGradient';\n\ntype Props = {\n colors: string[];\n locations?: number[] | null;\n start?: Point | null;\n end?: Point | null;\n} & React.ComponentProps<typeof View>;\n\ntype Point = { x: number; y: number } | [number, number];\n\nexport default class LinearGradient extends React.Component<Props> {\n static propTypes = {\n ...ViewPropTypes,\n colors: PropTypes.arrayOf(ColorPropType).isRequired,\n locations: PropTypes.arrayOf(PropTypes.number),\n start: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.number), PropTypes.object]),\n end: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.number), PropTypes.object]),\n };\n\n render() {\n let { colors, locations, start, end, ...props } = this.props;\n\n if (locations && colors.length !== locations.length) {\n console.warn('LinearGradient colors and locations props should be arrays of the same length');\n locations = locations.slice(0, colors.length);\n }\n\n return (\n <NativeLinearGradient\n {...props}\n colors={Platform.select({\n web: colors as any,\n default: colors.map(processColor),\n })}\n locations={locations}\n startPoint={_normalizePoint(start)}\n endPoint={_normalizePoint(end)}\n />\n );\n }\n}\n\nfunction _normalizePoint(point: Point | null | undefined): [number, number] | undefined {\n if (!point) {\n return undefined;\n }\n\n if (Array.isArray(point) && point.length !== 2) {\n console.warn('start and end props for LinearGradient must be of the format [x,y] or {x, y}');\n return undefined;\n }\n\n return Array.isArray(point) ? point : [point.x, point.y];\n}\n"]}
\No newline at end of file