Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React native parsed text #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions App/Components/SimpleList.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var SimpleList = React.createClass({
if (this.props.navigator) passAlong.navigator = this.props.navigator;
if (this.props.nextIcon) passAlong.nextIcon = this.props.nextIcon;
if (this.props.noTap) passAlong.noTap = this.props.noTap;
if (this.props.parseTitle) passAlong.parseTitle = this.props.parseTitle;

if (this.props.getItemProps) {
// swtich it out
Expand Down
12 changes: 12 additions & 0 deletions App/Components/SimpleListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ var {
TouchableHighlight
} = React;

var ParsedText = require('react-native-parsed-text');

var cssVar = require('../Lib/cssVar');

var Text = require('../Components/Text');
Expand All @@ -17,6 +19,16 @@ var SimpleListItem = React.createClass({

renderTitle: function() {
if (!this.props.title) return null;
if (this.props.parseTitle) {
return (
<ParsedText
parse={this.props.parseTitle}
style={styles.title}
>
{this.props.title}
</ParsedText>
)
}

return (
<Text style={styles.title}>
Expand Down
31 changes: 31 additions & 0 deletions App/Mixins/ListHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ var {
ListView
} = React;

var cssVar = require('../Lib/cssVar');

var CurrentUserStore = require('../Stores/CurrentUserStore');
var NavigationListener = require('../Mixins/NavigationListener');
var NavBarHelper = require('../Mixins/NavBarHelper');
Expand All @@ -23,6 +25,8 @@ var Text = require('../Components/Text');
var SegmentedControl = require('../Components/SegmentedControl');
var SimpleList = require('../Components/SimpleList');

var AppActions = require('../Actions/AppActions');

var ListHelper = {
mixins: [NavigationListener, NavBarHelper],

Expand Down Expand Up @@ -70,6 +74,18 @@ var ListHelper = {
return this.username;
},

getParseTitle: function() {
if (this.props.listProps.parse === true) {
return [
{type: 'url', style: styles.url, onPress: (url) => AppActions.launchExternalURL(url) },
{pattern: /@(\w+)/, style: styles.mention, onPress: (mention) => AppActions.launchRelativeItem(this.props.currentRoute, {replacePath: `follows/${mention.substring(1).toLowerCase()}/posts`}) },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user doesn't necessarily follow the person he mentioned. adding in follows will also make that the back button. I'd expect to have a change to the route parsing to allow something like /bleonard/posts/jrlai

{pattern: /#(\w+)/, style: styles.hashtag},
]
}

return null;
},

renderItems: function() {
return (
<SimpleList
Expand All @@ -78,6 +94,7 @@ var ListHelper = {
getItemProps={this.getItemProps}
items={this.state.items}
reloadList={this.reloadList}
parseTitle={this.getParseTitle()}
{...this.props.listProps}
/>
);
Expand Down Expand Up @@ -130,6 +147,20 @@ var ListHelper = {
var styles = StyleSheet.create({
flex: {
flex: 1
},

hashtag: {
color: cssVar('blue50'),
fontStyle: 'italic',
},

mention: {
color: cssVar('blue50'),
},

url: {
color: cssVar('blue50'),
textDecorationLine: 'underline',
}
});

Expand Down
3 changes: 2 additions & 1 deletion App/Screens/PostList.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ var PostList = React.createClass({
return {
store: PostListStore,
listProps: {
noTap: true
noTap: true,
parse: true,
},
segment: {
items: [
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"react-native": "^0.12.0",
"react-native-keyboardevents": "^0.4.5",
"react-native-keychain": "^0.2.5",
"react-native-parsed-text": "0.0.4",
"react-native-refreshable-listview": "^1.3.0",
"react-timer-mixin": "^0.13.3",
"superagent": "^1.4.0"
Expand Down