-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] Support linear gradient in cover block (#20411)
* add gradient support * Small refactor and fix changing customGradient to Image * Don't render overlay when the gradient is set
- Loading branch information
Showing
4 changed files
with
69 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
packages/components/src/mobile/linear-gradient/index.native.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import RNLinearGradient from 'react-native-linear-gradient'; | ||
|
||
function LinearGradient( { | ||
gradientValue, | ||
style, | ||
angleCenter = { x: 0.5, y: 0.5 }, | ||
...otherProps | ||
} ) { | ||
if ( ! gradientValue || ! gradientValue.includes( 'linear-gradient' ) ) { | ||
return null; | ||
} | ||
|
||
const matchColorGroup = /(rgba|rgb|#)(.+?)[\%]/g; | ||
const matchDeg = /(\d.+)deg/g; | ||
|
||
const colorGroup = gradientValue | ||
.match( matchColorGroup ) | ||
.map( ( color ) => color.split( ' ' ) ); | ||
|
||
const colors = colorGroup.map( ( color ) => color[ 0 ] ); | ||
const locations = colorGroup.map( | ||
( location ) => Number( location[ 1 ].replace( '%', '' ) ) / 100 | ||
); | ||
const angle = Number( matchDeg.exec( gradientValue )[ 1 ] ); | ||
|
||
return ( | ||
<RNLinearGradient | ||
colors={ colors } | ||
useAngle={ true } | ||
angle={ angle } | ||
locations={ locations } | ||
angleCenter={ angleCenter } | ||
style={ style } | ||
{ ...otherProps } | ||
/> | ||
); | ||
} | ||
|
||
export default LinearGradient; |