-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
61 lines (55 loc) · 1.86 KB
/
index.js
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
import * as React from "react";
import { StyleSheet, View, Text } from "react-native";
import { Children, cloneElement, isValidElement } from "react";
function TextStroke(props) {
const {color, stroke, children} = props;
const strokeW = stroke;
const top = createClones(0, -strokeW * 1.2, color);
const topLeft = createClones(-strokeW, -strokeW, color);
const topRight = createClones(strokeW, -strokeW, color);
const right = createClones(strokeW, 0, color);
const bottom = createClones(0, strokeW, color);
const bottomLeft = createClones(-strokeW, strokeW, color);
const bottomRight = createClones(strokeW, strokeW, color);
const left = createClones(-strokeW * 1.2, 0, color);
function createClones(w, h, color) {
return Children.map(children, child => {
if (isValidElement(child)) {
const currentProps = child.props;
const currentStyle = currentProps ? (currentProps.style || {}) : {};
const newProps = {
...currentProps,
style: {
...currentStyle,
textShadowOffset: {
width: w,
height: h
},
textShadowColor: color,
textShadowRadius: 0.1
}
}
return cloneElement(child, newProps)
}
return child;
});
}
return(
<View>
<View style={ styles.outline }>{ left }</View>
<View style={ styles.outline }>{ right }</View>
<View style={ styles.outline }>{ bottom }</View>
<View style={ styles.outline }>{ top }</View>
<View style={ styles.outline }>{ topLeft }</View>
<View style={ styles.outline }>{ topRight }</View>
<View style={ styles.outline }>{ bottomLeft }</View>
{ bottomRight }
</View>
)
}
const styles = StyleSheet.create({
outline: {
position: 'absolute',
},
});
export { TextStroke };