-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathSelectableText.tsx
More file actions
50 lines (45 loc) · 940 Bytes
/
SelectableText.tsx
File metadata and controls
50 lines (45 loc) · 940 Bytes
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
import React from "react";
import {
Platform,
TextInput,
Text,
TextStyle,
I18nManager,
StyleSheet,
TextInputProps,
TextProps,
StyleProp,
} from "react-native";
type Props = {
style?: StyleProp<TextStyle>;
text?: string;
} & (TextInputProps | TextProps);
const SelectableText: React.FC<Props> = ({ style, text, ...rest }) => {
const writingDirection: "auto" | "ltr" | "rtl" = I18nManager.isRTL
? "rtl"
: "ltr";
const baseStyle = [styles.baseText, { writingDirection }, style];
if (Platform.OS === "ios") {
return (
<TextInput
{...rest}
value={text}
editable={false}
scrollEnabled={false}
multiline
style={baseStyle}
/>
);
}
return (
<Text {...rest} selectable style={baseStyle}>
{text}
</Text>
);
};
const styles = StyleSheet.create({
baseText: {
textAlign: "left",
},
});
export default SelectableText;