Skip to content

Commit 395a2c5

Browse files
author
杨楠
committed
feat:Ellipsis 增加弹出展示全部文本内容
1 parent fd6bb1d commit 395a2c5

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

example/examples/src/routes/Ellipsis/index.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ export default class DividerView extends React.Component<DividerViewProps> {
3434
</Ellipsis>
3535
</WingBlank>
3636
</Card>
37+
<Card title="点击展示文本全部内容">
38+
<WingBlank>
39+
<Ellipsis maxLen={5} placeholder="。。。。">
40+
用于文本过长,超出长度显示 用于文本过长,超出长度显示
41+
用于文本过长,超出长度显示 用于文本过长,超出长度显示
42+
</Ellipsis>
43+
</WingBlank>
44+
</Card>
3745
</Body>
3846
<Footer />
3947
</Layout>

packages/core/src/Ellipsis/index.tsx

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,50 @@
1-
import React from 'react';
1+
import React, { useState } from 'react';
22
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';
47

8+
let MainHeight = Dimensions.get('window').height;
59
export interface EllipsisProps extends TextProps {
610
children?: React.ReactNode;
711
placeholder?: string;
812
maxLen?: number;
913
}
1014

1115
export default function Ellipsis({ maxLen, children, placeholder, ...props }: EllipsisProps) {
16+
const [modalVisible, setModalVisible] = useState(false);
17+
1218
let content = children;
19+
let content1 = children;
1320
if (maxLen && content && typeof content === 'string') {
1421
content = content.length > maxLen ? content.substr(0, maxLen) + placeholder : content;
1522
}
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+
);
1748
}
1849

1950
Ellipsis.propTypes = {

packages/core/src/Ellipsis/svg.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const right: string = `
2+
<svg t="1635326971544" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1198" width="200" height="200"><path d="M353.045333 86.826667L754.56 488.362667a32 32 0 0 1 2.090667 42.965333l-2.090667 2.282667L353.066667 935.168a8.533333 8.533333 0 0 1-6.037334 2.496h-66.368a8.533333 8.533333 0 0 1-6.037333-14.570667L686.72 511.018667 274.602667 98.901333a8.533333 8.533333 0 0 1 6.037333-14.570666h66.346667a8.533333 8.533333 0 0 1 6.058666 2.496z" fill="#333333" p-id="1199"></path></svg>
3+
`;

0 commit comments

Comments
 (0)