Skip to content

Commit cf9afc2

Browse files
authored
Add files via upload
1 parent 09ed9ac commit cf9afc2

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

index.js

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import * as React from "react";
2+
import { StyleSheet, View, Text } from "react-native";
3+
import { Children, cloneElement, isValidElement } from "react";
4+
5+
function TextStroke(props) {
6+
const {color, stroke, children} = props;
7+
const strokeW = stroke;
8+
const top = createClones(0, -strokeW * 1.2, color);
9+
const topLeft = createClones(-strokeW, -strokeW, color);
10+
const topRight = createClones(strokeW, -strokeW, color);
11+
const right = createClones(strokeW, 0, color);
12+
const bottom = createClones(0, strokeW, color);
13+
const bottomLeft = createClones(-strokeW, strokeW, color);
14+
const bottomRight = createClones(strokeW, strokeW, color);
15+
const left = createClones(-strokeW * 1.2, 0, color);
16+
17+
function createClones(w, h, color) {
18+
return Children.map(children, child => {
19+
if (isValidElement(child)) {
20+
const currentProps = child.props;
21+
const currentStyle = currentProps ? (currentProps.style || {}) : {};
22+
23+
const newProps = {
24+
...currentProps,
25+
style: {
26+
...currentStyle,
27+
textShadowOffset: {
28+
width: w,
29+
height: h
30+
},
31+
textShadowColor: color,
32+
textShadowRadius: 0.1
33+
}
34+
}
35+
return cloneElement(child, newProps)
36+
}
37+
return child;
38+
});
39+
}
40+
41+
return(
42+
<View>
43+
<View style={ styles.outline }>{ left }</View>
44+
<View style={ styles.outline }>{ right }</View>
45+
<View style={ styles.outline }>{ bottom }</View>
46+
<View style={ styles.outline }>{ top }</View>
47+
<View style={ styles.outline }>{ topLeft }</View>
48+
<View style={ styles.outline }>{ topRight }</View>
49+
<View style={ styles.outline }>{ bottomLeft }</View>
50+
{ bottomRight }
51+
</View>
52+
)
53+
}
54+
55+
const styles = StyleSheet.create({
56+
outline: {
57+
position: 'absolute',
58+
},
59+
});
60+
61+
export { TextStroke };

package.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "react-native-textstroke",
3+
"version": "1.0.0",
4+
"description": "React-Native-TextStroke",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/dvinfosys/React-Native-TextStroke.git"
12+
},
13+
"keywords": [
14+
"React-Native-TextStroke",
15+
"TextStroke",
16+
"React-Native",
17+
"Stroke"
18+
],
19+
"author": "dvinfosys",
20+
"license": "ISC",
21+
"bugs": {
22+
"url": "https://github.com/dvinfosys/React-Native-TextStroke/issues"
23+
},
24+
"homepage": "https://github.com/dvinfosys/React-Native-TextStroke#readme"
25+
}

0 commit comments

Comments
 (0)