1*b6f8472aSBrent Vatneimport React from 'react'; 2*b6f8472aSBrent Vatneimport { StyleSheet, View } from 'react-native'; 3*b6f8472aSBrent Vatneimport { requireNativeViewManager } from 'expo-core'; 4*b6f8472aSBrent Vatne 5*b6f8472aSBrent Vatnetype Props = { 6*b6f8472aSBrent Vatne colors: number[]; 7*b6f8472aSBrent Vatne locations?: number[] | null; 8*b6f8472aSBrent Vatne startPoint?: Point | null; 9*b6f8472aSBrent Vatne endPoint?: Point | null; 10*b6f8472aSBrent Vatne} & React.ComponentProps<typeof View>; 11*b6f8472aSBrent Vatne 12*b6f8472aSBrent Vatnetype Point = [number, number]; 13*b6f8472aSBrent Vatne 14*b6f8472aSBrent Vatneexport default class NativeLinearGradient extends React.Component<Props> { 15*b6f8472aSBrent Vatne render() { 16*b6f8472aSBrent Vatne let { colors, locations, startPoint, endPoint, children, style, ...props } = this.props; 17*b6f8472aSBrent Vatne 18*b6f8472aSBrent Vatne // TODO: revisit whether we need to inherit the container's borderRadius since this issue has 19*b6f8472aSBrent Vatne // been resolved: https://github.com/facebook/react-native/issues/3198 20*b6f8472aSBrent Vatne let flatStyle = StyleSheet.flatten(style) || {}; 21*b6f8472aSBrent Vatne let borderRadius = flatStyle.borderRadius || 0; 22*b6f8472aSBrent Vatne 23*b6f8472aSBrent Vatne // This is the format from: 24*b6f8472aSBrent Vatne // https://developer.android.com/reference/android/graphics/Path.html#addRoundRect(android.graphics.RectF,%20float[],%20android.graphics.Path.Direction) 25*b6f8472aSBrent Vatne let borderRadiiPerCorner = [ 26*b6f8472aSBrent Vatne flatStyle.borderTopLeftRadius || borderRadius, 27*b6f8472aSBrent Vatne flatStyle.borderTopLeftRadius || borderRadius, 28*b6f8472aSBrent Vatne flatStyle.borderTopRightRadius || borderRadius, 29*b6f8472aSBrent Vatne flatStyle.borderTopRightRadius || borderRadius, 30*b6f8472aSBrent Vatne flatStyle.borderBottomRightRadius || borderRadius, 31*b6f8472aSBrent Vatne flatStyle.borderBottomRightRadius || borderRadius, 32*b6f8472aSBrent Vatne flatStyle.borderBottomLeftRadius || borderRadius, 33*b6f8472aSBrent Vatne flatStyle.borderBottomLeftRadius || borderRadius, 34*b6f8472aSBrent Vatne ]; 35*b6f8472aSBrent Vatne 36*b6f8472aSBrent Vatne return ( 37*b6f8472aSBrent Vatne <View {...props} style={style}> 38*b6f8472aSBrent Vatne <BaseNativeLinearGradient 39*b6f8472aSBrent Vatne style={{ position: 'absolute', top: 0, left: 0, bottom: 0, right: 0 }} 40*b6f8472aSBrent Vatne colors={colors} 41*b6f8472aSBrent Vatne startPoint={startPoint} 42*b6f8472aSBrent Vatne endPoint={endPoint} 43*b6f8472aSBrent Vatne locations={locations} 44*b6f8472aSBrent Vatne borderRadii={borderRadiiPerCorner} 45*b6f8472aSBrent Vatne /> 46*b6f8472aSBrent Vatne {children} 47*b6f8472aSBrent Vatne </View> 48*b6f8472aSBrent Vatne ); 49*b6f8472aSBrent Vatne } 50*b6f8472aSBrent Vatne} 51*b6f8472aSBrent Vatne 52*b6f8472aSBrent Vatneconst BaseNativeLinearGradient = requireNativeViewManager('ExpoLinearGradient'); 53