Skip to content

Commit d3b9ef5

Browse files
MessageList Component added.
1 parent 8395261 commit d3b9ef5

5 files changed

Lines changed: 117 additions & 30 deletions

File tree

example-native/App.js

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ import {
1010
StyleSheet,
1111
Text,
1212
View,
13-
ScrollView,
1413
} from 'react-native';
1514

16-
import { ChatItem, MessageBox, } from '../native';
15+
import { ChatItem, MessageList, } from '../native';
1716
import Theme from '../native/Theme';
1817

1918
import IconI from 'react-native-vector-icons/Ionicons';
2019
import IconM from 'react-native-vector-icons/MaterialIcons';
21-
20+
var messageSource=[];
2221
export default class App extends Component<{}> {
2322
constructor(props) {
2423
super(props);
@@ -27,6 +26,7 @@ export default class App extends Component<{}> {
2726
show: true,
2827
messageList: [],
2928
};
29+
3030
Theme.icons = {
3131
waiting: <IconM name='access-time' size={13}/>,
3232
sent: <IconM name='check' size={13}/>,
@@ -67,7 +67,7 @@ export default class App extends Component<{}> {
6767
view: 'list',
6868
title: 'consectetur adipisicing elit',
6969
titleColor: this.getRandomColor(),
70-
text: type === 'spotify' ? 'spotify:track:7wGoVu4Dady5GV0Sv4UIsx' : 'Ab beatae odit deleniti dolor numquam nisi, non laboriosam sequi',
70+
text: 'Ab beatae odit deleniti dolor numquam nisi, non laboriosam sequi',
7171
data: {
7272
uri: require('./assets/chat-user.png'),
7373
status: {
@@ -101,38 +101,19 @@ export default class App extends Component<{}> {
101101
}
102102

103103
render() {
104-
var arr = [];
105-
for (var i = 0; i < 5; i++)
106-
arr.push(i);
107-
108-
var chatSource = arr.map(x => this.random('chat'));
109-
var messageSource = arr.map(x => this.random('message'));
104+
messageSource.unshift(this.random('message'));
110105
return (
111-
<ScrollView
106+
<View
112107
style={{
113108
flex: 1,
114109
marginTop: 10,
115110
backgroundColor: '#ccc',
116111
}}>
117-
{
118-
messageSource.map((x, i) => (
119-
<MessageBox
120-
key={i}
121-
{...x}/>
122-
))
123-
}
124-
{
125-
chatSource.map((x, i) => (
126-
<ChatItem
127-
key={i}
128-
title={x.title}
129-
unread={i || 1}
130-
statusColor='lightgreen'
131-
subtitle={x.subtitle}
132-
avatar={require('./assets/chat-user.png')}/>
133-
))
134-
}
135-
</ScrollView>
112+
<MessageList
113+
lockable={true}
114+
dataSource={messageSource}/>
115+
<Text onPress={() => {this.setState(this.state)}}>Gönder</Text>
116+
</View>
136117
);
137118
}
138119
}

native/MessageList/MessageList.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import React, { Component } from 'react';
2+
import styles from './MessageListStyle.js';
3+
4+
import Avatar from '../Avatar/Avatar';
5+
import MessageBox from '../MessageBox/MessageBox';
6+
7+
import {
8+
ScrollView,
9+
} from 'react-native';
10+
11+
export class MessageList extends Component {
12+
13+
constructor(props) {
14+
super(props);
15+
}
16+
17+
onOpen(item, i, e) {
18+
if (this.props.onOpen instanceof Function)
19+
this.props.onOpen(item, i, e);
20+
}
21+
22+
onDownload(item, i, e) {
23+
if (this.props.onDownload instanceof Function)
24+
this.props.onDownload(item, i, e);
25+
}
26+
27+
onPress(item, i, e) {
28+
if (this.props.onPress instanceof Function)
29+
this.props.onPress(item, i, e);
30+
}
31+
32+
onTitlePress(item, i, e) {
33+
if (this.props.onTitlePress instanceof Function)
34+
this.props.onTitlePress(item, i, e);
35+
}
36+
37+
onForwardPress(item, i, e) {
38+
if (this.props.onForwardPress instanceof Function)
39+
this.props.onForwardPress(item, i, e);
40+
}
41+
42+
loadRef(ref) {
43+
this.mlistRef = ref;
44+
if (this.props.cmpRef instanceof Function)
45+
this.props.cmpRef(ref);
46+
}
47+
48+
render() {
49+
return (
50+
<ScrollView
51+
ref={this.loadRef.bind(this)}
52+
style={styles.rceContainerMlist}>
53+
{
54+
this.props.dataSource.map((x, i) => (
55+
<MessageBox
56+
key={i}
57+
{...x}
58+
onOpen={this.props.onOpen && ((e) => this.onOpen(x, i, e))}
59+
onDownload={this.props.onDownload && ((e) => this.onDownload(x, i, e))}
60+
onTitlePress={this.props.onDownload && ((e) => this.onTitlePress(x, i, e))}
61+
onForwardPress={this.props.onForwardPress && ((e) => this.onForwardPress(x, i, e))}
62+
onPress={this.props.onPress && ((e) => this.onPress(x, i, e))}/>
63+
))
64+
}
65+
</ScrollView>
66+
);
67+
}
68+
}
69+
70+
71+
MessageList.defaultProps = {
72+
onPress: null,
73+
onTitlePress: null,
74+
onForwardPress: null,
75+
onOpen: null,
76+
onDownload: null,
77+
dataSource: [],
78+
lockable: false,
79+
toBottomHeight: 300,
80+
};
81+
82+
export default MessageList;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {
2+
StyleSheet,
3+
} from 'react-native';
4+
5+
export default StyleSheet.create({
6+
rceContainerMlist: {
7+
8+
}
9+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React, { Component } from 'react';
2+
import { shallow } from 'enzyme';
3+
import toJson from 'enzyme-to-json';
4+
import MessageList from '../MessageList';
5+
6+
describe('MessageList component', () => {
7+
it('should render without issues', () => {
8+
const component = shallow(<MessageList />);
9+
10+
expect(component.length).toBe(1);
11+
expect(toJson(component)).toMatchSnapshot();
12+
});
13+
});

native/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import ChatItem from './ChatItem/ChatItem';
22
import MessageBox from './MessageBox/MessageBox';
3+
import MessageList from './MessageList/MessageList';
34

45
export {
56
ChatItem,
67
MessageBox,
8+
MessageList,
79
};

0 commit comments

Comments
 (0)