Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Commits on Source (2)
(feat) limit blog card title length
· 6d460a9b
Martin Santangelo
authored
Dec 26, 2019
6d460a9b
Merge branch 'feat/limit-blog-card-title-to-two-lines' into 'release/3.15.0'
· 80e49027
Brian Hatchet
authored
Jan 03, 2020
Limit blog card title length See merge request
!470
80e49027
Hide whitespace changes
Inline
Side-by-side
__tests__/blogs/__snapshots__/BlogCard.js.snap
View file @
80e49027
...
...
@@ -80,6 +80,8 @@ exports[`blog card component should renders correctly 1`] = `
}
>
<Text
ellipsizeMode="tail"
numberOfLines={2}
style={
Array [
Object {
...
...
@@ -88,6 +90,9 @@ exports[`blog card component should renders correctly 1`] = `
Object {
"fontWeight": "500",
},
Object {
"flex": 1,
},
]
}
>
...
...
src/blogs/BlogCard.js
View file @
80e49027
...
...
@@ -23,13 +23,25 @@ import Actions from '../newsfeed/activity/Actions';
* Blog Card
*/
export
default
class
BlogCard
extends
PureComponent
{
/**
* Navigate to blog
*/
navToBlog
=
()
=>
{
if
(
!
this
.
props
.
navigation
||
!
this
.
props
.
entity
.
can
(
FLAG_VIEW
,
true
))
return
;
if
(
!
this
.
props
.
navigation
||
!
this
.
props
.
entity
.
can
(
FLAG_VIEW
,
true
))
{
return
;
}
return
this
.
props
.
navigation
.
push
(
'
BlogView
'
,
{
blog
:
this
.
props
.
entity
});
};
/**
* Trim and remove new line char
* @param {string} title
*/
cleanTitle
(
title
)
{
if
(
!
title
)
{
return
''
;
}
return
title
.
trim
().
replace
(
/
\n
/gm
,
'
'
);
}
/**
...
...
@@ -39,13 +51,14 @@ export default class BlogCard extends PureComponent {
const
blog
=
this
.
props
.
entity
;
const
channel
=
this
.
props
.
entity
.
ownerObj
;
const
image
=
blog
.
getBannerSource
();
const
title
=
this
.
cleanTitle
(
blog
.
title
);
return
(
<
TouchableOpacity
onPress
=
{
this
.
navToBlog
}
style
=
{
CS
.
backgroundWhite
}
>
<
FastImage
source
=
{
image
}
style
=
{
styles
.
banner
}
resizeMode
=
{
FastImage
.
resizeMode
.
cover
}
/
>
<
View
style
=
{[
CS
.
padding2x
]}
>
<
View
style
=
{[
CS
.
columnAlignStart
,
CS
.
fullWidth
]}
>
<
Text
style
=
{[
CS
.
fontL
,
CS
.
fontMedium
]}
>
{
blog
.
title
}
<
/Text
>
<
Text
style
=
{[
CS
.
fontL
,
CS
.
fontMedium
,
CS
.
flexContainer
]}
numberOfLines
=
{
2
}
ellipsizeMode
=
"
tail
"
>
{
title
}
<
/Text
>
<
View
style
=
{[
CS
.
marginBottom2x
,
CS
.
marginTop2x
,
CS
.
rowJustifyCenter
,
CS
.
alignCenter
]}
>
{
channel
&&
<
Avatar
width
=
{
24
}
...
...
@@ -73,5 +86,5 @@ const styles = StyleSheet.create({
flexDirection
:
'
row
'
,
height
:
150
,
width
:
'
100%
'
,
}
}
,
});