首页 > 解决方案 > 如何在本机反应中将线性渐变从 css 转换为线性渐变?

问题描述

我在 css 中有一个线性渐变,我想在 react native 中linear-gradient(315.43deg, #706EB6 -6.67%, #A57FCF 106.6%)使用该组件。和propsLinearGradient的等价物是什么start,我如何从 css 中的线性渐变传递到原生反应?endlocations

标签: cssreact-native

解决方案


在 React Native 中,您可以像这样使用颜色属性

<LinearGradient colors={['transparent', '#000000']}>
</LinearGradient>

同理,你可以传递开始、结束位置

你可以在这里看到 LinearGradient 的道具

declare module 'react-native-linear-gradient' {
  import * as React from 'react';
  import * as ReactNative from 'react-native';

  export interface LinearGradientProps extends ReactNative.ViewProps {
    colors: (string | number)[];
    start?: { x: number; y: number };
    end?: { x: number; y: number };
    locations?: number[];
    useAngle?: boolean;
    angleCenter?: {x: number, y: number};
    angle?: number;
  }

  export class LinearGradient extends React.Component<LinearGradientProps> {}

  export default LinearGradient;
}

推荐阅读