import { LinearGradient } from 'expo-linear-gradient';
import React from 'react';
import { Image, Platform, ScrollView, StyleSheet, Text, View } from 'react-native';
import MonoText from '../components/MonoText';
function incrementColor(color: string, step: number) {
const intColor = parseInt(color.substr(1), 16);
const newIntColor = (intColor + step).toString(16);
return `#${'0'.repeat(6 - newIntColor.length)}${newIntColor}`;
}
export default class LinearGradientScreen extends React.Component {
static navigationOptions = {
title: 'LinearGradient',
};
state = {
count: 0,
colorTop: '#000000',
colorBottom: '#cccccc',
};
_interval?: number;
componentDidMount() {
this._interval = setInterval(() => {
this.setState({
count: this.state.count + 1,
colorTop: incrementColor(this.state.colorTop, 1),
colorBottom: incrementColor(this.state.colorBottom, -1),
});
}, 100);
}
componentWillUnmount() {
clearInterval(this._interval);
}
render() {
const location = Math.sin(this.state.count / 100) * 0.5;
const position = Math.sin(this.state.count / 100);
return (
{Platform.OS !== 'web' && }
);
}
}
const Container: React.FunctionComponent<{ title: string }> = ({ title, children }) => (
{title}
{children}
);
const SnapshotTest = () => (
The gradients above should look the same.
);
const ControlPointTest: React.FunctionComponent<{
start?: [number, number];
end?: [number, number];
}> = ({
start = [0.5, 0],
end = [0, 1],
}) => {
const startInfo = `start={[${start.map(point => +point.toFixed(2)).join(', ')}]}`;
const endInfo = `end={[${end.map(point => +point.toFixed(2)).join(', ')}]}`;
return (
{[startInfo, endInfo].map((pointInfo, index) => (
{pointInfo}
))}
);
};
const ColorsTest = ({ colors }: { colors: string[] }) => {
const info = colors.map(value => `"${value}"`).join(', ');
return (
{`colors={[${info}]}`}
);
};
const LocationsTest: React.FunctionComponent<{ locations: number[] }> = ({ locations }) => {
const locationsInfo = locations.map(location => +location.toFixed(2)).join(', ');
return (
{`locations={[${locationsInfo}]}`}
);
};
const styles = StyleSheet.create({
container: {
padding: 8,
},
containerTitle: {
fontSize: 14,
fontWeight: '600',
textAlign: 'center',
marginBottom: 8,
},
});