Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 29 additions & 17 deletions index.windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
* @providesModule LinearGradient
* @flow
*/
import React, { Component } from 'react';
import { processColor, View } from 'react-native';
import React, { Component } from "react";
import { processColor, View } from "react-native";

import NativeLinearGradient, { type Props } from './common';
import NativeLinearGradient, { type Props } from "./common";

const convertPoint = (name, point) => {
if (Array.isArray(point)) {
console.warn(
`LinearGradient '${name}' property should be an object with fields 'x' and 'y', ` +
'Array type is deprecated.'
"Array type is deprecated."
);

return {
x: point[0],
y: point[1]
y: point[1],
};
}
return point;
Expand All @@ -37,31 +37,43 @@ export default class LinearGradient extends Component<Props> {

render() {
const {
children,
start,
end,
colors,
locations,
useAngle,
angleCenter,
angle,
style,
...otherProps
} = this.props;
if ((colors && locations) && (colors.length !== locations.length)) {
console.warn('LinearGradient colors and locations props should be arrays of the same length');
if (colors && locations && colors.length !== locations.length) {
console.warn(
"LinearGradient colors and locations props should be arrays of the same length"
);
}

return (
<NativeLinearGradient
ref={(component) => { this.gradientRef = component; }}
<View
ref={(component) => {
this.gradientRef = component;
}}
{...otherProps}
startPoint={convertPoint('start', start)}
endPoint={convertPoint('end', end)}
colors={colors.map(processColor)}
locations={locations ? locations.slice(0, colors.length) : null}
useAngle={useAngle}
angleCenter={convertPoint('angleCenter', angleCenter)}
angle={angle}
/>
style={style}
>
<NativeLinearGradient
style={{ position: "absolute", top: 0, left: 0, bottom: 0, right: 0 }}
colors={colors.map(processColor)}
startPoint={convertPoint("start", start)}
endPoint={convertPoint("end", end)}
locations={locations ? locations.slice(0, colors.length) : null}
useAngle={useAngle}
angleCenter={convertPoint("angleCenter", angleCenter)}
angle={angle}
/>
{children}
</View>
);
}
}