forked from software-mansion/react-native-svg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPattern.tsx
70 lines (66 loc) · 1.77 KB
/
Pattern.tsx
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import React from 'react';
import { requireNativeComponent } from 'react-native';
import extractTransform from '../lib/extract/extractTransform';
import extractViewBox from '../lib/extract/extractViewBox';
import { NumberProp, TransformProps } from '../lib/extract/types';
import units from '../lib/units';
import Shape from './Shape';
export default class Pattern extends Shape<{
id?: string;
x?: NumberProp;
y?: NumberProp;
width?: NumberProp;
height?: NumberProp;
viewBox?: string;
preserveAspectRatio?: string;
transform?: number[] | string | TransformProps;
patternTransform?: number[] | string | TransformProps;
patternUnits?: 'objectBoundingBox' | 'userSpaceOnUse';
patternContentUnits?: 'objectBoundingBox' | 'userSpaceOnUse';
}> {
static displayName = 'Pattern';
static defaultProps = {
x: '0%',
y: '0%',
width: '100%',
height: '100%',
};
render() {
const { props } = this;
const {
patternTransform,
transform,
id,
x,
y,
width,
height,
patternUnits,
patternContentUnits,
children,
viewBox,
preserveAspectRatio,
} = props;
const matrix = extractTransform(patternTransform || transform || props);
return (
<RNSVGPattern
ref={this.refMethod}
name={id}
x={x}
y={y}
width={width}
height={height}
matrix={matrix}
patternTransform={matrix}
patternUnits={(patternUnits && units[patternUnits]) || 0}
patternContentUnits={
patternContentUnits ? units[patternContentUnits] : 1
}
{...extractViewBox({ viewBox, preserveAspectRatio })}
>
{children}
</RNSVGPattern>
);
}
}
export const RNSVGPattern = requireNativeComponent('RNSVGPattern');