|
1 | | -import React from 'react'; |
| 1 | +import React, { useState } from 'react'; |
2 | 2 | import PropTypes from 'prop-types'; |
3 | | -import { Text, TextProps } from 'react-native'; |
| 3 | +import { View, Text, TextProps, Dimensions, TouchableOpacity } from 'react-native'; |
| 4 | +import Icon from '../Icon'; |
| 5 | +import { right } from './svg'; |
| 6 | +import MaskLayer from '../MaskLayer'; |
4 | 7 |
|
| 8 | +let MainHeight = Dimensions.get('window').height; |
5 | 9 | export interface EllipsisProps extends TextProps { |
6 | 10 | children?: React.ReactNode; |
7 | 11 | placeholder?: string; |
8 | 12 | maxLen?: number; |
9 | 13 | } |
10 | 14 |
|
11 | 15 | export default function Ellipsis({ maxLen, children, placeholder, ...props }: EllipsisProps) { |
| 16 | + const [modalVisible, setModalVisible] = useState(false); |
| 17 | + |
12 | 18 | let content = children; |
| 19 | + let content1 = children; |
13 | 20 | if (maxLen && content && typeof content === 'string') { |
14 | 21 | content = content.length > maxLen ? content.substr(0, maxLen) + placeholder : content; |
15 | 22 | } |
16 | | - return <Text {...props}>{content}</Text>; |
| 23 | + return ( |
| 24 | + <> |
| 25 | + <MaskLayer visible={modalVisible} onDismiss={() => setModalVisible(false)}> |
| 26 | + <View |
| 27 | + style={{ |
| 28 | + backgroundColor: '#fff', |
| 29 | + justifyContent: 'center', |
| 30 | + alignItems: 'center', |
| 31 | + marginTop: MainHeight * 0.2, |
| 32 | + height: children.length + 30, |
| 33 | + }} |
| 34 | + > |
| 35 | + <Text style={{ fontSize: 17 }}>{children}</Text> |
| 36 | + </View> |
| 37 | + </MaskLayer> |
| 38 | + |
| 39 | + <TouchableOpacity |
| 40 | + style={{ flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center' }} |
| 41 | + onPress={() => setModalVisible(true)} |
| 42 | + > |
| 43 | + <Text {...props}>{content}</Text> |
| 44 | + <Icon name="right" size={14} /> |
| 45 | + </TouchableOpacity> |
| 46 | + </> |
| 47 | + ); |
17 | 48 | } |
18 | 49 |
|
19 | 50 | Ellipsis.propTypes = { |
|
0 commit comments