Skip to content

Commit 6c1a1f1

Browse files
Merge pull request #9 from Roka20012/master
[feature] Add styling for SeeMore, SeeLess links [feature] option to pass components instead of see more/see less text
2 parents 45ecb87 + 603f605 commit 6c1a1f1

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

index.d.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
declare module 'react-native-see-more-inline' {
2+
import { ComponentClass, ReactElement } from 'react';
3+
4+
export type SeeMoreProps = {
5+
numberOfLines: number;
6+
linkColor: string;
7+
8+
linkPressedColor?: string;
9+
10+
seeMoreTextStyle?: StyleProp<TextStyle>;
11+
seeLessTextStyle?: StyleProp<TextStyle>;
12+
13+
seeMoreText?: string | ReactElement;
14+
seeLessText?: string | ReactElement;
15+
16+
style?: StyleProp<ViewStyle>;
17+
};
18+
19+
const SeeMore: ComponentClass<SeeMoreProps>;
20+
21+
export default SeeMore;
22+
}

src/SeeMore/SeeMore.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ class SeeMore extends React.Component {
108108
children: text,
109109
linkColor,
110110
linkPressedColor,
111+
seeMoreTextStyle,
112+
seeLessTextStyle,
111113
seeMoreText,
112114
seeLessText,
113115
style,
@@ -118,14 +120,27 @@ class SeeMore extends React.Component {
118120
return null;
119121
}
120122

123+
const SeeLessText =
124+
typeof seeLessText === 'string' ? (
125+
<Text style={seeLessTextStyle}> {seeLessText}</Text>
126+
) : (
127+
seeLessText
128+
);
129+
130+
const SeeMoreText =
131+
typeof seeMoreText === 'string' ? (
132+
<Text style={seeMoreTextStyle}> {seeMoreText}</Text>
133+
) : (
134+
seeMoreText
135+
);
136+
121137
return (
122138
<Text
123139
{...this.props}
124140
{...this.panResponder.panHandlers}
125-
style={[style, { color: isLinkPressed ? linkPressedColor : linkColor }]}
126-
>
141+
style={[style, { color: isLinkPressed ? linkPressedColor : linkColor }]}>
127142
{isShowingMore ? null : <Text {...this.props}>...</Text>}
128-
{isShowingMore ? ` ${seeLessText}` : ` ${seeMoreText}`}
143+
{isShowingMore ? SeeLessText : SeeMoreText}
129144
</Text>
130145
);
131146
}
@@ -141,9 +156,7 @@ class SeeMore extends React.Component {
141156
numberOfLines={isShowingMore ? undefined : numberOfLines}
142157
{...this.panResponder.panHandlers}
143158
>
144-
<Text {...this.props}>
145-
{isShowingMore ? text : text.slice(0, truncationIndex)}
146-
</Text>
159+
<Text {...this.props}>{isShowingMore ? text : text.slice(0, truncationIndex)}</Text>
147160
{this.renderSeeMoreSeeLessLink()}
148161
</Text>
149162
);
@@ -155,8 +168,10 @@ SeeMore.propTypes = {
155168
numberOfLines: PropTypes.number.isRequired,
156169
linkColor: PropTypes.string,
157170
linkPressedColor: PropTypes.string,
158-
seeMoreText: PropTypes.string,
159-
seeLessText: PropTypes.string,
171+
seeMoreTextStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
172+
seeLessTextStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
173+
seeMoreText: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
174+
seeLessText: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
160175
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
161176
};
162177

0 commit comments

Comments
 (0)