192f6de58SWill Schurmanimport { requireNativeViewManager } from '@unimodules/core'; 2*257e8878SEvan Baconimport * as React from 'react'; 3b6f8472aSBrent Vatneimport { StyleSheet, View } from 'react-native'; 4b6f8472aSBrent Vatne 5*257e8878SEvan Baconimport { NativeLinearGradientProps } from './NativeLinearGradient.types'; 6b6f8472aSBrent Vatne 7*257e8878SEvan Baconexport default function NativeLinearGradient({ 8*257e8878SEvan Bacon colors, 9*257e8878SEvan Bacon locations, 10*257e8878SEvan Bacon startPoint, 11*257e8878SEvan Bacon endPoint, 12*257e8878SEvan Bacon children, 13*257e8878SEvan Bacon style, 14*257e8878SEvan Bacon ...props 15*257e8878SEvan 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 18*257e8878SEvan Bacon const flatStyle = StyleSheet.flatten(style) ?? {}; 19*257e8878SEvan 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 = [ 24*257e8878SEvan Bacon flatStyle.borderTopLeftRadius ?? borderRadius, 25*257e8878SEvan Bacon flatStyle.borderTopLeftRadius ?? borderRadius, 26*257e8878SEvan Bacon flatStyle.borderTopRightRadius ?? borderRadius, 27*257e8878SEvan Bacon flatStyle.borderTopRightRadius ?? borderRadius, 28*257e8878SEvan Bacon flatStyle.borderBottomRightRadius ?? borderRadius, 29*257e8878SEvan Bacon flatStyle.borderBottomRightRadius ?? borderRadius, 30*257e8878SEvan Bacon flatStyle.borderBottomLeftRadius ?? borderRadius, 31*257e8878SEvan Bacon flatStyle.borderBottomLeftRadius ?? borderRadius, 32b6f8472aSBrent Vatne ]; 33b6f8472aSBrent Vatne 34b6f8472aSBrent Vatne return ( 35b6f8472aSBrent Vatne <View {...props} style={style}> 36b6f8472aSBrent Vatne <BaseNativeLinearGradient 37*257e8878SEvan 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