-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLimitlessText.js
59 lines (54 loc) · 1.43 KB
/
LimitlessText.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
import React, {forwardRef} from 'react';
import {Text, Alert} from 'react-native';
const normalizeStringFromChildrenComponents = (unsafeChildren) => {
let children = unsafeChildren;
let data = '';
if (typeof children === 'string') {
data += ` ${children}`;
}
if (typeof children === 'object') {
children = [children];
}
if (Array.isArray(children)) {
children.forEach((c) => {
if (typeof c === 'string') {
data += ` ${c}`;
} else {
if (c.props.textBefore) {
data += ` ${c.props.textBefore}`;
}
data += ` ${normalizeStringFromChildrenComponents(c.props.children)}`;
if (c.props.textAfter) {
data += ` ${c.props.textAfter}`;
}
}
});
}
return data;
};
// accessibilityActions={[
// {name: 'activate', label: 'open up the users profile'},
// ]}
const LimitlessText = forwardRef((props, ref) => {
let data = normalizeStringFromChildrenComponents(props.children);
return (
<Text
ref={ref}
accessible
accessibilityLabel={`${props.textBefore} ${data} ${props.textAfter}`}
onPress={() => Alert.alert('Alert', 'opened the profile')}
{...props}>
{props.children}
</Text>
);
});
// onAccessibilityAction={(event) => {
// switch (event) {
// case 'activate':
// Alert.alert('OPENED!!!');
// break;
// default:
// break;
// }
// }}>
export {LimitlessText};