import { LinearGradient } from 'expo-linear-gradient'; import React from 'react'; import { Image, Platform, Animated, ScrollView, StyleSheet, Text, View } from 'react-native'; import MonoText from '../components/MonoText'; // https://github.com/expo/expo/issues/10599 const AnimatedLinearGradient = Animated.createAnimatedComponent(LinearGradient); 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}`; } type State = { count: number; colorTop: string; colorBottom: string; }; // See: https://github.com/expo/expo/pull/10229#discussion_r490961694 // eslint-disable-next-line @typescript-eslint/ban-types export default class LinearGradientScreen extends React.Component<{}, State> { static navigationOptions = { title: 'LinearGradient', }; state = { count: 0, colorTop: '#000000', colorBottom: '#cccccc', }; _interval?: number; componentDidMount() { this._interval = setInterval(() => { this.setState((state) => ({ count: state.count + 1, colorTop: incrementColor(state.colorTop, 1), colorBottom: incrementColor(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; children?: React.ReactNode }> = ({ 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, flexShrink: 0, }, containerTitle: { fontSize: 14, fontWeight: '600', textAlign: 'center', marginBottom: 8, }, gradient: { flex: 1, flexShrink: 0, minHeight: 200, maxHeight: 200, }, });