-
-
Notifications
You must be signed in to change notification settings - Fork 464
Expand file tree
/
Copy pathSelectableText.tsx
More file actions
28 lines (26 loc) · 861 Bytes
/
SelectableText.tsx
File metadata and controls
28 lines (26 loc) · 861 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
import React from 'react'
import { Platform, TextInput, Text } from 'react-native'
export type SelectableTextProps = {
value: string | Record<string, any>
accessibilityLabel: string
}
const style = { color: 'black' } as const
const SelectableTextFabric = ({ value, accessibilityLabel }: SelectableTextProps) => {
const toRender = typeof value === 'string' ? value : JSON.stringify(value, null, 2)
return Platform.OS === 'ios' ? (
// it has some issues but good enough
<TextInput
multiline
accessibilityLabel={accessibilityLabel}
editable={false}
style={style}
value={toRender}
/>
) : (
<Text style={style} selectable accessibilityLabel={accessibilityLabel}>
{toRender}
</Text>
)
}
// maybe use different implementation for old architecture
export const SelectableText = SelectableTextFabric