Last Updated on : 2022-01-07 02:53:40download
The colored rectangle component ColorRect
is used to distribute colors evenly or proportionally as specified.
Evenly distributed:
Uneven distributed:
Custom style:
Field name | Data type | Description | Default value |
---|---|---|---|
style | StyleProp |
The style of the component. | None |
colors | Array | The array of colors. | [] |
activeOpacity | Number | The opacity of the component when it is tapped. | 0.8 |
onPress | ()=>void | The button tapping event. | None |
colors
Field name | Data type | Description | Default value |
---|---|---|---|
color | String | The color. | None |
percent | Number | The percentage of a color. | None |
import React, { PureComponent } from 'react';
import { View } from 'react-native';
import { ColorRect } from '@tuya/tuya-panel-lamp-sdk';
export default class Scene extends PureComponent {
render() {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
// Unevenly distributed.
<ColorRect
style={{ width: 80, height: 100 }}
colors={[
{ color: 'green', percent: 0.14 },
{ color: 'yellow', percent: 0.26 },
{ color: 'red', percent: 0.6 },
]}
onPress={() => {
console.log('press');
}}
/>
// Evenly distributed.
<ColorRect
style={{ width: 80, height: 100 }}
colors={['#E292FE', '#FFF76B']}
onPress={() => {
console.log('press');
}}
/>
</View>
);
}
}
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback