1*8285c032STomasz Sapetaimport { requireNativeViewManager } from 'expo-modules-core';
2257e8878SEvan Baconimport * as React from 'react';
3b6f8472aSBrent Vatneimport { StyleSheet, View } from 'react-native';
4b6f8472aSBrent Vatne
5257e8878SEvan Baconimport { NativeLinearGradientProps } from './NativeLinearGradient.types';
6b6f8472aSBrent Vatne
7257e8878SEvan Baconexport default function NativeLinearGradient({
8257e8878SEvan Bacon  colors,
9257e8878SEvan Bacon  locations,
10257e8878SEvan Bacon  startPoint,
11257e8878SEvan Bacon  endPoint,
12257e8878SEvan Bacon  children,
13257e8878SEvan Bacon  style,
14257e8878SEvan Bacon  ...props
15257e8878SEvan Bacon}: NativeLinearGradientProps): React.ReactElement {
16b6f8472aSBrent Vatne  // TODO: revisit whether we need to inherit the container's borderRadius since this issue has
17b6f8472aSBrent Vatne  // been resolved: https://github.com/facebook/react-native/issues/3198
18257e8878SEvan Bacon  const flatStyle = StyleSheet.flatten(style) ?? {};
19257e8878SEvan Bacon  const borderRadius = flatStyle.borderRadius ?? 0;
20b6f8472aSBrent Vatne
21b6f8472aSBrent Vatne  // This is the format from:
22b6f8472aSBrent Vatne  // https://developer.android.com/reference/android/graphics/Path.html#addRoundRect(android.graphics.RectF,%20float[],%20android.graphics.Path.Direction)
23b91f886fSJames Ide  const borderRadiiPerCorner = [
24257e8878SEvan Bacon    flatStyle.borderTopLeftRadius ?? borderRadius,
25257e8878SEvan Bacon    flatStyle.borderTopLeftRadius ?? borderRadius,
26257e8878SEvan Bacon    flatStyle.borderTopRightRadius ?? borderRadius,
27257e8878SEvan Bacon    flatStyle.borderTopRightRadius ?? borderRadius,
28257e8878SEvan Bacon    flatStyle.borderBottomRightRadius ?? borderRadius,
29257e8878SEvan Bacon    flatStyle.borderBottomRightRadius ?? borderRadius,
30257e8878SEvan Bacon    flatStyle.borderBottomLeftRadius ?? borderRadius,
31257e8878SEvan Bacon    flatStyle.borderBottomLeftRadius ?? borderRadius,
32b6f8472aSBrent Vatne  ];
33b6f8472aSBrent Vatne
34b6f8472aSBrent Vatne  return (
35b6f8472aSBrent Vatne    <View {...props} style={style}>
36b6f8472aSBrent Vatne      <BaseNativeLinearGradient
37257e8878SEvan Bacon        style={StyleSheet.absoluteFill}
38b6f8472aSBrent Vatne        colors={colors}
39b6f8472aSBrent Vatne        startPoint={startPoint}
40b6f8472aSBrent Vatne        endPoint={endPoint}
41b6f8472aSBrent Vatne        locations={locations}
42b6f8472aSBrent Vatne        borderRadii={borderRadiiPerCorner}
43b6f8472aSBrent Vatne      />
44b6f8472aSBrent Vatne      {children}
45b6f8472aSBrent Vatne    </View>
46b6f8472aSBrent Vatne  );
47b6f8472aSBrent Vatne}
48b6f8472aSBrent Vatne
49b6f8472aSBrent Vatneconst BaseNativeLinearGradient = requireNativeViewManager('ExpoLinearGradient');
50