-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
index.js
executable file
·33 lines (29 loc) · 932 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import React from "react";
import { View, StyleSheet } from "react-native";
import generateGradient from "./generator";
export { generateGradient };
export default ({ gradient, children, style }) => {
// Avoid breaking this when people are not using expo :)
// find a better solution to expose either expo-linear-gradient or
// react-native-linear-gradient.
const { LinearGradient } = require("expo-linear-gradient");
const generated = generateGradient(gradient, {
width: style.width,
height: style.height
});
if (generated.length > 1) {
return (
<View style={[style, { position: "relative" }]}>
{generated.map((obj, i) => (
<LinearGradient style={[StyleSheet.absoluteFill]} {...obj} key={i} />
))}
{children || null}
</View>
);
}
return (
<LinearGradient style={style} {...generated[0]}>
{children || null}
</LinearGradient>
);
};